二手车交易,后台点击弹框关闭时记录浏览量

This commit is contained in:
2025-03-19 10:14:13 +08:00
parent c5176ebc02
commit 48ab0cfb52
2 changed files with 18 additions and 27 deletions

View File

@ -98,6 +98,7 @@
</template> </template>
<script> <script>
import {myMixins} from "@/utils/myMixins" import {myMixins} from "@/utils/myMixins"
import {carInfoDetail,saveRecord} from "@/api/secondHandCar"; import {carInfoDetail,saveRecord} from "@/api/secondHandCar";
import { Dialog } from 'vant'; import { Dialog } from 'vant';
@ -119,8 +120,13 @@ export default {
} }
}, },
async mounted() { async mounted() {
// console.log(" localStorage.setItem('indexActiveTab', this.activeTab);", localStorage.getItem('indexActiveTab')) window.addEventListener('message', (event) => {
// 页面加载时记录进入时间 if (event.data === 'dialogClosed') {
console.log('Dialog 已关闭');
this.getDuration(1)
// 执行关闭后的逻辑
}
});
this.startTime = new Date(); this.startTime = new Date();
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
this.id=this.$route.query.id || urlParams.get('id'); this.id=this.$route.query.id || urlParams.get('id');
@ -140,22 +146,10 @@ export default {
} }
this.imgSrcList.unshift(res?.data?.vehicleAnglePhoto) this.imgSrcList.unshift(res?.data?.vehicleAnglePhoto)
} }
document.addEventListener('visibilitychange', ( ) => {
let state = document.visibilityState
if (state == 'hidden') { // 用户离开了
console.log("用户离开了1")
// 使用 sendBeacon 发送数据
/*const data = new FormData();
data.append('duration', 1);
navigator.sendBeacon('/api/getDuration', data);*/
this.getDuration(1);
console.log("用户离开了2")
}
});
}, },
/* destroyed() { destroyed() {
this.getDuration(1) this.getDuration(1)
},*/ },
methods:{ methods:{
formatToWan(num) { formatToWan(num) {
let result = (num / 10000).toString(); let result = (num / 10000).toString();

View File

@ -71,7 +71,12 @@ export default {
} }
}, },
async mounted() { async mounted() {
// 页面加载时记录进入时间 window.addEventListener('message', (event) => {
if (event.data === 'dialogClosed') {
console.log('Dialog 已关闭');
this.getDuration(1)
}
});
this.startTime = new Date(); this.startTime = new Date();
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
this.id=this.$route.query.id || urlParams.get('id'); this.id=this.$route.query.id || urlParams.get('id');
@ -84,18 +89,10 @@ export default {
}) })
this.detailInfo = res?.data this.detailInfo = res?.data
} }
document.addEventListener('visibilitychange', async ( ) => {
let state = document.visibilityState
if (state == 'hidden') { // 用户离开了
console.log("用户离开了1")
await this.getDuration(1);
console.log("用户离开了2")
}
});
}, },
/*destroyed() { destroyed() {
this.getDuration(1) this.getDuration(1)
},*/ },
methods:{ methods:{
getDuration(type){ getDuration(type){
const endTime = new Date(); const endTime = new Date();