diff --git a/src/common/api/ad.js b/src/common/api/ad.js
new file mode 100644
index 0000000..0db2f67
--- /dev/null
+++ b/src/common/api/ad.js
@@ -0,0 +1,18 @@
+/*
+ * @Author: ch
+ * @Date: 2022-05-31 11:17:38
+ * @LastEditors: ch
+ * @LastEditTime: 2022-05-31 11:35:10
+ * @Description: file content
+ */
+
+import {ToAsyncAwait, MsbRequest, MsbRequestTk} from '@/common/utils';
+import { AD_PLATFORM } from '../dicts/ad';
+
+const BASE_URL = '/mall/marketing';
+
+// 获取广告列表
+export const ApiGetAdList = (params) => ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/app/advertisement`, {
+ platform : AD_PLATFORM.MOBILE,
+ ...params
+}))
\ No newline at end of file
diff --git a/src/common/api/base.js b/src/common/api/base.js
index 8195f71..2667fdc 100644
--- a/src/common/api/base.js
+++ b/src/common/api/base.js
@@ -2,13 +2,34 @@
* @Author: ch
* @Date: 2022-04-06 17:29:13
* @LastEditors: ch
- * @LastEditTime: 2022-04-15 14:17:14
+ * @LastEditTime: 2022-05-31 11:18:44
* @Description: file content
*/
-import {ToAsyncAwait, MsbRequestTk} from '@/common/utils';
+import {ToAsyncAwait, MsbRequest, MsbRequestTk} from '@/common/utils';
const BASE_URL = '/mall/base';
+
+const BASE_URL_UC = '/uc';
+
+/**
+ * 登录
+ * @param {*} data
+ */
+export const ApiPostLogin = (data) => ToAsyncAwait(MsbRequest.post(`${BASE_URL_UC}/user/login`, data));
+/**
+ * 退出登录
+ * @param {*} data
+ */
+export const ApiGetLogout= () => ToAsyncAwait(MsbRequest.get(`${BASE_URL_UC}/user/logout`));
+/**
+ * 获取手机验证码
+ * @param {*} params
+ */
+export const ApiGetCode = (params) => ToAsyncAwait(MsbRequest.get(`${BASE_URL_UC}/user/login/verificationCode`, params));
+
+
+
/**
* 获取收货地址
*/
diff --git a/src/common/dicts/ad.js b/src/common/dicts/ad.js
index 7d6f138..59ad599 100644
--- a/src/common/dicts/ad.js
+++ b/src/common/dicts/ad.js
@@ -2,6 +2,27 @@
* @Author: ch
* @Date: 2022-05-31 11:05:08
* @LastEditors: ch
- * @LastEditTime: 2022-05-31 11:07:19
+ * @LastEditTime: 2022-05-31 11:15:27
* @Description: file content
- */
\ No newline at end of file
+ */
+
+
+const AD_PLATFORM = {
+ PC: 2,
+ MOBILE : 1
+}
+const AD_LOCATION = {
+ // 首页轮播图
+ HOME_BANNER: 1,
+ // 首页精装区
+ HOME_HARDCOVER: 2,
+ // 分类banner
+ CATEGORY_BANNER : 3
+
+}
+export {
+ // 广告所属平台
+ AD_PLATFORM,
+ // 广告位置
+ AD_LOCATION
+}
\ No newline at end of file
diff --git a/src/common/utils/utils.js b/src/common/utils/utils.js
index a964435..29a39e9 100644
--- a/src/common/utils/utils.js
+++ b/src/common/utils/utils.js
@@ -2,18 +2,19 @@
* @Author: ch
* @Date: 2022-03-17 19:15:10
* @LastEditors: ch
- * @LastEditTime: 2022-05-23 11:40:29
+ * @LastEditTime: 2022-05-31 15:17:45
* @Description: 一些无法归类的公共方法容器
*/
import {
- toAsyncAwait as ToAsyncAwait,
- isPhone as IsPhone,
- formatDate as FormatDate,
- creatUuid as CreateUUID,
- formatSearchJson as FormatSearchJson
+ toAsyncAwait as ToAsyncAwait,
+ isPhone as IsPhone,
+ formatDate as FormatDate,
+ creatUuid as CreateUUID,
+ formatSearchJson as FormatSearchJson
} from "js-util-all";
+import ENV from '@/common/config/env';
/** 防抖函数
* 首次运行时把定时器赋值给一个变量, 第二次执行时,
@@ -22,28 +23,56 @@ import {
* 没有执行清除定时器, 超过一定时间后触发回调函数。
*/
const Debounce = (fn, delay) => {
- let timer
- return function() {
- const that = this
- const _args = arguments // 存一下传入的参数
- if (timer) {
- clearTimeout(timer)
- }
- timer = setTimeout(function() {
- fn.apply(that, _args)
- }, delay)
- }
+ let timer
+ return function () {
+ const that = this
+ const _args = arguments // 存一下传入的参数
+ if (timer) {
+ clearTimeout(timer)
+ }
+ timer = setTimeout(function () {
+ fn.apply(that, _args)
+ }, delay)
+ }
+}
+/**
+ * 广告跳转
+ * 兼容APP,根据域名判断站内跳转还是站外跳转
+ * @param {*} link
+ */
+const AdJump = (link) => {
+ if (!/^(http|https):\/\/./.test(link)) {
+ uni.$u.toast('非法链接,暂不跳转!');
+ return false;
+ }
+ console.log(link);
+ const isInner = link.includes(ENV.staticUrl);
+ if (isInner) {
+ uni.navigateTo({
+ url : link.replace(ENV.staticUrl,'')
+ })
+ } else {
+ // #ifdef H5
+ window.location.href = link;
+ // #endif
+ // #ifdef APP-PLUS
+ plus.runtime.openURL(link);
+ // #endif
+ }
+
}
// 工具类的文件需要把文件提供的工具类统一放最下方做一个统一输出
export {
- // async await 标识结果处理
- ToAsyncAwait,
- // 判断是否为手机号
- IsPhone,
- // 时间格式化
- FormatDate,
- FormatSearchJson,
- CreateUUID,
- // 防抖函数
- Debounce
+ // async await 标识结果处理
+ ToAsyncAwait,
+ // 判断是否为手机号
+ IsPhone,
+ // 时间格式化
+ FormatDate,
+ FormatSearchJson,
+ CreateUUID,
+ // 防抖函数
+ Debounce,
+ // 广告跳转
+ AdJump
}
\ No newline at end of file
diff --git a/src/pages/goods/category.vue b/src/pages/goods/category.vue
index 3f61c30..bbaa5e5 100644
--- a/src/pages/goods/category.vue
+++ b/src/pages/goods/category.vue
@@ -17,10 +17,11 @@
-
+
-
+
{{item.name}}
@@ -30,9 +31,9 @@
-
-
+
@@ -45,6 +46,9 @@
import {ApiGetCategoryOneList, ApiGetCategoryTwoAndGoods} from '@/common/api/goods';
import BsEmpty from "@/components/BsEmpty";
import UiPageHeader from '../../components/UiPageHeader.vue';
+import { AD_LOCATION } from '@/common/dicts/ad';
+import { ApiGetAdList } from '@/common/api/ad';
+import { AdJump } from '@/common/utils';
export default {
components: { BsEmpty, UiPageHeader },
data() {
@@ -59,6 +63,11 @@ export default {
isLoading: true,
};
},
+ computed:{
+ curTwoCategory(){
+ return this.categoryData[this.curIndex];
+ }
+ },
onLoad() {
// 加载页面数据
this.getCategoryData();
@@ -94,11 +103,12 @@ export default {
item.children = [];
item.isLoading = true;
this.getTwoCategoryData(item);
+ this.getTwoCategoryAd(item);
return item;
});
this.isLoading = false;
},
-
+
/**
* 初始化分类列表数据
* @param {Object} result
@@ -107,6 +117,21 @@ export default {
const {error, result} = await ApiGetCategoryTwoAndGoods({categoryId : item.id});
this.$set(item, 'children', result);
this.$set(item, 'isLoading', false);
+ },
+ async getTwoCategoryAd(item){
+ const {error, result} = await ApiGetAdList({
+ loacation : AD_LOCATION.CATEGORY_BANNER,
+ productCategoryId : item.id
+ });
+ if(result.length){
+ this.$set(item, 'adPictureUrl', result[0].pictureUrl);
+ this.$set(item, 'adJumpUrl', result[0].jumpUrl);
+ }
+ },
+ handleAdJump(link){
+ if(link){
+ AdJump(link);
+ }
}
},
};
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index f82f8b1..0d57ee0 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2019-08-22 19:41:20
* @LastEditors: ch
- * @LastEditTime: 2022-05-21 16:30:22
+ * @LastEditTime: 2022-05-31 14:56:04
* @Description: file content
-->
@@ -24,9 +24,9 @@
+ @click="handleCategory(item)">
-
+
{{item.name}}
@@ -50,31 +50,15 @@ import Banner from './modules/Banner';
import {ApiGetBannerData} from '@/common/api/index.js';
import {ApiGetHomeSeckill} from '@/common/api/seckill.js';
import {ApiGetCategoryNav, ApiGetRecommendedGoodsList} from '@/common/api/goods.js';
+import {ApiGetAdList} from '@/common/api/ad.js';
+import {AD_LOCATION} from '@/common/dicts/ad.js';
+import {AdJump} from '@/common/utils';
export default {
components : {BsChoiceGoods, Pick, Banner, Seckill},
data(){
return {
scrollTop : 0,
- bannerList: [
- { url : 'https://msb-edu-prod.oss-cn-beijing.aliyuncs.com/uc/account-avatar/banner6.jpg',
- link : 'https://m.mashibing.com/live/1530'
- },
- { url : 'https://msb-edu-prod.oss-cn-beijing.aliyuncs.com/uc/account-avatar/banner5.jpg',
- link : 'https://m.mashibing.com/course/1373/1/'
- },
- { url : 'https://msb-edu-dev.oss-cn-beijing.aliyuncs.com/uc/account-avatar/banner4.jpg',
- id : 13
- },
- { url : 'https://msb-edu-dev.oss-cn-beijing.aliyuncs.com/uc/account-avatar/1.png',
- id : 30
- },
- { url : 'https://msb-edu-dev.oss-cn-beijing.aliyuncs.com/uc/account-avatar/2banner.png',
- id : 15
- },
- { url : 'https://msb-edu-dev.oss-cn-beijing.aliyuncs.com/uc/account-avatar/3banner.png',
- id : 40
- }
- ],
+ bannerList: [],
categoryList : [
],
recommendedGoodsList : [],
@@ -86,6 +70,7 @@ export default {
this.getCategoryList();
this.getRecommendedGoodsList();
this.getSeckillList();
+ this.getBannerData();
},
onReachBottom(){
this.$refs.goodsGroup.next();
@@ -106,10 +91,11 @@ export default {
},
methods : {
async getCategoryList(){
- const {error, result} = await ApiGetCategoryNav();
- if(result){
- this.categoryList = result;
- }
+
+ const {error, result} = await ApiGetAdList({
+ location : AD_LOCATION.HOME_HARDCOVER
+ });
+ this.categoryList = result;
},
async getRecommendedGoodsList(){
@@ -119,11 +105,22 @@ export default {
}
},
+ async getBannerData(){
+ const {error, result} = await ApiGetAdList({
+ location : AD_LOCATION.HOME_BANNER
+ });
+ this.bannerList = result;
+ },
async getSeckillList(){
const {error, result} = await ApiGetHomeSeckill();
if(result){
this.seckillData = result
}
+ },
+ handleCategory(item){
+ if(item.jumpUrl){
+ AdJump(item.jumpUrl);
+ }
}
}
}
diff --git a/src/pages/index/modules/Banner.vue b/src/pages/index/modules/Banner.vue
index 90ad818..49bfaa4 100644
--- a/src/pages/index/modules/Banner.vue
+++ b/src/pages/index/modules/Banner.vue
@@ -2,12 +2,13 @@
* @Author: ch
* @Date: 2022-03-23 10:31:12
* @LastEditors: ch
- * @LastEditTime: 2022-05-21 20:09:18
+ * @LastEditTime: 2022-05-31 14:54:22
* @Description: file content
-->
-
+
@@ -29,6 +30,7 @@