From 09dc74e264b6262cbe41c9c8476e24705871d4a6 Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期日, 08 十一月 2026 23:31:17 +0800
Subject: [PATCH] yxh
---
src/permission.ts | 226 ++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 184 insertions(+), 42 deletions(-)
diff --git a/src/permission.ts b/src/permission.ts
index 6db7476..bca1eba 100644
--- a/src/permission.ts
+++ b/src/permission.ts
@@ -1,17 +1,96 @@
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()
const { loadStart, loadDone } = usePageLoading()
+
+/**
+ * 銆岄�夋嫨宸ヤ綅妯″紡銆嶇殑璺宠浆鍒ゅ畾锛�0/1/2/3锛夈��
+ *
+ * - 0 鎸夐渶瑕佸己鍒堕�夋嫨宸ヤ綅锛氭湭鍏ュ骇 鈫� 寮哄埗鍘婚�夊伐浣嶉〉
+ * - 1 鐧诲綍IP鍖归厤宸ヤ綅锛氬厛鎸夋湰鏈篒P鑷姩鍖归厤骞惰嚜鍔ㄥ叆搴э紱鍖归厤涓嶅埌 鈫� 鎸� 0锛堝幓閫夊伐浣嶉〉锛屽甫鍘熷洜锛�
+ * - 2 鐧诲綍鏃舵墜鍔ㄩ�夋嫨宸ヤ綅锛氬己鍒跺幓閫夊伐浣嶉〉锛屽苟鍦ㄧ‘璁ゆ椂鎶婃湰鏈篒P鍐欏叆鎵�閫夊伐浣嶏紙鍐橧P鍦ㄩ�夊伐浣嶉〉閲屽仛锛�
+ * - 3 鎸夌郴缁熼粯璁ゅ鐞嗭細璇P鏈粦瀹氳繃宸ヤ綅 鈫� 鎸� 2锛堥�変竴娆″苟璁颁綇IP锛夛紱宸茬粦瀹� 鈫� 鎸� 1锛涘尮閰嶄笉鍒� 鈫� 鎸� 0
+ *
+ * @returns true 琛ㄧず宸叉斁琛岋紙鏃犻渶璺宠浆锛夛紝false 琛ㄧず宸茬粡鍙戣捣璺宠浆
+ */
+const checkRoomSelect = async (
+ to: { path: string; fullPath: string },
+ next: (v?: any) => void
+): Promise<boolean> => {
+ const userStore = useUserStoreWithOut()
+ const roomStore = useRoomStoreWithOut()
+
+ // 闈炲尰鐢熻鑹层�佹垨宸插叆搴� 鈫� 涓嶅共棰�
+ const isDoctor =
+ userStore.getRoles.includes('doctor') && !userStore.getRoles.includes('super_admin')
+ if (!isDoctor || roomStore.getIsSetRoom || to.path === '/roomselect') {
+ // 鐜板満鎺掓煡鐢細璇存槑"涓轰粈涔堣繖娆℃病鏈夎嚜鍔ㄥ叆搴�"锛坅dmin 绛夐潪鍖荤敓瑙掕壊鎸夎璁′笉鑷姩鍏ュ骇锛�
+ // 闇�瑕佺偣椤舵爮鐨勩�屾湭鍏ュ骇銆嶆爣绛捐繘閫夊伐浣嶉〉鎵嬪姩閫変竴娆★級
+ if (!isDoctor) {
+ console.info('[room] 褰撳墠瑙掕壊闈炲尰鐢燂紙roles=' + userStore.getRoles.join(',') + '锛夛紝璺宠繃鎸塈P鑷姩鍏ュ骇')
+ }
+ return true
+ }
+
+ const mode = await roomStore.loadRoomSelectMode()
+
+ // 妯″紡 1 / 3锛氬厛灏濊瘯鎸夋湰鏈篒P鑷姩鍖归厤骞惰嚜鍔ㄥ叆搴э紙鎴愬姛灏辩洿鎺ヨ繘锛�
+ if (mode === 1 || mode === 3) {
+ const res = await roomStore.tryAutoSeatByIp()
+ if (res.seated) {
+ return true
+ }
+
+ // 銆愭湰闇�姹傘�戞湰鏈� IP 瀵瑰簲鐨勫伐浣�**鏈変汉鍧愮潃**锛堜笂涓�鐝尰鐢熸病閫�鍑哄伐浣嶏級鈫� 鎻愮ず鏄惁鎺ョ銆�
+ // 鎺ョ鍚庣珛鍗虫垚涓鸿宸ヤ綅涓讳汉锛屽苟鎸夌幇鏈夐�昏緫鑷姩鍔犺浇璇ュ伐浣嶃�屽氨璇婁腑銆嶆偅鑰呫��
+ if (res.reason === 'occupied' && res.roomId != null && res.bedNo) {
+ const bedText = `${res.roomName || '璇婂' + res.roomId} 路 ${res.bedNo}`
+ try {
+ await ElMessageBox.confirm(
+ `鏈満瀵瑰簲鐨勫伐浣嶃��${bedText}銆嶅綋鍓嶇敱銆�${res.occupiedBy || '鍏朵粬鍖荤敓'}銆嶅崰鐢ㄣ�俓n` +
+ `鏄惁鎺ョ璇ュ伐浣嶇户缁伐浣滐紵锛堟帴绠″悗瀵规柟灏嗚寮哄埗绂诲骇锛塦,
+ '宸ヤ綅琚崰鐢�',
+ { confirmButtonText: '鎺ョ宸ヤ綅', cancelButtonText: '鍏堜笉鎺ョ锛堝彧璇诲洿瑙傦級', type: 'warning' }
+ )
+ const ok = await roomStore.takeOverBed(res.roomId, res.bedNo)
+ if (ok) {
+ ElMessage.success(`宸叉帴绠″伐浣嶏細${bedText}`)
+ return true
+ }
+ ElMessage.warning('鎺ョ澶辫触锛屽凡鎸夊彧璇诲洿瑙傝繘鍏ワ紙鍙◢鍚庡湪椤舵爮銆屽伐浣嶃�嶉噷鍐嶈瘯锛�')
+ } catch {
+ // 鐢ㄦ埛閫夋嫨涓嶆帴绠� 鈫� 鎸夊彧璇诲洿瑙傝繘鍏�
+ console.info('[room] 鐢ㄦ埛鏀惧純鎺ョ宸ヤ綅锛屾寜鍙鍥磋杩涘叆')
+ }
+ }
+
+ // 銆愪富/鍥磋銆戞病鑷姩鍏ュ骇涔�**涓嶅啀寮哄埗璺�"閫夊伐浣嶉〉"**锛�
+ // 鍏佽浠�"鏈叆搴� / 鍥磋"韬唤杩涘叆宸ヤ綔鍙帮紙鍙锛夛紝鐢卞伐浣滃彴椤堕儴鐨勩�屽伐浣嶃�嶄笅鎷�
+ // 閫夋嫨瑕佹煡鐪嬶紙鍥磋锛夋垨瑕佸叆搴х殑宸ヤ綅銆傝嫢涓�寰嬪脊鍥為�夊伐浣嶉〉锛屽氨姘歌繙鏃犳硶鍥磋鍒汉銆�
+ console.info('[room] 鏈嚜鍔ㄥ叆搴э紙' + (res.reason || 'nomatch') + '锛夛紝鎸�"鍙洿瑙�"鏀捐')
+ return true
+ }
+
+ // 妯″紡 0 / 2锛氬師鏉ュ己鍒跺幓閫夊伐浣嶉〉锛涙湰娆″悓鏍锋斁琛岋紝鐞嗙敱鍚屼笂锛堢敱椤堕儴涓嬫媺閫夋嫨宸ヤ綅锛夈��
+ // 閫夊伐浣嶉〉浠嶅彲浠庨《鏍忓伐浣嶆爣绛� / 椤堕儴涓嬫媺杩涘叆銆�
+ console.info('[room] 閫夋嫨宸ヤ綅妯″紡=' + mode + '锛氫笉寮哄埗璺抽�夊伐浣嶉〉锛屽厑璁歌繘鍏ュ悗鑷閫夋嫨/鍥磋')
+ return true
+}
const parseURL = (
url: string | null | undefined
@@ -53,57 +132,97 @@
'/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.getIsSetRoom ) {
- next({path: `/login-room-select?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 checkTypeStore = useCheckTypeStoreWithOut()
+ const permissionStore = usePermissionStoreWithOut()
+ if (!dictStore.getIsSetDict) {
+ await dictStore.setDictMap()
+ }
+ if (!checkTypeStore.getIsSetCheckType) {
+ await checkTypeStore.setCheckTypeMap()
+ }
+
+ if (userStore.getIsSetUser) {
+
+ // <<<銆愯瘖瀹ら�夋嫨銆戞寜銆岄�夋嫨宸ヤ綅妯″紡銆嶅弬鏁帮紙0/1/2/3锛夊喅瀹氭槸鍚﹀己鍒堕�夋嫨宸ヤ綅 >>>
+ if (!(await checkRoomSelect(to, next))) {
+ 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) // 鍔ㄦ�佹坊鍔犲彲璁块棶璺敱琛�
+ })
+
+ // <<<銆愯瘖瀹ら�夋嫨銆戞寜銆岄�夋嫨宸ヤ綅妯″紡銆嶅弬鏁帮紙0/1/2/3锛夊喅瀹氭槸鍚﹀己鍒堕�夋嫨宸ヤ綅 >>>
+ if (!(await checkRoomSelect(to, next))) {
+ 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 +230,27 @@
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()
+ // 銆愭湰娆″彉鏇淬��**宸茬Щ闄�** `setupBedReleaseOnUnload()`锛坧agehide + sendBeacon锛夈��
+ //
+ // 鍘熻涓猴細鍏抽棴鏍囩椤� / 鍒锋柊 / 璺宠蛋鏃堕兘浼氶噴鏀惧崰鐢ㄧ殑宸ヤ綅锛屽鑷�
+ // 路 鎸� F5 鍒锋柊涓�娆″氨涓㈠伐浣嶏紱
+ // 路 娴忚鍣ㄥ穿婧冩仮澶嶃�佸垏璧颁竴浼氬効鍥炴潵锛屼篃鍙兘鍥� pagehide 涓㈠伐浣嶃��
+ // 鐜板湪宸ヤ綅鍙湪**鐢ㄦ埛涓诲姩鎿嶄綔**鏃堕噴鏀撅細鎵嬪姩銆岀搴с�嶃�佹墜鍔ㄣ�岄��鍑虹櫥褰曘�嶃��
+ // 鍖荤敓涓嬬彮蹇樼搴х殑鍏滃簳锛氣憼 闂瘖鏃剁粺涓�娓呯┖褰撶彮宸ヤ綅锛涒憽 绠$悊鍛樸�屾竻绌哄伐浣嶃�嶃��
+ }
})
--
Gitblit v1.9.3