Files
lotteryFront/src/stores/error-store.ts
kang ca3a1db770 feat: enhance player panel and draw status handling
- Refactored PlayerPanel layout for improved title positioning and responsiveness.
- Added new function to check if betting is blocked based on hall status.
- Updated HallDrawPanel to utilize the new betting status check and display appropriate messages.
- Enhanced i18n support with new notices for review and non-bettable states across multiple languages.
2026-05-25 15:35:50 +08:00

73 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { create } from "zustand";
// 颜色常量
export const ERROR_COLORS = {
success: "#52c41a",
error: "#ff4d4f",
warning: "#faad14",
neutral: "#d9d9d9",
} as const;
type ErrorType = "network" | "server" | null;
interface ErrorState {
// 网络断开状态
isOffline: boolean;
setIsOffline: (value: boolean) => void;
// 服务器错误状态 (500)
isServerError: boolean;
serverErrorMessage: string;
setServerError: (isError: boolean, message?: string) => void;
clearServerError: () => void;
// 当前主要错误类型优先级server > network
currentErrorType: ErrorType;
}
export const useErrorStore = create<ErrorState>((set, get) => ({
// 首屏与 SSR 一致为 false真实离线状态由 useNetworkStatus 在 mount 后同步
isOffline: false,
isServerError: false,
serverErrorMessage: "服务器暂时不可用,请稍后重试",
currentErrorType: null,
// Actions
setIsOffline: (value: boolean) => {
set({ isOffline: value });
// 更新当前错误类型
const { isServerError } = get();
if (isServerError) {
set({ currentErrorType: "server" });
} else if (value) {
set({ currentErrorType: "network" });
} else {
set({ currentErrorType: null });
}
},
setServerError: (isError: boolean, message?: string) => {
set({
isServerError: isError,
serverErrorMessage: message || "服务器暂时不可用,请稍后重试",
});
// 更新当前错误类型 - 服务器错误优先级更高
if (isError) {
set({ currentErrorType: "server" });
} else {
const { isOffline } = get();
set({ currentErrorType: isOffline ? "network" : null });
}
},
clearServerError: () => {
const { isOffline } = get();
set({
isServerError: false,
currentErrorType: isOffline ? "network" : null,
});
},
}));