首页弹屏

已知活动结束时间和每天次数

// 首页弹屏
    show_actpop() {
      let {
        activity_paly: { activity_paly_num, end_time },
      } = this.data
      let now = new Date().getTime() / 1000
      let maxTime = wx.getStorageSync('indexpop').maxTime || '' // 24小时周期结束时间
      let count = wx.getStorageSync('indexpop').count || 0 // 周期内已弹次数
      let firstTime = wx.getStorageSync('indexpop').firstTime || '' // 周期内第一次弹出时间,即周期开始时间
      let last_time = wx.getStorageSync('indexpop').last_time || '' // 周期内上一次弹的时间
      let gapTime = wx.getStorageSync('indexpop').gapTime || '' //间隔时间:剩余时间 / 剩余次数
      if (!maxTime || now > maxTime) {
        count = 0
        firstTime = now
        maxTime = now + 24 * 60 * 60
        gapTime = (maxTime - now) / activity_paly_num
      }
      if (count < activity_paly_num && now < end_time) {
        if (count == 0 || now > last_time + gapTime) {
          last_time = now
          let remainCount = activity_paly_num - count
          gapTime = (maxTime - now) / remainCount
          count += 1
          wx.setStorageSync('indexpop', {
            firstTime,
            last_time,
            maxTime,
            gapTime,
            count,
          })
          this.setData({
            show_actpop: true,
          })
        }
      }
    },

你可能感兴趣的:(小程序,js)