jiaqingjiayi-xiaochengxu/甲情_甲意/miniprogram/app.js
2024-12-17 19:46:10 +08:00

30 lines
901 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

App({
onLaunch() {
my.getStorage({
key: 'userInfo',
success: (res) => {
const userInfo = res.data;
const currentTimestamp = new Date().getTime();
const lastLoginTimestamp = userInfo.timestamp; // 获取上次登录时间戳
// 计算时间差(单位:毫秒)
const timeDiff = currentTimestamp - lastLoginTimestamp;
const oneDay = 86400* 1000; // 24小时的毫秒数
// 如果时间差大于24小时则清除缓存
if (timeDiff > oneDay) {
console.log('超过24小时清除缓存');
my.removeStorage({
key: 'userInfo',
success: function () {
console.log('用户信息已删除');
},
fail: function (err) {
console.error('删除失败:', err);
}
});
}
},
});
},
})