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/store/auth.ts |   67 ++++++++++++++++++++++++++++++++-
 1 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/yuyueMiniProgram/src/store/auth.ts b/yuyueMiniProgram/src/store/auth.ts
index 2320da0..5846b14 100644
--- a/yuyueMiniProgram/src/store/auth.ts
+++ b/yuyueMiniProgram/src/store/auth.ts
@@ -8,10 +8,26 @@
   profile: MiniUserProfile | null
 }
 
+export interface MiniAuthUiState {
+  loginPromptVisible: boolean
+  needPhoneAuthorize: boolean
+  authPromptMessage: string
+}
+
+type MiniAuthStoreState = MiniAuthState & MiniAuthUiState
+
 function createInitialState(): MiniAuthState {
   return {
     token: '',
     profile: null,
+  }
+}
+
+function createInitialUiState(): MiniAuthUiState {
+  return {
+    loginPromptVisible: false,
+    needPhoneAuthorize: false,
+    authPromptMessage: '',
   }
 }
 
@@ -38,7 +54,7 @@
   uni.setStorageSync(MINI_AUTH_STORAGE_KEY, state)
 }
 
-function patchActiveStore(state: MiniAuthState) {
+function patchActiveStore(state: Partial<MiniAuthStoreState>) {
   const pinia = getActivePinia()
   if (!pinia) {
     return
@@ -50,7 +66,10 @@
 export function clearMiniAuthSession() {
   const state = createInitialState()
   uni.removeStorageSync(MINI_AUTH_STORAGE_KEY)
-  patchActiveStore(state)
+  patchActiveStore({
+    ...state,
+    ...createInitialUiState(),
+  })
 }
 
 export function updateMiniAuthProfile(profile: MiniUserProfile) {
@@ -62,8 +81,32 @@
   patchActiveStore(state)
 }
 
+export function showMiniLoginPrompt(message = '') {
+  patchActiveStore({
+    loginPromptVisible: true,
+    authPromptMessage: message,
+  })
+}
+
+export function hideMiniLoginPrompt() {
+  patchActiveStore({
+    loginPromptVisible: false,
+    authPromptMessage: '',
+    needPhoneAuthorize: false,
+  })
+}
+
+export function setMiniPhoneAuthorizeRequired(required: boolean) {
+  patchActiveStore({
+    needPhoneAuthorize: required,
+  })
+}
+
 export const useMiniAuthStore = defineStore('miniAuth', {
-  state: (): MiniAuthState => createInitialState(),
+  state: (): MiniAuthStoreState => ({
+    ...createInitialState(),
+    ...createInitialUiState(),
+  }),
   getters: {
     isLoggedIn: state => Boolean(state.token),
   },
@@ -71,6 +114,9 @@
     setSession(payload: MiniAuthState) {
       this.token = payload.token
       this.profile = payload.profile
+      this.loginPromptVisible = false
+      this.needPhoneAuthorize = false
+      this.authPromptMessage = ''
       writePersistedAuthState({
         token: payload.token,
         profile: payload.profile,
@@ -86,6 +132,9 @@
     clearSession() {
       this.token = ''
       this.profile = null
+      this.loginPromptVisible = false
+      this.needPhoneAuthorize = false
+      this.authPromptMessage = ''
       uni.removeStorageSync(MINI_AUTH_STORAGE_KEY)
     },
     restoreSession() {
@@ -94,5 +143,17 @@
       this.profile = state.profile
       return state
     },
+    showLoginPrompt(message = '') {
+      this.loginPromptVisible = true
+      this.authPromptMessage = message
+    },
+    hideLoginPrompt() {
+      this.loginPromptVisible = false
+      this.needPhoneAuthorize = false
+      this.authPromptMessage = ''
+    },
+    setNeedPhoneAuthorize(required: boolean) {
+      this.needPhoneAuthorize = required
+    },
   },
 })

--
Gitblit v1.7.1