【新增】增加[coreshop-advert]广告组件,对标后台管理功能的广告管理,前端可<coreshop-advert codes="广告位code"></coreshop-advert>来实现在前端任何地方引用广告。

This commit is contained in:
JianWeie
2022-05-08 15:07:09 +08:00
parent 3a441d1e60
commit 85d845f23c
7 changed files with 130 additions and 36 deletions

View File

@@ -0,0 +1,98 @@
<template>
<view>
<!--提示框组件-->
<u-toast ref="uToast" />
<view v-for="item in advert">
<u--image :showLoading="true" :src="item.imageUrl" mode="widthFix" width="100%" height="auto" @click="showSliderInfo(item.type, item.val)"></u--image>
</view>
</view>
</template>
<script>
import { navLinkType } from '@/common/setting/constVarsHelper.js';
export default {
props: {
codes: {
type: String,
required: true,
default: 'tpl1_class_banner1'
}
},
data() {
return {
advert: [],
}
},
created() {
console.log(this.codes);
this.getData();
},
methods: {
getData() {
this.$u.api.advert({
codes: this.codes
}).then(res => {
this.advert = res.data;
});
},
// 广告点击查看详情
showSliderInfo(type, val) {
if (!val) {
return;
}
if (type == 1) {
if (val.indexOf('http') != -1) {
// #ifdef H5
window.location.href = val
// #endif
// #ifdef H5 || APP-PLUS || APP-PLUS-NVUE || MP
this.$u.route('/pages/webview/webview', { src: val });
// #endif
} else {
// #ifdef H5 || APP-PLUS || APP-PLUS-NVUE || MP
if (val == '/pages/index/default/default' || val == '/pages/category/index/index' || val == '/pages/index/cart/cart' || val == '/pages/index/member/member') {
this.$u.route({ type: 'switchTab', url: val });
return;
} else if (val.indexOf('/pages/coupon/coupon') > -1) {
var id = val.replace('/pages/coupon/coupon?id=', "");
this.receiveCoupon(id)
} else {
this.$common.navigateTo(val);
return;
}
// #endif
}
} else if (type == 2) {
// 商品详情
this.$u.route('/pages/goods/goodDetails/goodDetails', { id: val });
} else if (type == 3) {
// 文章详情
this.$u.route('/pages/article/details/details', { idType: 1, id: val });
} else if (type == 4) {
// 文章列表
this.$u.route('/pages/article/list/list')
} else if (type == navLinkType.intelligentForms) {
this.$u.route('/pages/form/details/details', { id: val });
} else {
this.$u.route(val);
}
},
// 用户领取优惠券
receiveCoupon(couponId) {
let _this = this;
let coreshopdata = {
id: couponId
}
this.$u.api.getCoupon(coreshopdata).then(res => {
if (res.status) {
_this.$refs.uToast.show({ message: res.msg, type: 'success', back: false })
} else {
_this.$u.toast(res.msg)
}
})
},
},
}
</script>
<style scoped lang="scss">
</style>

View File

@@ -36,6 +36,7 @@
<block v-for="(item,index) in tabbar" :key="index">
<scroll-view scroll-y class="right-box" v-if="current==index">
<view class="coreshop-padding-10">
<coreshop-advert codes="TplIndexBanner1"></coreshop-advert>
<view class="class-item">
<view class="item-title">
<text>{{item.name}}</text>

View File

@@ -210,9 +210,6 @@ namespace CoreCms.Net.Web.Admin.Controllers
{
//返回数据
var jm = new AdminUiCallBack { code = 0 };
var data = EnumHelper.EnumToList<GlobalEnumVars.AdvertTemplateCode>();
jm.data = data;
return jm;
}
@@ -234,6 +231,13 @@ namespace CoreCms.Net.Web.Admin.Controllers
entity.createTime = DateTime.Now;
var have = await _coreCmsAdvertPositionServices.ExistsAsync(p => p.code == entity.code);
if (have)
{
jm.msg = "已存在相同位置编码。";
return jm;
}
var bl = await _coreCmsAdvertPositionServices.InsertAsync(entity) > 0;
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
@@ -264,14 +268,8 @@ namespace CoreCms.Net.Web.Admin.Controllers
return jm;
}
var advertTemplateCode = EnumHelper.EnumToList<GlobalEnumVars.AdvertTemplateCode>();
jm.code = 0;
jm.data = new
{
model,
advertTemplateCode
};
jm.data = model;
return jm;
}
@@ -299,6 +297,14 @@ namespace CoreCms.Net.Web.Admin.Controllers
return jm;
}
var have = await _coreCmsAdvertPositionServices.ExistsAsync(p => p.code == entity.code && p.id != oldModel.id);
if (have)
{
jm.msg = "已存在相同位置编码。";
return jm;
}
//事物处理过程开始
oldModel.name = entity.name;
oldModel.code = entity.code;

View File

@@ -352,7 +352,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
if (oldModel.positionId != entity.positionId)
{
oldModel.positionId = entity.positionId;
var type = _coreCmsAdvertPositionServices.QueryById(entity.positionId);
var type = await _coreCmsAdvertPositionServices.QueryByIdAsync(entity.positionId);
if (type != null) oldModel.code = type.code;
}

View File

@@ -12,13 +12,9 @@
<div class="layui-form-item">
<label for="code" class="layui-form-label">位置编码</label>
<div class="layui-input-inline">
<select name="code" id="code" required lay-verify="required" lay-reqText="请输入位置编码" placeholder="请输入位置编码">
<option value="">请选择</option>
{{# layui.each(d.params.data, function(index, item){ }}
<option value="{{ item.title }}">{{ item.description }}</option>
{{# }); }}
</select>
<input name="code" id="code" lay-verify="required|verifycode" class="layui-input" lay-reqText="请输入位置编码" placeholder="请输入位置编码" />
</div>
<div class="layui-form-mid layui-word-aux">请输入英文</div>
</div>
<div class="layui-form-item" pane>
<label for="isEnable" class="layui-form-label">是否启用</label>

View File

@@ -1,11 +1,11 @@
<script type="text/html" template lay-done="layui.data.sendParams(d);">
<div class="layui-form coreshop-form layui-form-pane" lay-filter="LAY-app-CoreCmsAdvertPosition-editForm" id="LAY-app-CoreCmsAdvertPosition-editForm">
<input type="hidden" name="id" id="id" value="{{d.params.data.model.id || '' }}" />
<input type="hidden" name="id" id="id" value="{{d.params.data.id || '' }}" />
<div class="layui-form-item">
<label for="name" class="layui-form-label">名称</label>
<div class="layui-input-inline">
<input name="name" id="name" lay-verify="required|verifyname" class="layui-input" placeholder="请输入名称" lay-reqText="请输入名称" value="{{d.params.data.model.name || '' }}" />
<input name="name" id="name" lay-verify="required|verifyname" class="layui-input" placeholder="请输入名称" lay-reqText="请输入名称" value="{{d.params.data.name || '' }}" />
</div>
<div class="layui-form-mid layui-word-aux">请输入不超过120个字符内容</div>
</div>
@@ -13,27 +13,22 @@
<div class="layui-form-item">
<label for="code" class="layui-form-label">位置编码</label>
<div class="layui-input-inline">
<select name="code" id="code" required lay-verify="required" lay-reqText="请输入位置编码" placeholder="请输入位置编码">
<option value="">请选择</option>
{{# layui.each(d.params.data.advertTemplateCode, function(index, item){ }}
<option value="{{ item.title }}" {{d.params.data.model.code==item.title?'selected="selected"':''}}>{{ item.description }}</option>
{{# }); }}
</select>
<input name="code" id="code" lay-verify="required|verifycode" class="layui-input" lay-reqText="请输入位置编码" placeholder="请输入位置编码" value="{{d.params.data.code || '' }}"/>
</div>
<div class="layui-form-mid layui-word-aux">请输入不超过32个字符内容</div>
<div class="layui-form-mid layui-word-aux">请输入英文</div>
</div>
<div class="layui-form-item" pane>
<label for="isEnable" class="layui-form-label">是否启用</label>
<div class="layui-input-block">
<input type="checkbox" lay-filter="switch" name="isEnable" id="isEnable" {{ d.params.data.model.isEnable ? 'checked' : '' }} lay-skin="switch" lay-text="开启|关闭">
<input type="checkbox" lay-filter="switch" name="isEnable" id="isEnable" {{ d.params.data.isEnable ? 'checked' : '' }} lay-skin="switch" lay-text="开启|关闭">
</div>
</div>
<div class="layui-form-item">
<label for="sort" class="layui-form-label">排序</label>
<div class="layui-input-inline">
<input type="number" min="0" max="999999" name="sort" id="sort" lay-verify="required|number" class="layui-input" value="{{d.params.data.model.sort}}" placeholder="请输入排序" lay-reqText="请输入排序并为数字" />
<input type="number" min="0" max="999999" name="sort" id="sort" lay-verify="required|number" class="layui-input" value="{{d.params.data.sort}}" placeholder="请输入排序" lay-reqText="请输入排序并为数字" />
</div>
<div class="layui-form-mid layui-word-aux">请输入数字</div>
</div>

View File

@@ -77,6 +77,8 @@ namespace CoreCms.Net.Web.WebApi.Controllers
}
#endregion
#region 广=============================================================================
/// <summary>
/// 获取广告位置信息
@@ -88,19 +90,15 @@ namespace CoreCms.Net.Web.WebApi.Controllers
{
var jm = new WebApiCallBack();
var position = await _advertPositionServices.QueryListByClauseAsync(p => p.isEnable && p.code == entity.codes);
if (!position.Any())
var position = await _advertPositionServices.QueryByClauseAsync(p => p.isEnable && p.code == entity.codes);
if (position == null)
{
jm.msg = "未获取到广告位置信息";
return jm;
}
var ids = position.Select(p => p.id).ToList();
var isement = await _advertisementServices.QueryListByClauseAsync(p => ids.Contains(p.positionId));
Dictionary<string, List<CoreCmsAdvertisement>> list = new Dictionary<string, List<CoreCmsAdvertisement>>();
list.Add(entity.codes, isement);
jm.status = true;
jm.data = list;
jm.data = await _advertisementServices.QueryListByClauseAsync(p => p.positionId == position.id);
return jm;