Feat(页面):监听页面打开次数和页面停留时长接口对接
This commit is contained in:
+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