|
|
@@ -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
|