From cf401c4c2c20aebb991d7f5ad0820a7eb87c1d66 Mon Sep 17 00:00:00 2001 From: hyx Date: Thu, 19 May 2022 18:26:51 +0800 Subject: [PATCH] =?UTF-8?q?CN-484=20=E4=BA=A4=E4=BA=92=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=9A=E7=99=BB=E5=BD=95=E6=8B=A6=E6=88=AA=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E5=9C=A8=E7=99=BB=E5=BD=95=E6=88=90=E5=8A=9F=E5=90=8E=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=8E=9Furl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Login.vue | 2 +- src/components/layout/Header.vue | 1 + src/permission.js | 29 +++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Login.vue b/src/Login.vue index 8455effb..19619264 100644 --- a/src/Login.vue +++ b/src/Login.vue @@ -77,7 +77,7 @@ export default { if (!this.$_.isEmpty(res.data.theme)) { localStorage.setItem(storageKey.theme, res.data.theme) } - res.loginSuccessPath = this.loginSuccessPath ? this.loginSuccessPath : localStorage.getItem(storageKey.tokenExpireCurrentPath) + res.loginSuccessPath = this.loginSuccessPath this.loginSuccess(res) localStorage.setItem(storageKey.username, this.username) } else if (res.code === 518005) { diff --git a/src/components/layout/Header.vue b/src/components/layout/Header.vue index 88cf7fcc..cdb27182 100644 --- a/src/components/layout/Header.vue +++ b/src/components/layout/Header.vue @@ -181,6 +181,7 @@ export default { this.showChangePin = true }, logout () { + sessionStorage.removeItem(storageKey.tokenExpireCurrentPath) localStorage.removeItem(storageKey.token) get(api.logout) }, diff --git a/src/permission.js b/src/permission.js index b728ae09..d49ce0f7 100644 --- a/src/permission.js +++ b/src/permission.js @@ -12,7 +12,7 @@ const permissionWhiteList = [...loginWhiteList, '/entityDetail'] // 权限白名 router.beforeEach(async (to, from, next) => { if (to.path.indexOf('/login') == -1) { - localStorage.setItem(storageKey.tokenExpireCurrentPath, to.fullPath) + sessionStorage.setItem(storageKey.tokenExpireCurrentPath, to.fullPath) } // 加载iso-3166-2资源 loadGeoData() @@ -46,7 +46,16 @@ router.beforeEach(async (to, from, next) => { } } else { if (loginWhiteList.indexOf(to.path) !== -1) { - next() + const tokenExpireCurrentPath = sessionStorage.getItem(storageKey.tokenExpireCurrentPath) + if (to.path === '/login' && tokenExpireCurrentPath) { + if (hasParam(to.fullPath, 'redirect')) { + next() + } else { + next({ path: '/login', query: { redirect: tokenExpireCurrentPath } }) + } + } else { + next() + } } else { next({ path: '/login', query: { redirect: to.fullPath } }) } @@ -69,6 +78,22 @@ export function hasMenu (menuList, route) { }) } +export function hasParam (url, param) { + let hasParam = false + let tempArr = url.split('?') + const query = {} + if (tempArr[1]) { + tempArr = tempArr[1].split('&') + tempArr.forEach(t => { + const kv = t.split('=') + if (kv[0] === param) { + hasParam = true + } + }) + } + return hasParam +} + export function hasButton (buttonList, code) { return buttonList.some(button => button === code) }