diff --git a/App.vue b/App.vue index 2c65b48..2641613 100644 --- a/App.vue +++ b/App.vue @@ -8,6 +8,7 @@ // import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'; import { USERKEY, COMMONKEY } from "@/store/actionKey" import { checkUpdate } from "@/common/appUpdate" + import { setSessionSystemInfo, getSessionSystemInfo } from "@/session" import { onPushMessage } from "@/common/messageNotice" export default { @@ -49,9 +50,11 @@ }, onShow: function() { console.log('HHH Show') + this.updateActiveTime() this.appCheckUpdate() }, onHide: function() { + this.updateActiveTime({ directUpdate: true }) console.log('HHH Hide') }, globalData: { @@ -68,6 +71,19 @@ // } checkUpdate() // #endif + }, + async updateActiveTime(opt = {}){ + let { directUpdate } = opt + let { lastActiveTime } = getSessionSystemInfo() + let curTime = new Date().valueOf() + let diff = (curTime - lastActiveTime) + // 活跃时间间隔超过一个小时 需要重新登录 + if(diff > 1000 * 60 * 60 && !directUpdate) { + await this.$store.dispatch(USERKEY.LOGOUT) + this.goto(`login/login`, 2) + } else { + setSessionSystemInfo({ lastActiveTime: curTime }) + } } } } diff --git a/session/index.js b/session/index.js index 7ab8a1d..90fde71 100644 --- a/session/index.js +++ b/session/index.js @@ -38,6 +38,7 @@ export const getSessionLoginInfo = ()=> { export const setSessionSystemInfo = (val = {})=> { // { // hongWaiSwitch: false, // 红外扫描 + // lastActiveTime: 时间戳, // 上次活跃时间戳 // } uni.setStorageSync(SYSTEM_INFO_KEY, val) }