Feat(页面):监听页面打开次数和页面停留时长接口对接
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<script>
|
||||
import { clearAllInterval } from '@/utils/util'
|
||||
export default {
|
||||
onLaunch: function () {
|
||||
console.log('App Launch')
|
||||
clearAllInterval()
|
||||
},
|
||||
onShow: function () {
|
||||
console.log('App Show')
|
||||
|
||||
@@ -207,4 +207,8 @@ export function getShareImage() {
|
||||
|
||||
export function getXiaoZhi() {
|
||||
return request.get("/appAdvertising", {}, {login: false})
|
||||
}
|
||||
|
||||
export function pushSystemStatic(data) {
|
||||
return request.post("/systemStats/push", data, { login: false })
|
||||
}
|
||||
+1
-4
@@ -1,6 +1,3 @@
|
||||
export const pageToWatchData = {
|
||||
'home_index': {
|
||||
count: 0,
|
||||
timer: 0
|
||||
}
|
||||
'appIndex': []
|
||||
}
|
||||
|
||||
+15
-12
@@ -1,15 +1,18 @@
|
||||
import {
|
||||
pageToWatchShowCount,
|
||||
pageToWatchShowTimer
|
||||
pageToWatchShowTimer,
|
||||
getCurrDateTime,
|
||||
TimeDifference
|
||||
} from '@/utils/util'
|
||||
export const pageListenMixins = {
|
||||
data(){
|
||||
return {
|
||||
pageTimer: null
|
||||
pageViewDateTime: ''
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
this.pageToWatchShowCount(this.pageKeyId, this.pageShowTimerFn())
|
||||
this.pageViewDateTime = getCurrDateTime()
|
||||
this.pageToWatchShowCount(this.pageKeyId)
|
||||
},
|
||||
onHide() {
|
||||
this.clearPageTimerFn()
|
||||
@@ -17,17 +20,17 @@ export const pageListenMixins = {
|
||||
methods: {
|
||||
pageToWatchShowCount,
|
||||
pageToWatchShowTimer,
|
||||
pageShowTimerFn() {
|
||||
this.pageTimer = setInterval(() => {
|
||||
console.log('----页面监听----%s', this.pageKeyId)
|
||||
this.pageToWatchShowTimer(this.pageKeyId)
|
||||
}, 1000)
|
||||
},
|
||||
clearPageTimerFn() {
|
||||
if (this.pageTimer) {
|
||||
console.log('清除页面监听-----%s', this.pageKeyId)
|
||||
clearInterval(this.pageTimer)
|
||||
const visitTime = TimeDifference(this.pageViewDateTime, getCurrDateTime())
|
||||
if (visitTime > 0) {
|
||||
this.pageToWatchShowTimer(this.pageKeyId, {
|
||||
statsName: this.pageKeyId,
|
||||
statsTime: this.pageViewDateTime,
|
||||
visitTime
|
||||
})
|
||||
}
|
||||
this.pageViewDateTime = ''
|
||||
console.log('清除页面监听-----%s', this.pageKeyId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,7 +372,7 @@ export default {
|
||||
contentFestival: {},
|
||||
countyFamous: {},
|
||||
seasonalFood: {},
|
||||
pageKeyId: Object.freeze('home_index'),
|
||||
pageKeyId: Object.freeze('appIndex'),
|
||||
scrollTop: 0
|
||||
}
|
||||
},
|
||||
|
||||
@@ -93,7 +93,7 @@ export default {
|
||||
mapLocations: [],
|
||||
goods: [],
|
||||
directionClass: ['', 'up', 'right', 'down', 'left'],
|
||||
pageKeyId: Object.freeze('land_index')
|
||||
pageKeyId: Object.freeze('landmarkGoodsIndex')
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
+16
-9
@@ -18,13 +18,18 @@ fly.interceptors.response.use(
|
||||
console.log('————————')
|
||||
handleLoginFailure();
|
||||
return Promise.reject({msg: "未登录", toLogin: true});
|
||||
}
|
||||
if (error.status == 401) {
|
||||
} else if (error.status == 401) {
|
||||
console.log('————————')
|
||||
console.log('登录失效 401', error)
|
||||
console.log('————————')
|
||||
handleLoginFailure();
|
||||
return Promise.reject({msg: "未登录", toLogin: true});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '服务开小差了,请稍后再试',
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
})
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
@@ -61,13 +66,15 @@ function baseRequest(options) {
|
||||
} else if (data.status === 200) {
|
||||
return Promise.resolve(data, res);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
icon: 'none',
|
||||
duration: 3000,
|
||||
success() {
|
||||
}
|
||||
})
|
||||
if (url.indexOf('api/systemStats/push') < 0) {
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
icon: 'none',
|
||||
duration: 3000,
|
||||
success() {
|
||||
}
|
||||
})
|
||||
}
|
||||
return Promise.reject({msg: res.data.msg, res, data});
|
||||
}
|
||||
});
|
||||
|
||||
+91
-9
@@ -1,4 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
import { pushSystemStatic } from '@/api/public'
|
||||
|
||||
// 日期格式化
|
||||
export function formatterDate(date, flag = '-', mode = 'date') {
|
||||
@@ -34,14 +35,11 @@ export function formatContent(html) {
|
||||
* @returns {null}
|
||||
*/
|
||||
export function pageToWatchShowCount(key, cb = '') {
|
||||
if (Vue.prototype.$pageToWatchData[key]) {
|
||||
Vue.prototype.$pageToWatchData[key].count++
|
||||
} else {
|
||||
Vue.prototype.$pageToWatchData[key] = {
|
||||
count: 1,
|
||||
timer: 0
|
||||
}
|
||||
console.log(Vue.prototype.$pageToWatchData)
|
||||
if (!Vue.prototype.$pageToWatchData[key]) {
|
||||
Vue.prototype.$pageToWatchData[key] = []
|
||||
}
|
||||
console.log('页面监听-----%s', key)
|
||||
cb && cb()
|
||||
}
|
||||
|
||||
@@ -52,8 +50,92 @@ export function pageToWatchShowCount(key, cb = '') {
|
||||
* @param key-页面唯一标识
|
||||
* @returns {null}
|
||||
*/
|
||||
export function pageToWatchShowTimer(key) {
|
||||
export function pageToWatchShowTimer(key, data) {
|
||||
if (Vue.prototype.$pageToWatchData[key]) {
|
||||
Vue.prototype.$pageToWatchData[key].timer++
|
||||
Vue.prototype.$pageToWatchData[key].push(data)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* desc: 获取当前系统时间
|
||||
* auth: lifizer
|
||||
* date: 2024-05-16
|
||||
* @returns {String}
|
||||
*/
|
||||
export function getCurrDateTime() {
|
||||
const date = new Date()
|
||||
let str = ''
|
||||
str += date.getFullYear() + '-'
|
||||
str += (date.getMonth() + 1).toString().padStart(2, '0') + '-'
|
||||
str += (date.getDate()).toString().padStart(2, '0') + ' '
|
||||
str += (date.getHours()).toString().padStart(2, '0') + ':'
|
||||
str += (date.getMinutes()).toString().padStart(2, '0') + ':'
|
||||
str += (date.getSeconds()).toString().padStart(2, '0')
|
||||
return str
|
||||
}
|
||||
|
||||
/**
|
||||
* desc: 计算两个时间的相差的秒数
|
||||
* auth: lifizer
|
||||
* date: 2024-05-16
|
||||
* @param startValue-开始时间
|
||||
* @param endValue-结束时间
|
||||
* @returns {null}
|
||||
*/
|
||||
export function TimeDifference(startValue, endValue) {
|
||||
const startYear = parseInt(startValue.substring(0, 4))
|
||||
const startMonth = parseInt(startValue.substring(5, 7)) - 1
|
||||
const startDate = parseInt(startValue.substring(8, 10))
|
||||
const startHours = parseInt(startValue.substring(11, 13))
|
||||
const startMinutes = parseInt(startValue.substring(14, 16))
|
||||
const startSeconds = parseInt(startValue.substring(17, 19))
|
||||
const endYear = parseInt(endValue.substring(0, 4))
|
||||
const endMonth = parseInt(endValue.substring(5, 7)) - 1
|
||||
const endDate = parseInt(endValue.substring(8, 10))
|
||||
const endHours = parseInt(endValue.substring(11, 13))
|
||||
const endMinutes = parseInt(endValue.substring(14, 16))
|
||||
const endSeconds = parseInt(endValue.substring(17, 19))
|
||||
const startTime = (new Date(startYear, startMonth, startDate, startHours, startMinutes, startSeconds)).getTime()
|
||||
const endTime = (new Date(endYear, endMonth, endDate, endHours, endMinutes, endSeconds)).getTime()
|
||||
return (endTime - startTime) / 1000
|
||||
}
|
||||
|
||||
/**
|
||||
* 清楚所有的定时器
|
||||
* @returns {null}
|
||||
*/
|
||||
export function clearAllInterval() {
|
||||
const endTimerId = setInterval(function() {
|
||||
console.log('clear all timer...')
|
||||
}, 1000)
|
||||
for (let i = 1; i <= endTimerId; i++) {
|
||||
clearInterval(i)
|
||||
}
|
||||
pushSysByOneMinutesHandle()
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时推送埋点
|
||||
* @returns {null}
|
||||
*/
|
||||
function pushSysByOneMinutesHandle() {
|
||||
setInterval(() => {
|
||||
let statsData = []
|
||||
for (const key in Vue.prototype.$pageToWatchData) {
|
||||
if (Vue.prototype.$pageToWatchData[key]) {
|
||||
console.log(Vue.prototype.$pageToWatchData[key])
|
||||
statsData = statsData.concat(Vue.prototype.$pageToWatchData[key])
|
||||
}
|
||||
}
|
||||
console.log(statsData)
|
||||
const postData = {
|
||||
uid: '',
|
||||
deviceType: 'android',
|
||||
statsData
|
||||
}
|
||||
console.log('开始上报数据-------------------')
|
||||
pushSystemStatic(postData).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
}, 60 * 1000)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user