广告跳转

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
* @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));
/**
* 获取收货地址
*/

@ -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
*/
*/
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,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
}

@ -17,10 +17,11 @@
<!-- 右侧 二级分类 -->
<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 class="cate-tow-group" :class="idx === categoryData[curIndex].children.length - 1 ? 'cate-tow-group__last' :''"
v-for="(item, idx) in categoryData[curIndex].children" :key="idx">
<view class="cate-tow-group" :class="idx === curTwoCategory.children.length - 1 ? 'cate-tow-group__last' :''"
v-for="(item, idx) in curTwoCategory.children" :key="idx">
<text class="cate-tow-group--title">{{item.name}}</text>
<view class="cate-tow-group--item" v-for="i in item.productList" :key="i.id"
@click="$Router.push(`/goodsDetail?id=${i.id}`)">
@ -30,9 +31,9 @@
</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')" />
<u-loadmore status="loading" v-if="categoryData[curIndex].isLoading" />
<u-loadmore status="loading" v-if="curTwoCategory.isLoading" />
</scroll-view>
</view>
<BsEmpty v-if="!categoryData.length && !isLoading" />
@ -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);
}
}
},
};

@ -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
-->
<template>
@ -24,9 +24,9 @@
<view class="category">
<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">
<image class="category--image" :src="item.picture"></image>
<image class="category--image" :src="item.pictureUrl"></image>
</view>
<text class="category--title">{{item.name}}</text>
</view>
@ -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);
}
}
}
}

@ -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
-->
<template>
<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--item">
<image class="desc--icon" src='@/static/index/bz.png'></image>
@ -29,6 +30,7 @@
</view>
</template>
<script>
import {AdJump} from '@/common/utils';
export default {
data(){
return {
@ -44,18 +46,9 @@ export default {
methods:{
goDetail(idx){
let item = this.data[idx];
if(item.link){
// #ifdef H5
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}`)
if(item.jumpUrl){
AdJump(item.jumpUrl);
}
}
}
}

Loading…
Cancel
Save