From bfa7d3b23e526809b04299d9c2719c3449aba3be Mon Sep 17 00:00:00 2001
From: longz <longzhaoz@qq.com>
Date: 星期二, 28 四月 2026 10:32:42 +0800
Subject: [PATCH] 小程序图片压缩

---
 yuyueMiniProgram/src/router/index.ts |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/yuyueMiniProgram/src/router/index.ts b/yuyueMiniProgram/src/router/index.ts
index c888450..d0f4898 100644
--- a/yuyueMiniProgram/src/router/index.ts
+++ b/yuyueMiniProgram/src/router/index.ts
@@ -2,7 +2,7 @@
 import { pages, subPackages } from 'virtual:uni-pages'
 import { fetchMiniMe } from '@/api/auth'
 import { setUnauthorizedRedirectHandler } from './authRedirect'
-import { clearMiniAuthSession, getPersistedAuthState, updateMiniAuthProfile } from '@/store/auth'
+import { clearMiniAuthSession, getPersistedAuthState, showMiniLoginPrompt, updateMiniAuthProfile } from '@/store/auth'
 import { normalizeMeProfile } from '@/types/auth'
 
 function generateRoutes() {
@@ -27,10 +27,11 @@
 })
 
 setUnauthorizedRedirectHandler(() => {
-  router.replaceAll({ name: 'login' })
+  showMiniLoginPrompt('登录已失效,请重新登录')
+  router.replaceAll({ name: 'home' })
 })
 
-const PUBLIC_ROUTE_NAMES = new Set(['login', 'visitorCode'])
+const PUBLIC_ROUTE_NAMES = new Set(['home', 'login', 'visitorCode'])
 const HOME_ROUTE_NAME = 'home'
 
 function isPublicRoute(name?: string) {
@@ -48,7 +49,8 @@
       next()
       return
     }
-    next({ name: 'login' })
+    showMiniLoginPrompt('您还未登录,请先登录')
+    next({ name: HOME_ROUTE_NAME })
     return
   }
 
@@ -64,16 +66,17 @@
     catch (error) {
       console.warn('mini auth guard fetch /me failed', error)
       clearMiniAuthSession()
+      showMiniLoginPrompt('登录已失效,请重新登录')
       return false
     }
   }
 
   return Promise.resolve(ensureProfile()).then((ok) => {
     if (!ok) {
-      next({ name: 'login' })
+      next({ name: HOME_ROUTE_NAME })
       return
     }
-    if (publicRoute) {
+    if (to.name === 'login') {
       next({ name: HOME_ROUTE_NAME })
       return
     }

--
Gitblit v1.7.1