vue记录使用日志 页面停留时间
import API from '@/modules/system/api/api_userTime'
const router = new Router({
mode: 'history',
base: process.env.BASE_URL,
scrollBehavior: () => ({ y: 0 }),
routes: constantRouterMap
})
let startTime = Date.now()
let currentTime
let standingTime = 0
let pageName = []
router.beforeEach((to, from, next) => {
if (to) {
pageName=[]
currentTime = Date.now()
standingTime = parseInt((currentTime - startTime) / 1000)
from.matched.forEach(routeItem => {
pageName.push(routeItem.meta.title)
})
if(pageName.length > 0){
const params = {
pageName: pageName.join("-"),
gmtCreate: '',
gmtLeave: '',
type: 'exit',
}
API.add(params).then(function(result) {
console.log(result)
}).catch(function(result) {
})
}
startTime = Date.now()
pageName = []
}
if(from){
to.matched.forEach(routeItem => {
pageName.push(routeItem.meta.title)
})
if(pageName.length > 0){
const param = {
pageName: pageName.join("-"),
gmtCreate: '',
gmtLeave: '',
type: 'enter'
}
console.log(param);
API.add(param).then(function(result) {
console.log(result)
}).catch(function(result) {
})
}
}
next()
})
export default router
|