Commit de742053 by howie

'弹窗广告组件修复'

parent a2bc5993
......@@ -23,51 +23,72 @@ Component({
},
ready() {
this.setData({
img: app.DFSImg(this.data.datas.componentData.imageUrl,700,null,1)
})
console.log(this.data.datas.componentData,'this.data.datas.componentData.once')
// if(!this.data.datas.componentData.once){
// console.log('laizhelile')
// let routes = getCurrentPages()
// let page = routes[routes.length - 1].route
// wx.removeStorageSync(`${app.globalData.shopInfo.shopCode}_popFlag_${page}_${this.data.datas.id}`)
// }
// if (this.getPopFlag() == 'true'){
// this.setData({
// domainShow : false
// })
// }else{
// this.setData({
// domainShow: true
// })
// if (this.data.datas.componentData.columnNum > 0 && this.data.datas.componentData.autoOff){
// this.autoOff()
// }
// }
let nowTime = Date.now()
let pushTime = this.data.datas.componentData.pushTime
// 如果没有设置时间范围,按老客户的需求执行(30天后过期),将条件设置为按天推送,间隔时间30天
if(pushTime.length == 0) {
this.data.datas.componentData.pushDay = 30
this.data.datas.componentData.pushFrequency = '2'
this.data.datas.componentData.isDayOrWeek = '0'
this.isPush()
}
// 设置了时间范围,且在时间范围中,根据条件推送
else if(pushTime.length > 0 && nowTime >= pushTime[0] && nowTime <= pushTime[1]) {
this.isPush()
}else {
// 不在时间范围中,关闭
this.setData({ domainShow: false })
let userInfo = wx.getStorageSync("loginUserInfo")
console.log("用户信息",userInfo);
if(this.data.datas.componentData.pushPeople == '1') {
if(userInfo.tagInfoResponseDTOS) {
try{
userInfo.tagInfoResponseDTOS.forEach(item => {
if(this.data.datas.componentData.pushDesignee.includes(item.id)) {
this.init()
throw Error()
}
})
}catch(e) {
console.log(e);
}
}
}
},
/**
* 组件的方法列表
*/
methods: {
init() {
this.setData({
img: app.DFSImg(this.data.datas.componentData.imageUrl,700,null,1)
})
console.log(this.data.datas.componentData,'this.data.datas.componentData.once')
// if(!this.data.datas.componentData.once){
// console.log('laizhelile')
// let routes = getCurrentPages()
// let page = routes[routes.length - 1].route
// wx.removeStorageSync(`${app.globalData.shopInfo.shopCode}_popFlag_${page}_${this.data.datas.id}`)
// }
// if (this.getPopFlag() == 'true'){
// this.setData({
// domainShow : false
// })
// }else{
// this.setData({
// domainShow: true
// })
// if (this.data.datas.componentData.columnNum > 0 && this.data.datas.componentData.autoOff){
// this.autoOff()
// }
// }
let nowTime = Date.now()
let pushTime = this.data.datas.componentData.pushTime
// 如果没有设置时间范围,按老客户的需求执行(30天后过期),将条件设置为按天推送,间隔时间30天
if(pushTime.length == 0) {
// if(this.datas.componentData.once){
// this.datas.componentData.pushFrequency = '0'
// }else {
// // 每次进入推送
// this.datas.componentData.pushFrequency = '1'
// } 暂时不兼容了
this.isPush()
}
// 设置了时间范围,且在时间范围中,根据条件推送
else if(pushTime.length > 0 && nowTime >= pushTime[0] && nowTime <= pushTime[1]) {
this.isPush()
}else {
// 不在时间范围中,关闭
this.setData({ domainShow: false })
}
},
// 判断何时定时关闭
autoOff() {
if (
......@@ -82,57 +103,61 @@ Component({
},
// 根据条件判断是否推送
isPush() {
let routes = getCurrentPages()
let page = routes[routes.length - 1].route
switch(this.data.datas.componentData.pushFrequency) {
case '0':
// 永久一次 推送
let pushCount = wx.getStorageSync('onlyPushOnceCount');
let pushCount = wx.getStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_onlyPushOnceCount`);
if(pushCount !='pushed') {
wx.setStorageSync('onlyPushOnceCount', 'pushed');
wx.setStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_onlyPushOnceCount`, 'pushed');
this.setData({ domainShow: true })
this.autoOff()
wx.removeStorageSync('dayPushTimeInfo') //清除按天推送的缓存,防止切换配置后出错
wx.removeStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_dayPushTimeInfo`) //清除按天推送的缓存,防止切换配置后出错
}else {
break;
}
break;
case '1':
// 每次进入 推送
wx.removeStorageSync('dayPushTimeInfo') //清除按天推送的缓存,防止切换配置后出错
wx.removeStorageSync('onlyPushOnceCount') //清除永久推送的缓存,防止切换配置后出错
wx.removeStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_dayPushTimeInfo`) //清除按天推送的缓存,防止切换配置后出错
wx.removeStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_onlyPushOnceCount`) //清除永久推送的缓存,防止切换配置后出错
this.setData({ domainShow: true })
this.autoOff()
break;
case '2':
// 自定义
if(this.data.datas.componentData.isDayOrWeek == 0) {
if(this.data.datas.componentData.isDayOrWeek == '0') {
// 按天推送
this.timedDayPush()
wx.removeStorageSync('onlyPushOnceCount') //清除永久推送的缓存,防止切换配置后出错
}else if(this.data.datas.componentData.isDayOrWeek == 1) {
wx.removeStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_onlyPushOnceCount`) //清除永久推送的缓存,防止切换配置后出错
}else if(this.data.datas.componentData.isDayOrWeek == '1') {
// 按周推送
this.timedWeekPush()
wx.removeStorageSync('dayPushTimeInfo') //清除按天推送的缓存,防止切换配置后出错
wx.removeStorageSync('onlyPushOnceCount') //清除永久推送的缓存,防止切换配置后出错
wx.removeStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_dayPushTimeInfo`) //清除按天推送的缓存,防止切换配置后出错
wx.removeStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_onlyPushOnceCount`) //清除永久推送的缓存,防止切换配置后出错
}
break;
}
},
// 自定义定时推送,按天数
timedDayPush() {
let routes = getCurrentPages()
let page = routes[routes.length - 1].route
// 如果缓存中没有信息,或者缓存中应该弹窗的时间已经过去了,则弹窗,并算出下一次弹窗的时间。
let nowTime = Date.now()
let pushTimeInfo = wx.getStorageSync('dayPushTimeInfo');
let pushTimeInfo = wx.getStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_dayPushTimeInfo`);
if(!pushTimeInfo || nowTime >= pushTimeInfo) {
this.setData({ domainShow: true })
this.autoOff()
let nextPushTime = nowTime + Number(this.data.datas.componentData.pushDay) * 24 * 60 * 60 * 1000;
wx.setStorageSync('dayPushTimeInfo', JSON.stringify(nextPushTime))
wx.setStorageSync(`${app.globalData.shopInfo.shopCode}_${page}_${this.data.datas.id}_dayPushTimeInfo`, JSON.stringify(nextPushTime))
}
},
// 自定义定时推送,按周几
timedWeekPush() {
// 当天是周几
let currentDayOfWeek = new Date().getDay()
let currentDayOfWeek = new Date().getDay().toString()
// 如果当天在推送的周几中,则推送
if(this.data.datas.componentData.pushWeek.includes(currentDayOfWeek)) {
this.setData({ domainShow: true })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment