From 977c0905bd3dc7475a1faecbe8f300ed9d1bd360 Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 17 Jun 2026 15:30:36 +0800 Subject: [PATCH] refactor(chat): remove redundant auth state management from ChatScreen documentation refactor(chat): update guest chat quota logic to use isProduction utility fix(user): add TODO for user initialization event on login status change --- src/app/chat/chat-screen.tsx | 5 ----- src/data/dto/chat/guest_chat_quota.ts | 22 ++++++++-------------- src/stores/user/user-auth-sync.tsx | 1 + 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/app/chat/chat-screen.tsx b/src/app/chat/chat-screen.tsx index eb3f0d8f..a247f6db 100644 --- a/src/app/chat/chat-screen.tsx +++ b/src/app/chat/chat-screen.tsx @@ -2,11 +2,6 @@ /** * ChatScreen 编排层 * - * 职责(本文件): - * - 订阅 auth 状态机(loginStatus)—— 派生 isGuest / 派鉴权生命周期事件给 chat 机器 - * - 屏幕生命周期事件(init / visible / invisible) - * - 不直接管理 WebSocket / 不直接读 AuthStorage(除 token 取值) - * * 子组件职责: * - ChatHeader:顶部栏(游客 banner / 菜单按钮) * - ChatArea:消息列表 diff --git a/src/data/dto/chat/guest_chat_quota.ts b/src/data/dto/chat/guest_chat_quota.ts index 8bd7204d..eccc2c86 100644 --- a/src/data/dto/chat/guest_chat_quota.ts +++ b/src/data/dto/chat/guest_chat_quota.ts @@ -6,6 +6,7 @@ import { type GuestChatQuotaInput, type GuestChatQuotaData, } from "@/data/schemas/chat/guest_chat_quota"; +import { isProduction } from "@/utils/app-env"; export class GuestChatQuota { // 静态常量 @@ -13,7 +14,7 @@ export class GuestChatQuota { static readonly maxQuotaPerDayTest = 4; static readonly defaultTotalQuota = 50; - static readonly defaultTotalQuotaDev = 5; + static readonly defaultTotalQuotaTest = 5; static readonly quotaExhausted = 0; declare readonly remaining: number; @@ -40,29 +41,22 @@ export class GuestChatQuota { return GuestChatQuota.quotaExhausted; } - /** - * 是否处于开发环境 - */ - static get isDevelopment(): boolean { - return process.env.NODE_ENV !== "production"; - } - /** * 获取当前环境的每日最大配额 */ static get threshold(): number { - return GuestChatQuota.isDevelopment - ? GuestChatQuota.maxQuotaPerDayTest - : GuestChatQuota.maxQuotaPerDay; + return isProduction() + ? GuestChatQuota.maxQuotaPerDay + : GuestChatQuota.maxQuotaPerDayTest; } /** * 获取当前环境的总配额默认值 */ static get totalQuotaDefault(): number { - return GuestChatQuota.isDevelopment - ? GuestChatQuota.defaultTotalQuotaDev - : GuestChatQuota.defaultTotalQuota; + return isProduction() + ? GuestChatQuota.defaultTotalQuota + : GuestChatQuota.defaultTotalQuotaTest; } /** diff --git a/src/stores/user/user-auth-sync.tsx b/src/stores/user/user-auth-sync.tsx index 26911c9d..78710f42 100644 --- a/src/stores/user/user-auth-sync.tsx +++ b/src/stores/user/user-auth-sync.tsx @@ -19,6 +19,7 @@ export function UserAuthSync() { const userDispatch = useUserDispatch(); const lastInitializedStatusRef = useRef(null); + //TODO 在测位栏界面监听变化,监听登录状态的变化若发生变化,则需要分发 user init 事件 useEffect(() => { if (loginStatus === "notLoggedIn" || loginStatus === "guest") { lastInitializedStatusRef.current = null;