feat: 添加全局确认对话框管理器,重构对话框服务,优化用户交互体验
This commit is contained in:
1 parent
4367fd6ed1
commit
562e4f5b9e
9 files changed
+543
-11
No files matched your search
@@ -0,0 +1,97 @@
|
||||
// 定义对话框选项接口
|
||||
interface BaseDialogOptions {
|
||||
title: string
|
||||
message: string
|
||||
confirmText?: string
|
||||
cancelText?: string
|
||||
confirmColor?: string
|
||||
}
|
||||
|
||||
interface ConfirmDialogOptions extends BaseDialogOptions { }
|
||||
|
||||
interface MessageDialogOptions extends BaseDialogOptions {
|
||||
dialogColor?: string
|
||||
}
|
||||
|
||||
// 对话框类型
|
||||
type DialogType = 'confirm' | 'info' | 'success' | 'warning' | 'error'
|
||||
|
||||
// 全局对话框管理器接口
|
||||
interface GlobalDialogManager {
|
||||
showConfirm: (options: ConfirmDialogOptions) => Promise<boolean>
|
||||
showMessage: (options: MessageDialogOptions) => Promise<void>
|
||||
}
|
||||
|
||||
// 确认对话框服务
|
||||
export const ConfirmDialogService = {
|
||||
// 显示确认对话框
|
||||
async confirm(options: ConfirmDialogOptions): Promise<boolean> {
|
||||
if (window.ConfirmDialogManager) {
|
||||
return (window.ConfirmDialogManager as GlobalDialogManager).showConfirm(options)
|
||||
} else {
|
||||
console.error('GlobalDialog component not properly initialized')
|
||||
// 降级到原生 confirm
|
||||
return confirm(`${options.title}: ${options.message}`)
|
||||
}
|
||||
},
|
||||
|
||||
// 显示信息对话框
|
||||
async info(options: MessageDialogOptions): Promise<void> {
|
||||
if (window.ConfirmDialogManager) {
|
||||
return (window.ConfirmDialogManager as GlobalDialogManager).showMessage({
|
||||
...options,
|
||||
dialogColor: options.dialogColor || 'info',
|
||||
confirmColor: options.confirmColor || 'white'
|
||||
})
|
||||
} else {
|
||||
console.error('GlobalDialog component not properly initialized')
|
||||
// 降级到原生 alert
|
||||
alert(`${options.title}: ${options.message}`)
|
||||
}
|
||||
},
|
||||
|
||||
// 显示成功对话框
|
||||
async success(options: MessageDialogOptions): Promise<void> {
|
||||
if (window.ConfirmDialogManager) {
|
||||
return (window.ConfirmDialogManager as GlobalDialogManager).showMessage({
|
||||
...options,
|
||||
dialogColor: options.dialogColor || 'success',
|
||||
confirmColor: options.confirmColor || 'white'
|
||||
})
|
||||
} else {
|
||||
console.error('GlobalDialog component not properly initialized')
|
||||
// 降级到原生 alert
|
||||
alert(`${options.title}: ${options.message}`)
|
||||
}
|
||||
},
|
||||
|
||||
// 显示警告对话框
|
||||
async warning(options: MessageDialogOptions): Promise<void> {
|
||||
if (window.ConfirmDialogManager) {
|
||||
return (window.ConfirmDialogManager as GlobalDialogManager).showMessage({
|
||||
...options,
|
||||
dialogColor: options.dialogColor || 'warning',
|
||||
confirmColor: options.confirmColor || 'white'
|
||||
})
|
||||
} else {
|
||||
console.error('GlobalDialog component not properly initialized')
|
||||
// 降级到原生 alert
|
||||
alert(`${options.title}: ${options.message}`)
|
||||
}
|
||||
},
|
||||
|
||||
// 显示错误对话框
|
||||
async error(options: MessageDialogOptions): Promise<void> {
|
||||
if (window.ConfirmDialogManager) {
|
||||
return (window.ConfirmDialogManager as GlobalDialogManager).showMessage({
|
||||
...options,
|
||||
dialogColor: options.dialogColor || 'error',
|
||||
confirmColor: options.confirmColor || 'white'
|
||||
})
|
||||
} else {
|
||||
console.error('GlobalDialog component not properly initialized')
|
||||
// 降级到原生 alert
|
||||
alert(`${options.title}: ${options.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user