element-plus
2024/10/7小于 1 分钟
element-plus
弹出框封装
function defaultMessage(message: string, type: 'success' | 'warning' | 'info' | 'error' = 'success', showClose: boolean = false, duration: number = 3000) {
return ElMessage({
message,
type,
showClose,
duration
})
}
function defaultMessageBox(contentText: string, boxType: 'success' | 'warning' | 'info' | 'error' = 'warning',
doing: () => void = () => { }, undo: (action?: Action) => void = () => { }, title: string = 'Warning') {
ElMessageBox.confirm(
contentText,
title,
{
confirmButtonText: 'Yes',
cancelButtonText: 'Cancel',
type: boxType,
}
)
.then(doing)
.catch(undo)
}
function promiseMessageBox(contentText: string, boxType: 'success' | 'warning' | 'info' | 'error' = 'warning', title: string = 'Warning') {
return new Promise<boolean>((resolve) => {
ElMessageBox.confirm(
contentText,
title,
{
confirmButtonText: 'Yes',
cancelButtonText: 'Cancel',
type: boxType,
}
).then(() => {
resolve(true)
}).catch(() => resolve(false))
})
}