Commit 0f5a5a93 by 李伟康

feat(utils): 优化 Track 类以获取页面路径

- 在 Track 类中添加获取当前页面和前一页的逻辑
- 更新 prePagePath 和 pagePath 的赋值,使其更准确地反映页面路径
- 优化了页面路径的获取方式,提高了代码的健壮性
1 parent 105bfbe6
......@@ -15,14 +15,18 @@ class Track {
userType
} = uni.$storage.get('userInfo') || {},
trackList = uni.getStorageSync('TRACK_LIST') || []
let pages = getCurrentPages(),
currentPage = pages[pages.length - 1],
prePage = {}
if (pages.length > 1) prePage = pages[pages.length - 2]
let item = {
userType,
loginAccount,
phoneNumber,
uuid,
scene,
prePagePath: '/',
pagePath:data.pagePath|| '/',
prePagePath: data.prePagePath || prePage.route || '/',
pagePath: data.pagePath || currentPage.route || '/',
eventTime: dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss'),
systemSource: 3,
eventType: data.eventType || 0
......@@ -48,7 +52,7 @@ class Track {
const recordList = uni.getStorageSync('TRACK_LIST') || []
if (recordList.length) {
const res = await uni.$api.commonApi.recordInsert({ recordList })
if (res)
if (res)
uni.setStorageSync('TRACK_LIST', [])
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!