From fb4db4ae9b6a7f113ba049f6789e6916c0dcc276 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 12 十月 2026 09:15:08 +0800
Subject: [PATCH] feat(mes): 新增业务码支持并优化追溯查询功能

---
 src/router/guard.ts |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/router/guard.ts b/src/router/guard.ts
index 8b88c83..3e27562 100644
--- a/src/router/guard.ts
+++ b/src/router/guard.ts
@@ -13,6 +13,8 @@
 import { useAuthStore } from '#/store';
 
 import { generateAccess } from './access';
+import { safeDestination, terminalHome, terminalType } from '#/mobile/terminal';
+import { allowedMobilePath } from '#/mobile/access';
 
 /**
  * 閫氱敤瀹堝崼閰嶇疆
@@ -55,14 +57,24 @@
     const authStore = useAuthStore();
     const dictStore = useDictStore();
 
+    // Mobile core routes require authentication and per-feature authorization.
+    if (to.path.startsWith('/mobile')) {
+      if (!accessStore.accessToken) return { path: LOGIN_PATH, query: { redirect: encodeURIComponent(to.fullPath) }, replace: true };
+      if (terminalType.value !== 'mobile') return preferences.app.defaultHomePath;
+      if (authStore.loadedTerminal !== 'mobile') {
+        try { await authStore.fetchUserInfo(); }
+        catch { return { path: LOGIN_PATH, query: { loadError: '1' }, replace: true }; }
+      }
+      if (!allowedMobilePath(to.path)) return { path: '/mobile/home', query: { forbidden: '1' }, replace: true };
+      return true;
+    }
+    if (accessStore.accessToken && terminalType.value === 'mobile' && !to.path.startsWith('/auth/')) return '/mobile/home';
+
     // 鍩烘湰璺敱锛岃繖浜涜矾鐢变笉闇�瑕佽繘鍏ユ潈闄愭嫤鎴�
     if (coreRouteNames.includes(to.name as string)) {
-      if (to.path === LOGIN_PATH && accessStore.accessToken) {
-        return decodeURIComponent(
-          (to.query?.redirect as string) ||
-            userStore.userInfo?.homePath ||
-            preferences.app.defaultHomePath,
-        );
+      if (to.path === LOGIN_PATH && accessStore.accessToken && !to.query.loadError) {
+        return safeDestination(to.query?.redirect,
+          terminalHome() || userStore.userInfo?.homePath || preferences.app.defaultHomePath);
       }
       return true;
     }
@@ -90,6 +102,15 @@
       return to;
     }
 
+    // A fresh tab or a terminal switch must reload the corresponding menu set.
+    if (authStore.loadedTerminal !== 'pc') {
+      try {
+        await authStore.fetchUserInfo();
+        accessStore.setIsAccessChecked(false);
+      } catch {
+        return { path: LOGIN_PATH, query: { loadError: '1' }, replace: true };
+      }
+    }
     // 鏄惁宸茬粡鐢熸垚杩囧姩鎬佽矾鐢�
     if (accessStore.isAccessChecked) {
       return true;

--
Gitblit v1.9.3