import {createEnum} from "@peryl/utils/createEnum"; import {Dialog} from "../Dialog"; import {ThemeStatus} from "../../uses/useStyle"; import {anonymousEffects, createHooks, RenderNode} from "@peryl/react-compose"; import {createCounter} from "@peryl/utils/createCounter"; /** * 给dialog option生成id * @author 韦胜健 * @date 2022.5.4 21:45 */ export const nextDialogId = createCounter('dialog-service'); /** * 关闭dialog观察者对象 * @author 韦胜健 * @date 2022.5.4 21:45 */ export const closeDialogServiceHook = createHooks<(id?: string) => void>(anonymousEffects); /** * 销毁dialog观察者对象 * @author 韦胜健 * @date 2022.5.4 21:45 */ export const destroyDialogServiceHook = createHooks<(option: any) => void>(anonymousEffects); /** * 弹框服务编辑框类型 * @author 韦胜健 * @date 2022.5.3 14:05 */ export const DialogServiceEditType = createEnum(['input', 'textarea', 'number'] as const); /** * 弹框服务,独立于DialogProps额外的属性 * @author 韦胜健 * @date 2022.5.3 14:12 */ export interface iDialogServiceCustomOption { id?: string, // 关闭弹框服务的唯一标识 message?: string, // 提示的消息 editRequired?: boolean, // 输入的时候是否必填 editType?: keyof typeof DialogServiceEditType, // 输入类型 editValue?: string | number | null, // 输入初始内容 editReadonly?: boolean, // 输入框只读 handleConfirm?: (data: { close: () => void, editValue?: string | number | null }) => void | boolean | Promise, // 处理确定动作 hold?: boolean, // 持久使用实例,不释放 status?: typeof ThemeStatus.TYPE | null, // 对话框状态 render?: () => RenderNode, // 自定义对话框内容 renderHead?: () => RenderNode, // 自定义对话框标题内容 renderFoot?: () => RenderNode, // 自定义对话框底部内容 } /** * 用来获取keys的类型 * @author 韦胜健 * @date 2022.5.3 14:11 */ const dialogCustomOption: Record = { id: '', message: '', editRequired: false, editReadonly: false, editType: 'input', editValue: '', render: () => null, renderHead: () => null, renderFoot: () => null, status: 'secondary', handleConfirm: null, hold: '', }; /** * 弹框服务自定义额外的ket,用来区分dialog本身的props * @author 韦胜健 * @date 2022.5.3 14:27 */ export const dialogCustomOptionKeys = Object.keys(dialogCustomOption); /** * 弹框服务参数对象配置类型 * @author 韦胜健 * @date 2022.5.3 14:28 */ export type iDialogServiceOption = iDialogServiceCustomOption & Omit, 'handleConfirm' | 'status'>