绿满眶商城微信小程序-uniapp
zxl
2025-12-16 8e36cf0540a398cc48ee96cdc4e294f57300a700
pages/tabbar/index/home.vue
@@ -403,63 +403,72 @@
   onShow() {
      getSessionId().then(res=>{
         console.log('res',JSON.stringify(res))
         this.pageSessionNo = res.data.data
         if(this.pageSessionNo){
         let   param = Object.assign({},this.actionParam);
         this.actionParam.sessionId = this.pageSessionNo
         param.sessionId = this.pageSessionNo
            userAction(param)
         }
      if (res.code === 200){
        this.pageSessionNo = res.data.data
        if(this.pageSessionNo){
          let   param = Object.assign({},this.actionParam);
          this.actionParam.sessionId = this.pageSessionNo
          param.sessionId = this.pageSessionNo
          userAction(param)
        }
        this.getONPrizeActivity()
        let showPopup = storage.getPopupShow();
        console.log(showPopup)
        if (showPopup) {
          console.log("首次打开,显示弹窗");
          storage.setPopupShow(true); // 标记为已显示
        } else {
          console.log("已显示过,不弹窗");
        }
        if(showPopup){
          this.openActivityPopup()
        }
        if (!this.userId) {
          this.getUserId()
        }
        // const token = storage.getAccessToken();
        // if (! token) {
        //  this.wxSilentLogin(() => {
        //   this.loadVideos();
        //  })
        // } else {
        //      this.loadVideos();
        // }
        if (this.videoList.length < 1) {
          this.loading = false;
          this.videoNoMore = false;
          console.log('触发数据加载')
          this.loadVideos();
        }
        // 如果视频按下暂停后切换页面再回到页面时,只算暂停时间(因为暂停时间和离开页面时间是重复的,只算一个)
        if (this.startHidenTime !== 0 && this.currentVideoIsPlaying) {
          const duration = Date.now() - this.startHidenTime
          this.totalHidenTime += duration
        }
      }
      })
    this.getONPrizeActivity()
    let showPopup = storage.getPopupShow();
    console.log(showPopup)
    if (showPopup) {
      console.log("首次打开,显示弹窗");
      storage.setPopupShow(true); // 标记为已显示
    } else {
      console.log("已显示过,不弹窗");
    }
    if(showPopup){
      this.openActivityPopup()
    }
      if (!this.userId) {
         this.getUserId()
      }
      // const token = storage.getAccessToken();
      // if (! token) {
      //  this.wxSilentLogin(() => {
      //   this.loadVideos();
      //  })
      // } else {
      //      this.loadVideos();
      // }
      if (this.videoList.length < 1) {
         this.loading = false;
         this.videoNoMore = false;
         console.log('触发数据加载')
         this.loadVideos();
      }
      // 如果视频按下暂停后切换页面再回到页面时,只算暂停时间(因为暂停时间和离开页面时间是重复的,只算一个)
      if (this.startHidenTime !== 0 && this.currentVideoIsPlaying) {
         const duration = Date.now() - this.startHidenTime
         this.totalHidenTime += duration
      }
   },
  onUnload() {
    let   param = Object.assign({},this.actionParam);
    if (this.sendOnShow)return
    param.pageStatus = "LEAVE"
    userAction(param)
    // if (this.isNotEmpty(param.sessionId)){
      console.log("离开页面开始记录")
      //TODO 页面刷新 导致onshow未执行,导致sessionId未赋值
      userAction(param)
    // }
  },
  onHide() {
    this.startHidenTime = Date.now()
    let   param = Object.assign({},this.actionParam);
    this.sendOnShow = true;
    param.pageStatus = "LEAVE"
    console.log("执行onHide的userAction")
    userAction(param)
  },
   onLoad(option) {
@@ -598,6 +607,15 @@
      });
   },
   methods: {
     isNotEmpty(value) {
       if (value === null || value === undefined) {
         return false;
       }
       if (typeof value === 'string') {
         return value.trim() !== '';
       }
       return true;
     },
    getONPrizeActivity(){
      getONPrizeActivity().then(res =>{
        if(res.statusCode=== 200){