|
|
|
@ -5,7 +5,16 @@ App({ |
|
|
|
globalData: { |
|
|
|
userInfo: null, |
|
|
|
currentTab: 'index', |
|
|
|
sessionStartTime: null |
|
|
|
sessionStartTime: null, |
|
|
|
// 缓存相关
|
|
|
|
cachedData: { |
|
|
|
userInfo: null, |
|
|
|
personnelInfo: null |
|
|
|
}, |
|
|
|
cacheExpireTime: { |
|
|
|
userInfo: 0, // 时间戳,0表示无缓存
|
|
|
|
personnelInfo: 0 // 时间戳,0表示无缓存
|
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 事件总线,用于页面间通信
|
|
|
|
@ -36,6 +45,49 @@ App({ |
|
|
|
this.globalData.currentTab = tabName; |
|
|
|
}, |
|
|
|
|
|
|
|
// 缓存管理方法
|
|
|
|
setCache(key, data, expireTime = 3600000) { // 默认缓存1小时
|
|
|
|
this.globalData.cachedData[key] = data; |
|
|
|
this.globalData.cacheExpireTime[key] = Date.now() + expireTime; |
|
|
|
}, |
|
|
|
|
|
|
|
getCache(key) { |
|
|
|
const now = Date.now(); |
|
|
|
if (this.globalData.cacheExpireTime[key] > now) { |
|
|
|
return this.globalData.cachedData[key]; |
|
|
|
} |
|
|
|
// 缓存过期,清除缓存
|
|
|
|
this.globalData.cachedData[key] = null; |
|
|
|
this.globalData.cacheExpireTime[key] = 0; |
|
|
|
return null; |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取业务员信息(带缓存)
|
|
|
|
getPersonnelInfo(phoneNumber) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
// 检查缓存
|
|
|
|
const cachedData = this.getCache('personnelInfo'); |
|
|
|
if (cachedData) { |
|
|
|
console.log('使用缓存的业务员信息'); |
|
|
|
resolve(cachedData); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 从服务器获取
|
|
|
|
api.request('/api/personnel/get', 'POST', { phone: phoneNumber }) |
|
|
|
.then(res => { |
|
|
|
console.log('从服务器获取业务员信息成功:', res); |
|
|
|
// 设置缓存,缓存1小时
|
|
|
|
this.setCache('personnelInfo', res, 3600000); |
|
|
|
resolve(res); |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.error('获取业务员信息失败:', err); |
|
|
|
reject(err); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 记录用户踪迹
|
|
|
|
recordUserTrace(action, additionalData = {}) { |
|
|
|
const traceData = { |
|
|
|
|