广告跳转

feature/ad-0531-ch
ch 3 years ago
parent 7e4dd1b9ca
commit d6516bbfcf

@ -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
}))

@ -2,13 +2,34 @@
* @Author: ch * @Author: ch
* @Date: 2022-04-06 17:29:13 * @Date: 2022-04-06 17:29:13
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-04-15 14:17:14 * @LastEditTime: 2022-05-31 11:18:44
* @Description: file content * @Description: file content
*/ */
import {ToAsyncAwait, MsbRequestTk} from '@/common/utils'; import {ToAsyncAwait, MsbRequest, MsbRequestTk} from '@/common/utils';
const BASE_URL = '/mall/base'; 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));
/** /**
* 获取收货地址 * 获取收货地址
*/ */

@ -2,6 +2,27 @@
* @Author: ch * @Author: ch
* @Date: 2022-05-31 11:05:08 * @Date: 2022-05-31 11:05:08
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-31 11:07:19 * @LastEditTime: 2022-05-31 11:15:27
* @Description: file content * @Description: file content
*/ */
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
}

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-17 19:15:10 * @Date: 2022-03-17 19:15:10
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-23 11:40:29 * @LastEditTime: 2022-05-31 15:17:45
* @Description: 一些无法归类的公共方法容器 * @Description: 一些无法归类的公共方法容器
*/ */
@ -14,6 +14,7 @@ import {
formatSearchJson as FormatSearchJson formatSearchJson as FormatSearchJson
} from "js-util-all"; } from "js-util-all";
import ENV from '@/common/config/env';
/** /**
* 首次运行时把定时器赋值给一个变量 第二次执行时 * 首次运行时把定时器赋值给一个变量 第二次执行时
@ -23,17 +24,43 @@ import {
*/ */
const Debounce = (fn, delay) => { const Debounce = (fn, delay) => {
let timer let timer
return function() { return function () {
const that = this const that = this
const _args = arguments // 存一下传入的参数 const _args = arguments // 存一下传入的参数
if (timer) { if (timer) {
clearTimeout(timer) clearTimeout(timer)
} }
timer = setTimeout(function() { timer = setTimeout(function () {
fn.apply(that, _args) fn.apply(that, _args)
}, delay) }, 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 { export {
// async await 标识结果处理 // async await 标识结果处理
@ -45,5 +72,7 @@ export {
FormatSearchJson, FormatSearchJson,
CreateUUID, CreateUUID,
// 防抖函数 // 防抖函数
Debounce Debounce,
// 广告跳转
AdJump
} }

@ -17,10 +17,11 @@
<!-- 右侧 二级分类 --> <!-- 右侧 二级分类 -->
<scroll-view class="cate-right" @scrolltolower="reachBottom" :scroll-top="scrollTop" :scroll-y="true"> <scroll-view class="cate-right" @scrolltolower="reachBottom" :scroll-top="scrollTop" :scroll-y="true">
<image class="cate-tow-img" :src="`https://msb-edu-dev.oss-cn-beijing.aliyuncs.com/uc/account-avatar/category${categoryData[curIndex].id}.jpg`"></image> <image class="cate-tow-img" v-if="curTwoCategory.adPictureUrl" :src="curTwoCategory.adPictureUrl"
@click="handleAdJump(curTwoCategory.adJumpUrl)"></image>
<!-- <view @click="onTargetGoodsList(item.id)"> --> <!-- <view @click="onTargetGoodsList(item.id)"> -->
<view class="cate-tow-group" :class="idx === categoryData[curIndex].children.length - 1 ? 'cate-tow-group__last' :''" <view class="cate-tow-group" :class="idx === curTwoCategory.children.length - 1 ? 'cate-tow-group__last' :''"
v-for="(item, idx) in categoryData[curIndex].children" :key="idx"> v-for="(item, idx) in curTwoCategory.children" :key="idx">
<text class="cate-tow-group--title">{{item.name}}</text> <text class="cate-tow-group--title">{{item.name}}</text>
<view class="cate-tow-group--item" v-for="i in item.productList" :key="i.id" <view class="cate-tow-group--item" v-for="i in item.productList" :key="i.id"
@click="$Router.push(`/goodsDetail?id=${i.id}`)"> @click="$Router.push(`/goodsDetail?id=${i.id}`)">
@ -30,9 +31,9 @@
</view> </view>
</view> </view>
<!-- </view> --> <!-- </view> -->
<BsEmpty class="empty" v-if="!categoryData[curIndex].children.length && !categoryData[curIndex].isLoading" <BsEmpty class="empty" v-if="!curTwoCategory.children.length && !curTwoCategory.isLoading"
:icon="require('@/static/common/empty_goods.png')" /> :icon="require('@/static/common/empty_goods.png')" />
<u-loadmore status="loading" v-if="categoryData[curIndex].isLoading" /> <u-loadmore status="loading" v-if="curTwoCategory.isLoading" />
</scroll-view> </scroll-view>
</view> </view>
<BsEmpty v-if="!categoryData.length && !isLoading" /> <BsEmpty v-if="!categoryData.length && !isLoading" />
@ -45,6 +46,9 @@
import {ApiGetCategoryOneList, ApiGetCategoryTwoAndGoods} from '@/common/api/goods'; import {ApiGetCategoryOneList, ApiGetCategoryTwoAndGoods} from '@/common/api/goods';
import BsEmpty from "@/components/BsEmpty"; import BsEmpty from "@/components/BsEmpty";
import UiPageHeader from '../../components/UiPageHeader.vue'; 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 { export default {
components: { BsEmpty, UiPageHeader }, components: { BsEmpty, UiPageHeader },
data() { data() {
@ -59,6 +63,11 @@ export default {
isLoading: true, isLoading: true,
}; };
}, },
computed:{
curTwoCategory(){
return this.categoryData[this.curIndex];
}
},
onLoad() { onLoad() {
// //
this.getCategoryData(); this.getCategoryData();
@ -94,6 +103,7 @@ export default {
item.children = []; item.children = [];
item.isLoading = true; item.isLoading = true;
this.getTwoCategoryData(item); this.getTwoCategoryData(item);
this.getTwoCategoryAd(item);
return item; return item;
}); });
this.isLoading = false; this.isLoading = false;
@ -107,6 +117,21 @@ export default {
const {error, result} = await ApiGetCategoryTwoAndGoods({categoryId : item.id}); const {error, result} = await ApiGetCategoryTwoAndGoods({categoryId : item.id});
this.$set(item, 'children', result); this.$set(item, 'children', result);
this.$set(item, 'isLoading', false); 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);
}
} }
}, },
}; };

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2019-08-22 19:41:20 * @Date: 2019-08-22 19:41:20
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-21 16:30:22 * @LastEditTime: 2022-05-31 14:56:04
* @Description: file content * @Description: file content
--> -->
<template> <template>
@ -24,9 +24,9 @@
<view class="category"> <view class="category">
<view class="category--item" v-for="item in categoryList" :key="item.id" <view class="category--item" v-for="item in categoryList" :key="item.id"
@click="$Router.push(`/goodsList?categoryId=${item.id}`)"> @click="handleCategory(item)">
<view class="category--image-box"> <view class="category--image-box">
<image class="category--image" :src="item.picture"></image> <image class="category--image" :src="item.pictureUrl"></image>
</view> </view>
<text class="category--title">{{item.name}}</text> <text class="category--title">{{item.name}}</text>
</view> </view>
@ -50,31 +50,15 @@ import Banner from './modules/Banner';
import {ApiGetBannerData} from '@/common/api/index.js'; import {ApiGetBannerData} from '@/common/api/index.js';
import {ApiGetHomeSeckill} from '@/common/api/seckill.js'; import {ApiGetHomeSeckill} from '@/common/api/seckill.js';
import {ApiGetCategoryNav, ApiGetRecommendedGoodsList} from '@/common/api/goods.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 { export default {
components : {BsChoiceGoods, Pick, Banner, Seckill}, components : {BsChoiceGoods, Pick, Banner, Seckill},
data(){ data(){
return { return {
scrollTop : 0, scrollTop : 0,
bannerList: [ 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
}
],
categoryList : [ categoryList : [
], ],
recommendedGoodsList : [], recommendedGoodsList : [],
@ -86,6 +70,7 @@ export default {
this.getCategoryList(); this.getCategoryList();
this.getRecommendedGoodsList(); this.getRecommendedGoodsList();
this.getSeckillList(); this.getSeckillList();
this.getBannerData();
}, },
onReachBottom(){ onReachBottom(){
this.$refs.goodsGroup.next(); this.$refs.goodsGroup.next();
@ -106,10 +91,11 @@ export default {
}, },
methods : { methods : {
async getCategoryList(){ async getCategoryList(){
const {error, result} = await ApiGetCategoryNav();
if(result){ const {error, result} = await ApiGetAdList({
location : AD_LOCATION.HOME_HARDCOVER
});
this.categoryList = result; this.categoryList = result;
}
}, },
async getRecommendedGoodsList(){ 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(){ async getSeckillList(){
const {error, result} = await ApiGetHomeSeckill(); const {error, result} = await ApiGetHomeSeckill();
if(result){ if(result){
this.seckillData = result this.seckillData = result
} }
},
handleCategory(item){
if(item.jumpUrl){
AdJump(item.jumpUrl);
}
} }
} }
} }

@ -2,12 +2,13 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-23 10:31:12 * @Date: 2022-03-23 10:31:12
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-21 20:09:18 * @LastEditTime: 2022-05-31 14:54:22
* @Description: file content * @Description: file content
--> -->
<template> <template>
<view class="banner"> <view class="banner">
<u-swiper bgColor="none" @click="goDetail" radius="18rpx" keyName="url" :list="data" height="240rpx" circular indicator indicatorMode="dot"></u-swiper> <u-swiper bgColor="none" radius="18rpx" height="240rpx" keyName="pictureUrl" indicatorMode="dot"
@click="goDetail" :list="data" circular indicator></u-swiper>
<view class="desc"> <view class="desc">
<view class="desc--item"> <view class="desc--item">
<image class="desc--icon" src='@/static/index/bz.png'></image> <image class="desc--icon" src='@/static/index/bz.png'></image>
@ -29,6 +30,7 @@
</view> </view>
</template> </template>
<script> <script>
import {AdJump} from '@/common/utils';
export default { export default {
data(){ data(){
return { return {
@ -44,18 +46,9 @@ export default {
methods:{ methods:{
goDetail(idx){ goDetail(idx){
let item = this.data[idx]; let item = this.data[idx];
if(item.link){ if(item.jumpUrl){
// #ifdef H5 AdJump(item.jumpUrl);
window.location.href = item.link;
// #endif
// #ifdef APP-PLUS
plus.runtime.openURL(item.link);
// #endif
}else{
this.$Router.push(`/goodsDetail?id=${this.data[idx].id}`)
} }
} }
} }
} }

Loading…
Cancel
Save