From 6ab4b1e0b68e4c347110e37018fa005603f53904 Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期二, 29 九月 2026 23:49:04 +0800
Subject: [PATCH] ai优化

---
 src/permission.ts |  152 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 110 insertions(+), 42 deletions(-)

diff --git a/src/permission.ts b/src/permission.ts
index 3dace6d..85c14e2 100644
--- a/src/permission.ts
+++ b/src/permission.ts
@@ -1,13 +1,18 @@
 import router from './router'
 import type { RouteRecordRaw } from 'vue-router'
 import { isRelogin } from '@/config/axios/service'
-import { getAccessToken } from '@/utils/auth'
+import { getAccessToken, removeToken } from '@/utils/auth'
+import { deleteUserCache } from '@/hooks/web/useCache'
 import { useTitle } from '@/hooks/web/useTitle'
 import { useNProgress } from '@/hooks/web/useNProgress'
 import { usePageLoading } from '@/hooks/web/usePageLoading'
 import { useDictStoreWithOut } from '@/store/modules/dict'
+import { useCheckTypeStoreWithOut } from '@/store/modules/checkType'
 import { useUserStoreWithOut } from '@/store/modules/user'
 import { usePermissionStoreWithOut } from '@/store/modules/permission'
+import { useRoomStoreWithOut } from "@/store/modules/room";
+// 闇�姹傦細30 鍒嗛挓鏃犳搷浣滄墠瑕佹眰閲嶆柊鐧诲綍锛堝墠绔┖闂叉娴嬶級
+import { setupIdleLogout } from '@/hooks/web/useIdleLogout'
 
 const { start, done } = useNProgress()
 
@@ -53,57 +58,104 @@
   '/auth-redirect',
   '/bind',
   '/register',
-  '/oauthLogin/gitee'
+  '/oauthLogin/gitee',
+  '/calling-screen-big',
+  '/calling-screen-room'
 ]
 
 // 璺敱鍔犺浇鍓�
 router.beforeEach(async (to, from, next) => {
+  console.info("router.beforeEach to: " + to.fullPath + " from: " + from.fullPath)
   start()
   loadStart()
-  if (getAccessToken()) {
-    if (to.path === '/login') {
-      next({ path: '/' })
-    } else {
-      // 鑾峰彇鎵�鏈夊瓧鍏�
-      const dictStore = useDictStoreWithOut()
-      const userStore = useUserStoreWithOut()
-      const permissionStore = usePermissionStoreWithOut()
-      if (!dictStore.getIsSetDict) {
-        await dictStore.setDictMap()
-      }
-      if (!userStore.getIsSetUser) {
-        isRelogin.show = true
-        await userStore.setUserInfoAction()
-        isRelogin.show = false
-        // 鍚庣杩囨护鑿滃崟
-        await permissionStore.generateRoutes()
-        permissionStore.getAddRouters.forEach((route) => {
-          router.addRoute(route as unknown as RouteRecordRaw) // 鍔ㄦ�佹坊鍔犲彲璁块棶璺敱琛�
-        })
 
-        // 鏂板銆愯瘖瀹ら�夋嫨銆戦�昏緫
-        if (userStore.getRoles.includes("doctor") && !userStore.getRoles.includes("super_admin") && !userStore.getIsSetRoom ) {
-          next({path: `/roomselect?redirect=${to.fullPath}`})
-        }
-        // <<<銆愯瘖瀹ら�夋嫨銆�<<<
-        else {
-          const redirectPath = from.query.redirect || to.path
-          // 淇璺宠浆鏃朵笉甯﹀弬鏁扮殑闂
-          const redirect = decodeURIComponent(redirectPath as string)
-          const {paramsObject: query} = parseURL(redirect)
-          const nextData = to.path === redirect ? {...to, replace: true} : {path: redirect, query}
-          next(nextData)
-        }
-      } else {
-        next()
+  if (whiteList.indexOf(to.path) !== -1) {
+    next()
+    return
+  }
+
+  if (!getAccessToken()) {
+    next(`/login?redirect=${to.fullPath}`) // 鍚﹀垯鍏ㄩ儴閲嶅畾鍚戝埌鐧诲綍椤�
+    return
+  }
+
+  // ==========================================================================
+  // 銆愪慨澶嶃�戜互涓嬫墍鏈� await 閮藉繀椤诲寘鍦� try/catch 鍐呫��
+  //
+  // 鑳屾櫙锛歭ocalStorage 閲屽彲鑳芥畫鐣�**宸插け鏁堢殑 token**锛堟湇鍔$閲嶅惎銆佷护鐗岃繃鏈熺瓑锛夈��
+  // 姝ゆ椂 getAccessToken() 浠嶆湁鍊� 鈫� 瀹堝崼涓嶄細璺崇櫥褰曢〉 鈫� 缁х画鐢ㄦ棫 token 璇锋眰鍚庣
+  // 鈫� 401 鈫� handleAuthorized() 杩斿洖 Promise.reject('鐧诲綍瓒呮椂,璇烽噸鏂扮櫥褰�!')銆�
+  // 鍘熷厛璇� reject 鏃犱汉鎹曡幏锛屼細涓�璺啋娉″埌 setupRouter()锛屽鑷达細
+  //     [Vue Router warn] uncaught error during route navigation
+  //     [Vue Router warn] Unexpected error when starting the router
+  //     main.ts:76 Uncaught (in promise) 鐧诲綍瓒呮椂,璇烽噸鏂扮櫥褰�!
+  // **璺敱瀹夎澶辫触锛屾暣涓〉闈㈣捣涓嶆潵**锛堢敤鎴峰繀椤绘墜鍔ㄩ噸鏂扮櫥褰曟墠鎭㈠锛夈��
+  //
+  // 鐜板湪缁熶竴鍏滃簳锛氭棤璁洪壌鏉冨け璐ヨ繕鏄叾浠栧紓甯革紝閮芥竻鎺夋湰鍦板け鏁堝嚟璇佸苟杞櫥褰曢〉锛�
+  // 淇濊瘉璺敱鍣ㄤ竴瀹氳兘瀹屾垚鍒濆鍖栥��
+  //
+  // 娉細鍘熷厛姝ゅ杩樻湁 `if (to.path === '/login') next({path:'/'})`锛�
+  // 鍥� '/login' 宸插湪 whiteList 涓彁鍓� return锛岃鍒嗘敮姘镐笉鍙揪锛屽凡绉婚櫎銆�
+  // ==========================================================================
+  try {
+    // 鑾峰彇鎵�鏈夊瓧鍏�
+    const dictStore = useDictStoreWithOut()
+    const userStore = useUserStoreWithOut()
+    const roomStore = useRoomStoreWithOut()
+    const checkTypeStore = useCheckTypeStoreWithOut()
+    const permissionStore = usePermissionStoreWithOut()
+    if (!dictStore.getIsSetDict) {
+      await dictStore.setDictMap()
+    }
+    if (!checkTypeStore.getIsSetCheckType) {
+      await checkTypeStore.setCheckTypeMap()
+    }
+
+    if (userStore.getIsSetUser) {
+
+      // <<<銆愯瘖瀹ら�夋嫨銆�<<<
+      if (to.path !== '/roomselect' &&
+          userStore.getRoles.includes("doctor") && !userStore.getRoles.includes("super_admin")
+          && !roomStore.getIsSetRoom) {
+        next({ path: `/roomselect?redirect=${to.fullPath}` })
+        return
       }
-    }
-  } else {
-    if (whiteList.indexOf(to.path) !== -1) {
+
       next()
-    } else {
-      next(`/login?redirect=${to.fullPath}`) // 鍚﹀垯鍏ㄩ儴閲嶅畾鍚戝埌鐧诲綍椤�
+      return
     }
+
+    isRelogin.show = true
+    await userStore.setUserInfoAction()
+    isRelogin.show = false
+
+    // 鍚庣杩囨护鑿滃崟
+    await permissionStore.generateRoutes()
+    permissionStore.getAddRouters.forEach((route) => {
+      router.addRoute(route as unknown as RouteRecordRaw) // 鍔ㄦ�佹坊鍔犲彲璁块棶璺敱琛�
+    })
+
+    // <<<銆愯瘖瀹ら�夋嫨銆�<<<
+    if (to.path !== '/roomselect' &&
+        userStore.getRoles.includes("doctor") && !userStore.getRoles.includes("super_admin")
+        && !roomStore.getIsSetRoom) {
+      next({ path: `/roomselect?redirect=${to.fullPath}` })
+      return
+    }
+
+    const redirectPath = from.query.redirect || to.path
+    // 淇璺宠浆鏃朵笉甯﹀弬鏁扮殑闂
+    const redirect = decodeURIComponent(redirectPath as string)
+    const { paramsObject: query } = parseURL(redirect)
+    const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect, query }
+    next(nextData)
+  } catch (e) {
+    // 鍏滃簳锛氭竻鐞嗘湰鍦板け鏁堝嚟璇侊紝鏀捐鍒扮櫥褰曢〉锛岀粷涓嶈寮傚父涓柇璺敱鍒濆鍖�
+    console.warn('[permission] 璺敱瀹堝崼鎵ц澶辫触锛屽凡娓呯悊鏈湴鍑瘉骞惰浆鐧诲綍椤碉細', e)
+    isRelogin.show = false
+    removeToken()
+    deleteUserCache()
+    next(`/login?redirect=${to.fullPath}`)
   }
 })
 
@@ -111,4 +163,20 @@
   useTitle(to?.meta?.title as string)
   done() // 缁撴潫Progress
   loadDone()
+
+  // ==========================================================================
+  // 闇�姹傦細**30 鍒嗛挓涓嶆搷浣�**鎵嶈姹傞噸鏂拌緭鍏ュ瘑鐮併��
+  //
+  // 鑳屾櫙锛氬悗绔� token 鏄浐瀹氭湁鏁堟湡锛坰ystem_oauth2_client.access_token_validity_seconds锛�
+  // 褰撳墠 default 瀹㈡埛绔� = 3600 绉掞級锛屼笌鐢ㄦ埛鏄惁鏈夋搷浣滄棤鍏� 鈥斺�� 鎸傜潃涓嶅姩涔熶細鍒扮偣琚涪銆�
+  // 杩欓噷鍦ㄥ墠绔ˉ涓�**鐪熸鐨勭┖闂叉娴�**锛�
+  //   路 鏈夐紶鏍�/閿洏/瑙︽懜/婊氬姩绛夋搷浣� 鈫� 璁℃椂閲嶇疆锛�
+  //   路 杩炵画 30 鍒嗛挓鏃犱换浣曟搷浣�   鈫� 涓诲姩娓呭嚟璇佸苟璺崇櫥褰曢〉銆�
+  // 浠〃鐩�/鍙彿灞忕瓑鐧藉悕鍗曢〉闈笉浼氳蛋鍒拌繖閲岋紝涓嶅彈褰卞搷銆�
+  //
+  // 鍙湪**宸茬櫥褰�**涓旈潪鐧诲綍椤垫椂鍚姩锛泂etupIdleLogout 鍐呴儴骞傜瓑锛岄噸澶嶈皟鐢ㄦ棤鍓綔鐢ㄣ��
+  // ==========================================================================
+  if (getAccessToken() && to.path !== '/login') {
+    setupIdleLogout()
+  }
 })

--
Gitblit v1.9.3