// stores/modalStore.ts import { create } from 'zustand'; type ModalConfig ={ content: React.ReactNode; beforeClose?: () => Promise | void; // 用户自定义关闭前回调 onCancel?: () => Promise | void; // 用户自定义关闭前回调 onConfirm?: () => Promise | void; // 用户自定义关闭前回调 } type ModalStore = { isVisible: boolean; config: ModalConfig | null; showModal: (config:ModalConfig) => void; hideModal: () => void; onConfirm: ()=> void onCancel: ()=> void }; export const useModalStore = create((set, get) => ({ isVisible: false, config: null, showModal: (config) => set({ isVisible: true, config }), hideModal: () => set({ isVisible: false }), onConfirm: () => { get().config?.onConfirm?.() get().hideModal(); }, onCancel: () => { get().config?.onCancel?.() get().hideModal(); }, }));