Commit 00ac6488 authored by Damon's avatar Damon

降低检查token有效期频率

parent ce49bcff
...@@ -150,8 +150,13 @@ export default { ...@@ -150,8 +150,13 @@ export default {
}, },
onShow: function () { onShow: function () {
const loginTime = cache.getCache('loginTime')
const validityTime = 3600000 * 24 * 7 // 7天检查一次token是否过期
if (util.getToken()) { if (util.getToken()) {
this.loginCheck() if (Date.now() - loginTime > validityTime) { // 超过有效期,检查token是否过期
this.loginCheck()
}
} else { } else {
this.autoLogin() this.autoLogin()
} }
...@@ -391,7 +396,8 @@ export default { ...@@ -391,7 +396,8 @@ export default {
// 如果已经登录则直接获取相关信息 // 如果已经登录则直接获取相关信息
util.setOpenid(userInfo.wxopenid) util.setOpenid(userInfo.wxopenid)
util.setToken(userInfo.token) util.setToken(userInfo.token)
uni.setStorageSync('user-info', userInfo); uni.setStorageSync('user-info', userInfo);
uni.setStorageSync('loginTime', new Date())
} else { } else {
util.setToken('') util.setToken('')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment