Explorar el Código

服务器停运公告

FanHong hace 1 semana
padre
commit
9eefec6de6
Se han modificado 1 ficheros con 25 adiciones y 4 borrados
  1. 25 4
      shudao-vue-frontend/src/router/index.js

+ 25 - 4
shudao-vue-frontend/src/router/index.js

@@ -32,13 +32,13 @@ const routes = [
         console.log('📱 检测到移动设备,重定向到 /mobile')
         console.log('📍 原始 URL:', window.location.href)
         console.log('📍 原始查询参数:', to.query)
-        
+
         // 重定向时保留所有查询参数(包括票据)
         // 使用 replace 而不是 push,避免在历史记录中留下 /
-        next({ 
-          path: '/mobile', 
+        next({
+          path: '/mobile',
           query: to.query,  // 保留查询参数
-          replace: true 
+          replace: true
         });
       } else {
         next();
@@ -144,6 +144,27 @@ const router = createRouter({
   routes
 })
 
+// 全局前置守卫 - 系统停机维护拦截
+const isMaintenance = true; // 是否开启停机维护模式
+
+router.beforeEach((to, from, next) => {
+  if (isMaintenance) {
+    // 允许访问的维护页面(即显示了公告的主界面)
+    const allowedPaths = ['/', '/mobile'];
+
+    if (!allowedPaths.includes(to.path)) {
+      console.log('🚧 系统维护中,拦截访问:', to.path);
+      // 根据设备类型重定向到对应的主界面(带上原有参数防丢失)
+      if (isMobile()) {
+        return next({ path: '/mobile', query: to.query, replace: true });
+      } else {
+        return next({ path: '/', query: to.query, replace: true });
+      }
+    }
+  }
+  next();
+})
+
 // ===== 注释掉:登录认证守卫已废弃,改用票据认证 =====
 // 全局前置守卫 - 登录认证
 // router.beforeEach((to, from, next) => {