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 @@