From c95d9ac76e2709cf6e7b82eaacfde40b3e89fada Mon Sep 17 00:00:00 2001
From: a0049873 <79py69t9wb@privaterelay.appleid.com>
Date: Mon, 10 Oct 2022 10:35:29 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9token=E5=A4=B1=E6=95=88=20?=
=?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=99=BD=E5=B1=8F=E9=97=AE=E9=A2=98=EF=BC=8C?=
=?UTF-8?q?=20=E7=9B=AE=E5=89=8D=E8=AE=BE=E7=BD=AE=E7=9A=84=E6=9C=89?=
=?UTF-8?q?=E6=95=88=E6=97=B6=E9=95=BF=E4=B8=BA2=E5=B0=8F=E6=97=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
front/src/router/index.js | 22 ++
front/src/views/login/index.vue | 366 +++++++++++++++++---------------
2 files changed, 213 insertions(+), 175 deletions(-)
diff --git a/front/src/router/index.js b/front/src/router/index.js
index 47c429c7..9c0f4ca9 100644
--- a/front/src/router/index.js
+++ b/front/src/router/index.js
@@ -1,5 +1,7 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/layout'
+import { message } from 'ant-design-vue'
+import Cookies from 'js-cookie'
export const constantRoutes = [
{
@@ -567,4 +569,24 @@ 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 = null
+ }
+ console.log('判断token失效', token, date - tokenStartTime > timeOver)
+ if (!token) {
+ if (to.path == '/login') return next()
+ message.warning('登录失效,请重新登录!')
+ return next('/login')
+ } else if (to.path == '/login') {
+ return next('/home')
+ }
+ next()
+})
+
export default router
diff --git a/front/src/views/login/index.vue b/front/src/views/login/index.vue
index cd9cc7f8..c684ab11 100644
--- a/front/src/views/login/index.vue
+++ b/front/src/views/login/index.vue
@@ -15,7 +15,11 @@
-
+
@@ -23,8 +27,15 @@
-
+
登录
@@ -36,191 +47,196 @@