From 1b735913668da77590db631c1d04c56ef414745d Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Wed, 17 Jan 2024 15:47:21 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=99=BB=E5=BD=95=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/startup.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/utils/startup.js b/src/utils/startup.js index 8022861ba..6efe9e084 100644 --- a/src/utils/startup.js +++ b/src/utils/startup.js @@ -8,6 +8,8 @@ import orgUtil from '@/utils/org' import orgs from '@/api/orgs' import { getPropView, isViewHasOrgs } from '@/utils/jms' import request from '@/utils/request' +import i18n from '@/i18n/i18n' +import { MessageBox } from 'element-ui' const whiteList = ['/login', process.env.VUE_APP_LOGIN_PATH] // no redirect whitelist @@ -39,12 +41,30 @@ async function checkLogin({ to, from, next }) { return reject('No session mark found in cookie') } else if (sessionExpire === 'close') { let startTime = new Date().getTime() + this.newLoginHasOpen = false const intervalId = setInterval(() => { const endTime = new Date().getTime() const delta = (endTime - startTime) startTime = endTime Vue.$log.debug('Set session expire: ', delta) - if (!isRenewalExpired(120)) { + const currentTimeStamp = Math.floor(endTime / 1000) + const sessionExpireTimestamp = VueCookie.get('jms_session_expire_timestamp') + if (currentTimeStamp >= parseInt(sessionExpireTimestamp, 10)) { + if (!this.newLoginHasOpen) { + this.newLoginHasOpen = true + MessageBox.confirm( + i18n.t('auth.LoginRequiredMsg'), + i18n.t('common.Info'), + { + confirmButtonText: i18n.t('auth.ReLogin'), + cancelButtonText: i18n.t('common.Cancel'), + type: 'warning' + }).finally(() => { + window.location = '/core/auth/logout/' + clearInterval(intervalId) + }) + } + } else if (!isRenewalExpired(120)) { VueCookie.set('jms_session_expire', 'close', { expires: '2m' }) } else { clearInterval(intervalId)