Files
lingxi-web/src/app/store/confirm.ts
T

28 lines
674 B
TypeScript

import { create } from 'zustand'
export interface ConfirmOptions {
title: string
description?: string
confirmText?: string
cancelText?: string
danger?: boolean
onConfirm: () => void | Promise<void>
}
interface ConfirmState {
current: ConfirmOptions | null
ask: (opts: ConfirmOptions) => void
close: () => void
}
export const useConfirmStore = create<ConfirmState>()((set) => ({
current: null,
ask: (opts) => set({ current: opts }),
close: () => set({ current: null }),
}))
/** 任意位置调用:confirmDialog({ title, danger, onConfirm }) */
export function confirmDialog(opts: ConfirmOptions): void {
useConfirmStore.getState().ask(opts)
}