Feat(页面):监听页面打开次数和页面停留时长接口对接
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { clearAllInterval } from '@/utils/util'
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function () {
|
onLaunch: function () {
|
||||||
console.log('App Launch')
|
console.log('App Launch')
|
||||||
|
clearAllInterval()
|
||||||
},
|
},
|
||||||
onShow: function () {
|
onShow: function () {
|
||||||
console.log('App Show')
|
console.log('App Show')
|
||||||
|
|||||||
@@ -208,3 +208,7 @@ export function getShareImage() {
|
|||||||
export function getXiaoZhi() {
|
export function getXiaoZhi() {
|
||||||
return request.get("/appAdvertising", {}, {login: false})
|
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 = {
|
export const pageToWatchData = {
|
||||||
'home_index': {
|
'appIndex': []
|
||||||
count: 0,
|
|
||||||
timer: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-12
@@ -1,15 +1,18 @@
|
|||||||
import {
|
import {
|
||||||
pageToWatchShowCount,
|
pageToWatchShowCount,
|
||||||
pageToWatchShowTimer
|
pageToWatchShowTimer,
|
||||||
|
getCurrDateTime,
|
||||||
|
TimeDifference
|
||||||
} from '@/utils/util'
|
} from '@/utils/util'
|
||||||
export const pageListenMixins = {
|
export const pageListenMixins = {
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
pageTimer: null
|
pageViewDateTime: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.pageToWatchShowCount(this.pageKeyId, this.pageShowTimerFn())
|
this.pageViewDateTime = getCurrDateTime()
|
||||||
|
this.pageToWatchShowCount(this.pageKeyId)
|
||||||
},
|
},
|
||||||
onHide() {
|
onHide() {
|
||||||
this.clearPageTimerFn()
|
this.clearPageTimerFn()
|
||||||
@@ -17,17 +20,17 @@ export const pageListenMixins = {
|
|||||||
methods: {
|
methods: {
|
||||||
pageToWatchShowCount,
|
pageToWatchShowCount,
|
||||||
pageToWatchShowTimer,
|
pageToWatchShowTimer,
|
||||||
pageShowTimerFn() {
|
|
||||||
this.pageTimer = setInterval(() => {
|
|
||||||
console.log('----页面监听----%s', this.pageKeyId)
|
|
||||||
this.pageToWatchShowTimer(this.pageKeyId)
|
|
||||||
}, 1000)
|
|
||||||
},
|
|
||||||
clearPageTimerFn() {
|
clearPageTimerFn() {
|
||||||
if (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)
|
console.log('清除页面监听-----%s', this.pageKeyId)
|
||||||
clearInterval(this.pageTimer)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,7 +372,7 @@ export default {
|
|||||||
contentFestival: {},
|
contentFestival: {},
|
||||||
countyFamous: {},
|
countyFamous: {},
|
||||||
seasonalFood: {},
|
seasonalFood: {},
|
||||||
pageKeyId: Object.freeze('home_index'),
|
pageKeyId: Object.freeze('appIndex'),
|
||||||
scrollTop: 0
|
scrollTop: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export default {
|
|||||||
mapLocations: [],
|
mapLocations: [],
|
||||||
goods: [],
|
goods: [],
|
||||||
directionClass: ['', 'up', 'right', 'down', 'left'],
|
directionClass: ['', 'up', 'right', 'down', 'left'],
|
||||||
pageKeyId: Object.freeze('land_index')
|
pageKeyId: Object.freeze('landmarkGoodsIndex')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|||||||
+9
-2
@@ -18,13 +18,18 @@ fly.interceptors.response.use(
|
|||||||
console.log('————————')
|
console.log('————————')
|
||||||
handleLoginFailure();
|
handleLoginFailure();
|
||||||
return Promise.reject({msg: "未登录", toLogin: true});
|
return Promise.reject({msg: "未登录", toLogin: true});
|
||||||
}
|
} else if (error.status == 401) {
|
||||||
if (error.status == 401) {
|
|
||||||
console.log('————————')
|
console.log('————————')
|
||||||
console.log('登录失效 401', error)
|
console.log('登录失效 401', error)
|
||||||
console.log('————————')
|
console.log('————————')
|
||||||
handleLoginFailure();
|
handleLoginFailure();
|
||||||
return Promise.reject({msg: "未登录", toLogin: true});
|
return Promise.reject({msg: "未登录", toLogin: true});
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: '服务开小差了,请稍后再试',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
@@ -61,6 +66,7 @@ function baseRequest(options) {
|
|||||||
} else if (data.status === 200) {
|
} else if (data.status === 200) {
|
||||||
return Promise.resolve(data, res);
|
return Promise.resolve(data, res);
|
||||||
} else {
|
} else {
|
||||||
|
if (url.indexOf('api/systemStats/push') < 0) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: res.data.msg,
|
title: res.data.msg,
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
@@ -68,6 +74,7 @@ function baseRequest(options) {
|
|||||||
success() {
|
success() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return Promise.reject({msg: res.data.msg, res, data});
|
return Promise.reject({msg: res.data.msg, res, data});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+91
-9
@@ -1,4 +1,5 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
|
import { pushSystemStatic } from '@/api/public'
|
||||||
|
|
||||||
// 日期格式化
|
// 日期格式化
|
||||||
export function formatterDate(date, flag = '-', mode = 'date') {
|
export function formatterDate(date, flag = '-', mode = 'date') {
|
||||||
@@ -34,14 +35,11 @@ export function formatContent(html) {
|
|||||||
* @returns {null}
|
* @returns {null}
|
||||||
*/
|
*/
|
||||||
export function pageToWatchShowCount(key, cb = '') {
|
export function pageToWatchShowCount(key, cb = '') {
|
||||||
if (Vue.prototype.$pageToWatchData[key]) {
|
console.log(Vue.prototype.$pageToWatchData)
|
||||||
Vue.prototype.$pageToWatchData[key].count++
|
if (!Vue.prototype.$pageToWatchData[key]) {
|
||||||
} else {
|
Vue.prototype.$pageToWatchData[key] = []
|
||||||
Vue.prototype.$pageToWatchData[key] = {
|
|
||||||
count: 1,
|
|
||||||
timer: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
console.log('页面监听-----%s', key)
|
||||||
cb && cb()
|
cb && cb()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +50,92 @@ export function pageToWatchShowCount(key, cb = '') {
|
|||||||
* @param key-页面唯一标识
|
* @param key-页面唯一标识
|
||||||
* @returns {null}
|
* @returns {null}
|
||||||
*/
|
*/
|
||||||
export function pageToWatchShowTimer(key) {
|
export function pageToWatchShowTimer(key, data) {
|
||||||
if (Vue.prototype.$pageToWatchData[key]) {
|
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