202404 入场需要查看免责声明
This commit is contained in:
@@ -26,7 +26,36 @@ const getCurrentPageUrl = () => {
|
||||
return url;
|
||||
}
|
||||
|
||||
const setTimeOutStorage = (key,value,timeout) => {
|
||||
let timestamp = Date.parse(new Date());
|
||||
wx.setStorageSync(key,
|
||||
{
|
||||
'value': value,
|
||||
'timeout': timestamp + timeout
|
||||
})
|
||||
}
|
||||
|
||||
const getTimeoutStorage = (key) => {
|
||||
// 当前时间
|
||||
let timestamp = Date.parse(new Date());
|
||||
// 缓存中的过期时间
|
||||
let data = wx.getStorageSync(key);
|
||||
let data_expiration = data.timeout;
|
||||
let value = data.value;
|
||||
// 如果缓存中没有data_expiration,说明也没有token,还未登录
|
||||
if (data_expiration) {
|
||||
// 如果超时了,清除缓存,重新登录
|
||||
if (timestamp > data_expiration) {
|
||||
wx.removeStorageSync(key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatTime: formatTime,
|
||||
getCurrentPageUrl: getCurrentPageUrl
|
||||
getCurrentPageUrl: getCurrentPageUrl,
|
||||
setTimeOutStorage: setTimeOutStorage,
|
||||
getTimeoutStorage: getTimeoutStorage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user