Bläddra i källkod

记录浏览时长

duanshenglang 8 månader sedan
förälder
incheckning
676d1f6c4d
2 ändrade filer med 52 tillägg och 3 borttagningar
  1. 9 3
      lottery/carOwnerScreening.html
  2. 43 0
      lottery/registrationActivity.html

+ 9 - 3
lottery/carOwnerScreening.html

@@ -127,6 +127,12 @@
     text-align: end;
   }
 
+  .el-select-dropdown__item {
+    white-space: normal;
+    overflow: unset;
+    height: auto;
+  }
+
   .no_testDrive {
     font-size: 16px;
     color: #FFFFFF;
@@ -307,10 +313,10 @@
       if (!this.env || this.env === 'prod') {
         this.httpUrl = 'https://wlapi.wefanbot.com'
       } else {
-        // this.httpUrl = 'http://test.wefanbot.com:18993'
-        this.httpUrl = 'http://192.168.1.147:18993'
+        this.httpUrl = 'http://test.wefanbot.com:18993'
+        // this.httpUrl = 'http://192.168.1.147:18993'
       }
-      this.ifH5Type()
+      // this.ifH5Type()
       // this.getAllCar()
       // this.getCityLevel()
     },

+ 43 - 0
lottery/registrationActivity.html

@@ -392,6 +392,7 @@
           verificationGuide: '',
           verificationFailGuide: '',
           verificationFailGuide2: '',
+          browseId: null,
         },
         step: 1,
         verificationCode: '',
@@ -400,6 +401,8 @@
         province: '',
         city: '',
         loading: false,
+        intervalId: null, // 定时任务的ID
+        loadTime: null,   // 页面加载的时间戳
       }
     },
     created () {
@@ -412,6 +415,9 @@
       }
       this.ifH5Type()
     },
+    beforeDestroy() {
+      this.clearIntervalTask() // 在组件销毁前清除定时任务
+    },
     methods: {
       ifH5Type () {
         if (this.getQueryParam('openId') || localStorage.getItem('openId')) {
@@ -580,6 +586,8 @@
                 // 不符合资格
                 this.step = 5
               }
+              this.loadTime = Date.now() // 记录页面加载时间
+              this.startInterval() // 启动定时任务
             } else {
               this.$message({
                 message: msg,
@@ -587,6 +595,41 @@
             }
           })
       },
+      startInterval() {
+        if (this.intervalId !== null) {
+          clearInterval(this.intervalId); // 如果定时任务已经存在,先清除它
+        }
+        this.intervalId = setInterval(() => {
+          const elapsedTime = Math.floor((Date.now() - this.loadTime) / 1000); // 计算停留时长(秒)
+          this.sendDataToServer(this.toshopData.browseId, elapsedTime);
+        }, 10000); // 每10秒调用一次
+      },
+      sendDataToServer(browseId, elapsedTime) {
+        let openId = this.getQueryParam('openId') || localStorage.getItem('openId')
+        fetch(this.httpUrl + `/scrm/v1/wxcp-toshop-client-browse-history/p/updateBrowseDuration?openId=${openId}`, {
+          method: 'post',
+          body: JSON.stringify({
+            id: browseId,
+            duration: elapsedTime,
+          }),
+          headers: {
+            'Content-Type': 'application/json'
+          }
+        }).then(res => {
+          return res.json()
+        }).then(result => {
+          let { data, code, msg } = result
+          if (data) {
+          } else {
+          }
+        })
+      },
+      clearIntervalTask() {
+        if (this.intervalId !== null) {
+          clearInterval(this.intervalId)
+          this.intervalId = null // 清空定时任务的ID
+        }
+      },
       toSignUp () {
         if (this.step === 1) {
           this.step = 2