vue 每天第一次开启程序,先清空指定数据

近期做了个今日任务的功能,需要每天将任务列表的状态还原。原来思路是设置定时任务,每晚23:59执行;但是发现H5页面没有打开时,定时任务压根就不会执行。所以又做了个临时措施: 每天第一次开启页面时,还原任务状态。

代码如下:

async smartRecordTime () {
      console.log('smartRecordTime', 'smartRecordTime')
      var now = new Date().toLocaleDateString()
      var time = Date.parse(new Date(now))
      let res = await awaitWrap(this.uplusApi.upUserModule.getUserInfo())
      console.log('smartRecordTime', res)
      if (res[1]) {
        this.userId = res[1].retData.userId
      }
      // 获取保存的页面开启时间
      res = await awaitWrap(this.uplusApi.upStorageModule.getStringValue({storageName: this.userId + ',firstDate', storageValue: ''}))
      console.log('res', res)
      if (res[1].retData) {
        console.log('time2', time)
        // res[1].retData = 16000000
       // 与当前时间相比较,如果小于当前时间,则还原状态,并再次保存时间
        if (time > res[1].retData) {
          console.log('time1', time)
          this.uplusApi.upStorageModule.deleteNode({storageName: this.userId + ',todayTasks'}).then(result => console.log('result deleteNode', result))
          this.$refs.myEnergy.initEnergyList()
          this.uplusApi.upStorageModule.putStringValue({storageName: this.userId + ',firstDate', storageValue: JSON.stringify(time)})
            .then(result => console.log('result', result)).catch(err => console.log('err', err))
        }
      } else {
        console.log('time', '今天第一次开启')
        this.uplusApi.upStorageModule.deleteNode({storageName: this.userId + ',todayTasks'})
        this.$refs.myEnergy.initEnergyList()
        this.uplusApi.upStorageModule.putStringValue({storageName: this.userId + ',firstDate', storageValue: JSON.stringify(time)})
          .then(result => console.log('result1', result))
          .catch(err => console.log('err1', err))
      }
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值