优化网页访问量接口调用时机

This commit is contained in:
hejin 2025-10-15 21:23:19 +08:00
parent 3d3bd4ae35
commit 38dfb0c8c2
2 changed files with 12 additions and 12 deletions

View File

@ -1,21 +1,10 @@
export default async function ({
$axios,
store,
req
}) {
let userAgent = process.server ? req.headers['user-agent'] : navigator.userAgent
let url = process.server ? req.headers['referer'] : window.location.href
const isMobile = (userAgent) => {
return /Mobile|Android|iPhone|iPad|iPod|Opera Mini|IEMobile|BlackBerry|webOS/i.test(userAgent);
}
store.commit('SET_DEVICE', isMobile(userAgent))
let data = {
url,
equipment: store.state.device,
}
if (url && url !== '') {
console.log("url", url)
$axios.post('/web/pageSave',data)
}
}

View File

@ -1,6 +1,17 @@
export default ({ app,$cookies,$config, store }) => {
export default ({ app,$cookies,$config, store, $axios }) => {
app.router.beforeEach((to, from, next) => {
app.i18n.locale = store.state.locale
next()
})
app.router.afterEach((to, from) => {
if (process.client) {
let data = {
url: window.location.href,
equipment: store.state.device,
}
if (data.url && data.url !== '') {
$axios.post('/web/pageSave',data)
}
}
})
}