From be971b7112884aaa143c1522d18d03e4587e5244 Mon Sep 17 00:00:00 2001 From: a0049873 <79py69t9wb@privaterelay.appleid.com> Date: Mon, 10 Oct 2022 16:52:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9token=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/router/index.js | 22 ---------------------- front/src/utils/accessToken.js | 7 ++++--- front/src/vab/plugins/permissions.js | 4 ++-- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/front/src/router/index.js b/front/src/router/index.js index 536d6b37..47c429c7 100644 --- a/front/src/router/index.js +++ b/front/src/router/index.js @@ -1,7 +1,5 @@ import { createRouter, createWebHashHistory } from 'vue-router' import Layout from '@/layout' -import { message } from 'ant-design-vue' -import Cookies from 'js-cookie' export const constantRoutes = [ { @@ -569,24 +567,4 @@ const router = createRouter({ routes: constantRoutes, }) -router.beforeEach((to, from, next) => { - let token = Cookies.get('ucsToken') - const tokenStartTime = window.localStorage.getItem('tokenStartTime') - // 定义失效时间 - const timeOver = 2 * 60 * 60 * 1000 - let date = new Date().getTime() - if (date - tokenStartTime > timeOver && token) { - message.warning('登录失效,请重新登录!') - token = null - } - console.log('判断token失效', token, date - tokenStartTime > timeOver) - if (!token) { - if (to.path == '/login') return next() - return next('/login') - } else if (to.path == '/login') { - return next('/home') - } - next() -}) - export default router diff --git a/front/src/utils/accessToken.js b/front/src/utils/accessToken.js index 343f3587..e17ac6ee 100644 --- a/front/src/utils/accessToken.js +++ b/front/src/utils/accessToken.js @@ -1,8 +1,8 @@ /* * @Author: hisense.wuhongjian * @Date: 2022-03-29 17:48:03 - * @LastEditors: hisense.wuhongjian - * @LastEditTime: 2022-04-25 17:47:09 + * @LastEditors: Light + * @LastEditTime: 2022-10-10 16:52:10 * @Description: 告诉大家这是什么 */ import { storage, tokenTableName } from '@/config' @@ -42,7 +42,8 @@ export function setAccessToken(accessToken) { } else if ('sessionStorage' === storage) { return sessionStorage.setItem(tokenTableName, accessToken) } else if ('cookie' === storage) { - return cookie.set(tokenTableName, accessToken) + let expires = new Date(new Date() * 1 + 2 * 60 * 60 * 1000) + return cookie.set(tokenTableName, accessToken, { expires: expires }) // return cookie.set(tokenTableName, '213124123412341234') } else { return localStorage.setItem(tokenTableName, accessToken) diff --git a/front/src/vab/plugins/permissions.js b/front/src/vab/plugins/permissions.js index e7535f15..1cd6fbd4 100644 --- a/front/src/vab/plugins/permissions.js +++ b/front/src/vab/plugins/permissions.js @@ -1,8 +1,8 @@ /* * @Author: hisense.wuhongjian * @Date: 2022-04-01 17:23:11 - * @LastEditors: hisense.wuhongjian - * @LastEditTime: 2022-07-18 18:45:20 + * @LastEditors: Light + * @LastEditTime: 2022-10-10 16:43:58 * @Description: 告诉大家这是什么 */ /** From 8f6ef3d8f9b491f990e132a914a8728ab0482a1d Mon Sep 17 00:00:00 2001 From: a0049873 <79py69t9wb@privaterelay.appleid.com> Date: Mon, 10 Oct 2022 16:57:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?token=E6=94=B9=E6=88=9012=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/utils/accessToken.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/front/src/utils/accessToken.js b/front/src/utils/accessToken.js index e17ac6ee..b5df58f4 100644 --- a/front/src/utils/accessToken.js +++ b/front/src/utils/accessToken.js @@ -2,7 +2,7 @@ * @Author: hisense.wuhongjian * @Date: 2022-03-29 17:48:03 * @LastEditors: Light - * @LastEditTime: 2022-10-10 16:52:10 + * @LastEditTime: 2022-10-10 16:56:17 * @Description: 告诉大家这是什么 */ import { storage, tokenTableName } from '@/config' @@ -42,7 +42,7 @@ export function setAccessToken(accessToken) { } else if ('sessionStorage' === storage) { return sessionStorage.setItem(tokenTableName, accessToken) } else if ('cookie' === storage) { - let expires = new Date(new Date() * 1 + 2 * 60 * 60 * 1000) + let expires = new Date(new Date() * 1 + 12 * 60 * 60 * 1000) return cookie.set(tokenTableName, accessToken, { expires: expires }) // return cookie.set(tokenTableName, '213124123412341234') } else {