Browse Source

对接完成开屏页和首页ad广告弹窗

master
邓平艺 4 years ago
parent
commit
60aa312bdb
  1. 5
      App.vue
  2. 14
      components/lf-adModal/lf-adModal.vue
  3. 39
      pages/index/index/index.vue
  4. 48
      pages/index/openScreenAd/openScreenAd.vue

5
App.vue

@ -5,11 +5,10 @@ export default {
globalData:{ globalData:{
giftLogin:false, giftLogin:false,
share: false, // false share: false, // false
app_first_full: true,
app_first_alert: true
}, },
onLaunch: function(e) { onLaunch: function(e) {
// 广 TODO
// this.$url('/pages/index/openScreenAd/openScreenAd', {type: 'redirect'});
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
var referrerInfo = e.referrerInfo; var referrerInfo = e.referrerInfo;
if (referrerInfo.appId) { if (referrerInfo.appId) {

14
components/lf-adModal/lf-adModal.vue

@ -1,12 +1,12 @@
<template> <template>
<view class="content" v-if="value">
<view class="content" v-if="value && list.length">
<view class="box"> <view class="box">
<swiper class="swiper" :circular="true" <swiper class="swiper" :circular="true"
indicator-active-color="#0091ff" indicator-active-color="#0091ff"
:current="current" :current="current"
:indicator-dots="list.length > 1"> :indicator-dots="list.length > 1">
<swiper-item v-for="(item, index) in list" :key="index"> <swiper-item v-for="(item, index) in list" :key="index">
<image class="img" :src="item" mode="aspectFill" @click="clickAd"></image>
<image class="img" :src="item.image" mode="aspectFill" @click="clickAd(item)"></image>
</swiper-item> </swiper-item>
</swiper> </swiper>
<view class="close" @click="close"> <view class="close" @click="close">
@ -22,19 +22,23 @@
value: { value: {
type: Boolean, type: Boolean,
default: true default: true
},
list: {
type: Array,
default: []
} }
}, },
data(){ data(){
return { return {
list: ['https://picsum.photos/200', 'https://picsum.photos/200']
} }
}, },
created(){ created(){
}, },
methods: { methods: {
clickAd(){
this.$msg('您点击了广告图')
clickAd(item){
this.$url(item.url);
}, },
close(){ close(){
this.$emit('update:value', false); this.$emit('update:value', false);

39
pages/index/index/index.vue

@ -379,7 +379,7 @@
</view> </view>
</view> </view>
<!-- ad广告弹出组件 TODO 暂时先注释 --> <!-- ad广告弹出组件 TODO 暂时先注释 -->
<!-- <lf-ad-modal :value.sync="show_ad"></lf-ad-modal> -->
<lf-ad-modal :value.sync="show_ad" :list="ad_modal_list"></lf-ad-modal>
<!-- 回到顶部组件 --> <!-- 回到顶部组件 -->
<u-back-top :scrollTop="pageScrollTop"></u-back-top> <u-back-top :scrollTop="pageScrollTop"></u-back-top>
<!-- tabbar组件 --> <!-- tabbar组件 -->
@ -452,7 +452,8 @@
userInfo: '', userInfo: '',
microData:"", microData:"",
is_login:'',// is_login:'',//
show_ad: true, // ad广
show_ad: false, // ad广
ad_modal_list: [], // ad广
nav_bg_color: 'transparent' ,// nav_bg_color: 'transparent' ,//
recommend_list: [ recommend_list: [
{ {
@ -532,7 +533,7 @@
this.isLogin=!!this.$cookieStorage.get('user_token') this.isLogin=!!this.$cookieStorage.get('user_token')
let toekn = this.$cookieStorage.get('user_token'); let toekn = this.$cookieStorage.get('user_token');
if (toekn) { if (toekn) {
this.getUserInfo(); this.getUserInfo();
} }
@ -550,8 +551,17 @@
// //
onLoad(e) { onLoad(e) {
//
var gbConfig = this.$cookieStorage.get('globalConfig') || '';
// 广
if(app.globalData.app_first_full){
getApp().globalData.app_first_full = false;
this.$url('/pages/index/openScreenAd/openScreenAd', {type: 'launch'});
}else if(app.globalData.app_first_alert){
getApp().globalData.app_first_alert = false;
this.getAlertAd();
}
//
var gbConfig = this.$cookieStorage.get('globalConfig') || '';
this.config=gbConfig; this.config=gbConfig;
@ -598,6 +608,25 @@
}, },
// //
methods: { methods: {
getAlertAd(){
this.$http.get({
api: '/api/ad'
}).then(res => {
let alert = res.data.data.alert;
this.alert = alert;
if(this.$isRight(alert)){
if(this.$shared.isValueType(alert.image) == 'array'){
this.ad_modal_list = alert.image;
}else{
this.ad_modal_list.push({
image: alert.image,
url: alert.url
})
}
this.show_ad = true;
}
});
},
close(){ close(){
this.setData({ this.setData({
showNoGift:false showNoGift:false

48
pages/index/openScreenAd/openScreenAd.vue

@ -1,7 +1,9 @@
<template> <template>
<view class="content"> <view class="content">
<image class="img" src="https://picsum.photos/200" mode="aspectFill"></image>
<view class="tips" @click="next">跳过 {{ num }}s</view>
<block v-if="$isRight(full)">
<image class="img" :src="full.image" mode="aspectFill" @click="clickAd"></image>
<view class="tips" @click="next">跳过 {{ num }}s</view>
</block>
</view> </view>
</template> </template>
@ -10,18 +12,12 @@
data(){ data(){
return { return {
num: 5, num: 5,
timer: null
timer: null,
full: {}
} }
}, },
onLoad(){ onLoad(){
this.timer = setInterval(() => {
this.num--;
if(this.num <= 0){
clearInterval(this.timer);
this.timer = null;
this.next();
}
}, 1000);
this.getAd();
}, },
onUnload(){ onUnload(){
if(this.timer){ if(this.timer){
@ -30,8 +26,35 @@
} }
}, },
methods: { methods: {
getAd(){
this.$http.get({
api: '/api/ad'
}).then(res => {
this.full = res.data.data.full;
if(this.$isRight(res.data.data.full)){
this.startTime();
}else{
this.next();
}
}).catch(rej => {
this.next();
})
},
startTime(){
this.timer = setInterval(() => {
this.num--;
if(this.num <= 0){
clearInterval(this.timer);
this.timer = null;
this.next();
}
}, 1000);
},
next(){ next(){
this.$url('/pages/index/index/index', {type: 'redirect'}); this.$url('/pages/index/index/index', {type: 'redirect'});
},
clickAd(){
this.$url(this.full.url, {type: 'redirect'});
} }
} }
} }
@ -50,6 +73,8 @@
.img{ .img{
width: 100%; width: 100%;
height: 100%; height: 100%;
position: absolute;
z-index: 9;
} }
.tips{ .tips{
position: absolute; position: absolute;
@ -64,6 +89,7 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
border-radius: 28rpx; border-radius: 28rpx;
z-index: 999;
} }
} }
</style> </style>
Loading…
Cancel
Save