123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- type DialogType = 'success' | 'error' | 'info'
- interface DialogBoxProps {
- show?: boolean
- type?: DialogType
- confirmText?: string
- confirmPlain?: boolean
- cancelText?: string
- iconSize?: string
- message?: string
- tip?: string
- showConfirm?: boolean
- showCancel?: boolean
- showTip?: boolean
- closeOnClickOverlay?: boolean
- }
- const DIALOG_PRESETS: Record<DialogType, Partial<DialogBoxProps>> = {
- info: {
- type: 'info',
- iconSize: '120rpx',
- confirmText: '知道了',
- },
- success: {
- type: 'success',
- iconSize: '120rpx',
- confirmText: '好的',
- },
- error: {
- type: 'error',
- iconSize: '120rpx',
- confirmText: '重试',
- },
- }
- /**
- * 创建预设对话框配置
- * @param type 对话框类型
- * @param message 消息内容
- * @param options 额外配置选项
- * @returns 对话框配置
- */
- export function createDialogConfig(
- type: DialogType,
- message: string,
- options: Partial<DialogBoxProps> = {},
- ): DialogBoxProps {
- const preset = DIALOG_PRESETS[type]
- return {
- show: true,
- message,
- ...preset,
- ...options,
- }
- }
- /**
- * 创建信息对话框配置
- */
- export function createInfoDialog(message: string, options?: Partial<DialogBoxProps>) {
- return createDialogConfig('info', message, options)
- }
- /**
- * 创建成功对话框配置
- */
- export function createSuccessDialog(message: string, options?: Partial<DialogBoxProps>) {
- return createDialogConfig('success', message, options)
- }
- /**
- * 创建错误对话框配置
- */
- export function createErrorDialog(message: string, options?: Partial<DialogBoxProps>) {
- return createDialogConfig('error', message, options)
- }
- /**
- * 对话框工具类
- */
- export class DialogUtils {
- /**
- * 显示信息对话框
- */
- static info(message: string, options?: Partial<DialogBoxProps>) {
- return createInfoDialog(message, options)
- }
- /**
- * 显示成功对话框
- */
- static success(message: string, options?: Partial<DialogBoxProps>) {
- return createSuccessDialog(message, options)
- }
- /**
- * 显示错误对话框
- */
- static error(message: string, options?: Partial<DialogBoxProps>) {
- return createErrorDialog(message, options)
- }
- }
|