From 07b5dcb4905a15d0b39a51219d51c57fbd5ca4d1 Mon Sep 17 00:00:00 2001 From: hcong <1050828145@qq.com> Date: 星期四, 28 十一月 2024 13:35:04 +0800 Subject: [PATCH] 1. 新增登录页面 2. 新增登录接口 3. 新增stores/userToken.js 保存登录状态登录和退出登录 和 stores/activeCheck.js 保存登录超时和延时函数 4. components/core/Header完善退出登录点击事件 5. 新增cookie工具类 6. 新增登录工具类 --- src/router/index.js | 41 +++++++++++++++++++++++++++++++++-------- 1 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 6a36171..4b29d64 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,7 +2,9 @@ import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router' import pinia from '../stores/index' import { useLoadingStore } from '../stores/loadingStore' - +import { useActiveCheck } from '@/stores/activeCheck'; +import { useUserStore } from '@/stores/userToken'; +import loginUtil from '../utils/loginUtil'; const routes = [ // { // //鏁存敼瀹℃牳 @@ -208,19 +210,42 @@ name: 'docTest', path: '/common/docTest', component: () => import('@/views/DocTest.vue') + }, + { + //鐧婚檰 + name: 'loginView', + path: '/common/loginView', + component: () => import('@/views/LoginView.vue') } -] +]; const router = createRouter({ // history: createWebHistory(import.meta.env.BASE_URL) history: createWebHashHistory(), routes: routes -}) +}); -const loadingStore = useLoadingStore(pinia) +const loadingStore = useLoadingStore(pinia); +const activeCheck = useActiveCheck(pinia); +const userStore = useUserStore(pinia); // eslint-disable-next-line no-unused-vars router.afterEach((to, from) => { - loadingStore.clearLoading() -}) - -export { router, routes } + loadingStore.clearLoading(); +}); +function loginJudge() { + // 濡傛灉鏄湭鐧诲綍 灏濊瘯浠巆ookie鐧诲綍 + if (!userStore.isLoggedIn()) { + loginUtil.loginFromCookie(); + } + // 濡傛灉鐧诲綍瓒呮椂 璺宠浆鍒扮櫥褰曢〉闈� + if (!activeCheck.isActive()) { + router.push('/common/loginView'); + } +} +router.beforeEach((to, from) => { + // 娣诲姞鐧诲綍楠岃瘉 + if (to.fullPath !== '/common/loginView') { + loginJudge(); + } +}); +export { router, routes }; -- Gitblit v1.9.3