From 79b9c73e0717c244391ab1e15c6f6da9975f2610 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期二, 12 十一月 2024 15:58:30 +0800 Subject: [PATCH] 打包bug --- src/permission.ts | 65 +++++++++++++++++++++----------- 1 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/permission.ts b/src/permission.ts index 4543d08..6c4934b 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -8,44 +8,51 @@ import useUserStore from '@/store/modules/user'; import useSettingsStore from '@/store/modules/settings'; import usePermissionStore from '@/store/modules/permission'; +import { ElMessage } from "element-plus"; +import { fa } from 'element-plus/es/locale'; NProgress.configure({ showSpinner: false }); const whiteList = ['/login', '/register', '/social-callback']; router.beforeEach(async (to, from, next) => { NProgress.start(); - if (getToken()) { + + if (judge(getToken())) { + console.log('鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁宸叉媺鍙栧畬user_info淇℃伅'); to.meta.title && useSettingsStore().setTitle(to.meta.title as string); + /* has token*/ if (to.path === '/login') { next({ path: '/' }); NProgress.done(); } else { - if (useUserStore().roles.length === 0) { - isRelogin.show = true; - // 鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁宸叉媺鍙栧畬user_info淇℃伅 - const [err] = await tos(useUserStore().getInfo()); - if (err) { - await useUserStore().logout(); - ElMessage.error(err); - next({ path: '/' }); - } else { - isRelogin.show = false; - const accessRoutes = await usePermissionStore().generateRoutes(); - // 鏍规嵁roles鏉冮檺鐢熸垚鍙闂殑璺敱琛� - accessRoutes.forEach((route) => { - if (!isHttp(route.path)) { - router.addRoute(route); // 鍔ㄦ�佹坊鍔犲彲璁块棶璺敱琛� - } - }); - next({ ...to, replace: true }); // hack鏂规硶 纭繚addRoutes宸插畬鎴� - } - } else { - next(); - } + // if (useUserStore().roles.length === 0) { + isRelogin.show = true; + // // 鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁宸叉媺鍙栧畬user_info淇℃伅 + + // const [err] = await tos(useUserStore().getInfo()); + // if (err) { + // await useUserStore().logout(); + // ElMessage.error(err); + // next({ path: '/' }); + // } else { + // isRelogin.show = false; + // const accessRoutes = await usePermissionStore().generateRoutes(); + // // 鏍规嵁roles鏉冮檺鐢熸垚鍙闂殑璺敱琛� + // accessRoutes.forEach((route) => { + // if (!isHttp(route.path)) { + // router.addRoute(route); // 鍔ㄦ�佹坊鍔犲彲璁块棶璺敱琛� + // } + // }); + // next({ ...to, replace: true }); // hack鏂规硶 纭繚addRoutes宸插畬鎴� + // } + // } else { + next(); + // } } } else { // 娌℃湁token + console.log('娌℃湁token'); if (whiteList.indexOf(to.path) !== -1) { // 鍦ㄥ厤鐧诲綍鐧藉悕鍗曪紝鐩存帴杩涘叆 next(); @@ -59,3 +66,15 @@ router.afterEach(() => { NProgress.done(); }); + +const judge = (token: string | null) => { + if (token) { + const data = JSON.parse(token); + if (data != null) { + if (data.expirse != null && new Date().getTime() - data.expirse < 60 * 60 * 1000) { + return true; + } + } + } + return false; +}; -- Gitblit v1.8.0