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 | 290 +++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 205 insertions(+), 85 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index ba6758f..4b29d64 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,131 +1,251 @@ -import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'; -import pinia from "../stores/index"; -import { useLoadingStore } from "../stores/loadingStore"; - - +// eslint-disable-next-line no-unused-vars +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 = [ - { - //闂瀹℃牳 - name: 'procheck', - path: '/procheck', - component: () => import('@/views/check/ProCheck.vue'), - }, - { - //鏁存敼瀹℃牳 - name: 'changecheck', - path: '/changecheck', - component: () => import('@/views/check/ChangeCheck.vue'), - }, - { - //鍙拌处瀹℃牳 - name: 'ledger', - path: '/ledger', - component: () => import('@/views/ledger/LedgerManage.vue'), - }, + // { + // //鏁存敼瀹℃牳 + // name: 'changecheck', + // path: '/changecheck', + // component: () => import('@/views/check/ChangeCheck.vue') + // }, + /**********************************椋炵窘鐩戠***********************************************/ { //闂鍔ㄦ�佽窡韪� name: 'profollow', - path: '/analysis/profollow', - component: () => import('@/views/analysis/ProFollow.vue'), + path: '/fysp/data-product/profollow', + component: () => import('@/views/fysp/data-product/ProdProFollow.vue') }, { //闂鏁存敼鍒嗘瀽 name: 'proanalysis', - path: '/analysis/proanalysis', - component: () => import('@/views/analysis/ProAnalysis.vue'), + path: '/fysp/data-product/proanalysis', + component: () => import('@/views/fysp/data-product/ProdProAnalysis.vue') }, { //瑙勮寖鎬ц瘎浼� name: 'standardjudge', - path: '/analysis/standardjudge', - component: () => import('@/views/analysis/StandardJudge.vue'), + path: '/fysp/data-product/standardjudge', + component: () => import('@/views/fysp/data-product/ProdStandardJudge.vue') }, { //鏃ユ姤绠$悊 name: 'dailyreport', - path: '/dailyreport', - component: () => import('@/views/dailyreport/DailyReport.vue'), + path: '/fysp/data-product/dailyreport', + component: () => import('@/views/fysp/data-product/ProdDailyReport.vue') }, { - //鍦烘櫙鎶ュ憡-宸ュ湴 - name: 'construction', - path: '/scenereport/construction', - component: () => import('@/views/scenereport/ConstructionReport.vue'), - }, - { - //鍦烘櫙鎶ュ憡-鐮佸ご - name: 'wharf', - path: '/scenereport/wharf', - component: () => import('@/views/scenereport/WharfReport.vue'), - }, - { - //鍦烘櫙鎶ュ憡-鎼呮媽绔� - name: 'mixing', - path: '/scenereport/mixing', - component: () => import('@/views/scenereport/MixingReport.vue'), - }, - { - //鍦烘櫙鎶ュ憡-鍫嗗満 - name: 'storage', - path: '/scenereport/storage', - component: () => import('@/views/scenereport/StorageReport.vue'), - }, - { - //閫氱煡绠$悊 - name: 'notice', - path: '/notice', - component: () => import('@/views/notice/NoticeManage.vue'), - }, - - // 椋炵窘鐩戠 - { - //璐︽埛绠$悊 - name: 'fyspUser', - path: '/fysp/userInfo', - component: () => import('@/views/baseinfo/fysp/user/UserInfo.vue'), + //鍦烘櫙鎶ュ憡 + name: 'scenereport', + path: '/fysp/data-product/scenereport', + component: () => import('@/views/fysp/data-product/ProdSceneReport.vue') }, // { - // //鍦烘櫙绠$悊 - // name: 'fyspSceneManage', - // path: '/fysp/sceneManage/', - // component: () => import('@/views/user/fysp/SceneManage.vue'), - // children: [ - - // ] + // //鍦烘櫙鎶ュ憡-宸ュ湴 + // name: 'construction', + // path: '/scenereport/construction', + // component: () => import('@/views/fysp/scenereport/ConstructionReport.vue') // }, + // { + // //鍦烘櫙鎶ュ憡-鐮佸ご + // name: 'wharf', + // path: '/scenereport/wharf', + // component: () => import('@/views/fysp/scenereport/WharfReport.vue') + // }, + // { + // //鍦烘櫙鎶ュ憡-鎼呮媽绔� + // name: 'mixing', + // path: '/scenereport/mixing', + // component: () => import('@/views/fysp/scenereport/MixingReport.vue') + // }, + // { + // //鍦烘櫙鎶ュ憡-鍫嗗満 + // name: 'storage', + // path: '/scenereport/storage', + // component: () => import('@/views/fysp/scenereport/StorageReport.vue') + // }, + + { + //鐩戠浠诲姟 + name: 'taskmanage', + path: '/fysp/task/manage', + component: () => import('@/views/fysp/task/TaskManage.vue'), + meta: { keepAlive: true } + }, + { + //鐩戠浠诲姟鍦烘櫙缂栬緫 + name: 'monitorObjEdit', + path: '/fysp/task/edit', + component: () => import('@/views/fysp/task/MonitorObjEdit.vue') + }, + { + //鐩戠浠诲姟璁″垝缂栬緫 + name: 'monitorPlanEdit', + path: '/fysp/task/plan/edit', + component: () => import('@/views/fysp/task/MonitorPlanEdit.vue') + }, + { + //鐩戠浠诲姟璁″垝缂栬緫 + name: 'monitorTaskCreate', + path: '/fysp/task/create', + component: () => import('@/views/fysp/task/MonitorTaskCreate.vue') + }, + { + //闂瀹℃牳 + name: 'procheck', + path: '/fysp/procheck', + component: () => import('@/views/fysp/check/ProCheck.vue') + }, + // { + // //璐︽埛绠$悊 + // name: 'fyspUser', + // path: '/fysp/userInfo', + // component: () => import('@/views/baseinfo/fysp/user/UserInfo.vue') + // }, + { + //鐩戠闂 + name: 'fyspProblemType', + path: '/fysp/config/problemType', + component: () => import('@/views/fysp/config/ProblemType.vue') + }, + { + //璁惧鍖归厤 + name: 'fyspDeviceMatch', + path: '/fysp/config/deviceMatch', + component: () => import('@/views/fysp/config/DeviceMatch.vue') + }, + { + //璇勪及瑙勫垯绠$悊 + name: 'fyspEvalutationRule', + path: '/fysp/config/evalutationRule', + component: () => import('@/views/fysp/config/EvalutationRule.vue') + }, + { + //璇勪及鏁版嵁婧� + name: 'fyspEvalutationTask', + path: '/fysp/evaluation/evalutationTask', + component: () => import('@/views/fysp/evaluation/EvalutationTask.vue'), + meta: { keepAlive: false } + }, + { + //璇勪及绠$悊 + name: 'fyspEvalutationRecord', + path: '/fysp/evaluation/evalutationRecord', + component: () => import('@/views/fysp/evaluation/EvalutationRecord.vue'), + meta: { keepAlive: true } + }, + { + //璇勪及缁撴灉璇︽儏 + name: 'fyspEvalutationEdit', + path: '/fysp/evaluation/evalutationEdit/:subTaskId', + component: () => import('@/views/fysp/evaluation/EvalutationEdit.vue'), + }, { //鍦烘櫙淇℃伅 name: 'fyspSceneInfo', path: '/fysp/sceneInfo', - component: () => import('@/views/baseinfo/fysp/scene/SceneInfo.vue'), - meta: { keepAlive: true }, + component: () => import('@/views/fysp/scene/SceneInfo.vue'), + meta: { keepAlive: true } }, { //鍦烘櫙缂栬緫 name: 'fyspSceneEdit', path: '/fysp/sceneEdit/:sid', - component: () => import('@/views/baseinfo/fysp/scene/SceneEdit.vue'), - meta: { transition: 'slide-left' }, + component: () => import('@/views/fysp/scene/SceneEdit.vue'), + meta: { transition: 'slide-left' } + }, + { + //瀵瑰鏀寔 + name: 'fyspSupport', + path: '/fysp/support', + component: () => import('@/views/fysp/support/JingAnSupport.vue'), }, - // 椋炵窘鐜 + /**********************************椋炵窘鐜***********************************************/ + { + //鍙拌处瀹℃牳 + name: 'ledger', + path: '/fytz/ledger', + component: () => import('@/views/fytz/ledger/LedgerManage.vue') + }, + { + //閫氱煡绠$悊 + name: 'notice', + path: '/fytz/notice', + component: () => import('@/views/fytz/notice/NoticeManage.vue') + }, { //璐︽埛绠$悊 name: 'fytzUser', path: '/fytz/userInfo', - component: () => import('@/views/baseinfo/fytz/user/UserInfo.vue'), + component: () => import('@/views/fytz/user/UserInfo.vue'), + meta: { keepAlive: true } }, + { + //璐︽埛缂栬緫 + name: 'fytzUserEdit', + path: '/fytz/userEdit/:userId', + component: () => import('@/views/fytz/user/UserEdit.vue'), + meta: { transition: 'slide-left' } + }, + { + //鐜繚鐫e療妗堜緥 + name: 'enforceCase', + path: '/fytz/enforceCase', + component: () => import('@/views/fytz/enforce-case/EnforceCase.vue') + }, + + /**********************************閫氱敤妯″潡***********************************************/ + { + //璐︽埛鍖归厤 + name: 'userMatch', + path: '/common/userMatch', + component: () => import('@/views/common/UserMatch.vue') + }, + { + //鏂囨。鐢熸垚娴嬭瘯 + 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, + 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() -}) - + 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