二手车交易,记录浏览量

This commit is contained in:
2025-03-19 09:08:34 +08:00
parent e373acb818
commit 6864a1330f
2 changed files with 22 additions and 25 deletions

View File

@ -106,7 +106,6 @@ export default {
mixins:[myMixins],
data(){
return{
show:false,
current: 0,
noClick:true,
id:'',
@ -144,14 +143,15 @@ export default {
document.addEventListener('visibilitychange', async ( ) => {
let state = document.visibilityState
if (state == 'hidden') { // 用户离开了
console.log("用户离开了")
await this.getDuration()
console.log("用户离开了1")
await this.getDuration(1);
console.log("用户离开了2")
}
});
},
destroyed() {
this.getDuration()
},
/* destroyed() {
this.getDuration(1)
},*/
methods:{
formatToWan(num) {
let result = (num / 10000).toString();
@ -163,25 +163,23 @@ export default {
}
return result + '万';
},
getDuration(){
getDuration(type){
// 页面卸载时记录离开时间并计算浏览时长
const endTime = new Date();
const duration = (endTime - this.startTime) / 1000; // 计算时长(秒)\
this.saveRecord(duration);
this.saveRecord(duration,type);
},
async saveRecord(duration){
await saveRecord({type: this.recordType, carInfoId: this.id, duration})
async saveRecord(duration,type){
await saveRecord({type: type, carInfoId: this.id, duration})
},
handle(){
this.show=true
this.getDuration(2)
Dialog.alert({
message:this.detailInfo.contactNumber ,
confirmButtonText:'拨打电话',
showCancelButton:true,
}).then(async() => {
this.recordType=2
window.location.href = `tel:${this.detailInfo.contactNumber}`;
await this.getDuration()
}).catch(() => {
// on cancel
});

View File

@ -67,7 +67,6 @@ export default {
detailInfo:'',
duration:'',
startTime: null, // 记录进入时间
recordType:1,
isList:false,
}
},
@ -88,31 +87,31 @@ export default {
document.addEventListener('visibilitychange', async ( ) => {
let state = document.visibilityState
if (state == 'hidden') { // 用户离开了
console.log("用户离开了")
await this.getDuration()
console.log("用户离开了1")
await this.getDuration(1);
console.log("用户离开了2")
}
});
},
destroyed() {
this.getDuration()
},
/*destroyed() {
this.getDuration(1)
},*/
methods:{
getDuration(){
getDuration(type){
const endTime = new Date();
const duration = (endTime - this.startTime) / 1000; // 计算时长(秒)
this.saveRecord(duration);
this.saveRecord(duration,type);
},
async saveRecord(duration){
await saveRecord({type:this.recordType,carInfoId:this.id,duration})
async saveRecord(duration,type){
await saveRecord({type:type,carInfoId:this.id,duration})
},
handle(){
this.getDuration(2)
Dialog.alert({
message:this.detailInfo.contactNumber ,
confirmButtonText:'拨打电话',
showCancelButton:true,
}).then(() => {
this.recordType=2
this.getDuration()
window.location.href = `tel:${this.detailInfo.contactNumber}`;
}).catch(() => {
// on cancel