7 changed files with 282 additions and 52 deletions
@ -0,0 +1,127 @@ |
|||||||
|
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus' |
||||||
|
export const useMessage = () => { |
||||||
|
return { |
||||||
|
// 消息提示
|
||||||
|
info(content: string) { |
||||||
|
ElMessage.info(content) |
||||||
|
}, |
||||||
|
// 错误消息
|
||||||
|
error(content: string) { |
||||||
|
ElMessage.error(content) |
||||||
|
}, |
||||||
|
// 成功消息
|
||||||
|
success(content: string) { |
||||||
|
ElMessage.success(content) |
||||||
|
}, |
||||||
|
// 警告消息
|
||||||
|
warning(content: string) { |
||||||
|
ElMessage.warning(content) |
||||||
|
}, |
||||||
|
// 弹出提示
|
||||||
|
alert(content: string) { |
||||||
|
ElMessageBox.alert(content, '系统提示') |
||||||
|
}, |
||||||
|
// 错误提示
|
||||||
|
alertError(content: string) { |
||||||
|
ElMessageBox.alert(content, '系统提示', { type: 'error' }) |
||||||
|
}, |
||||||
|
// 成功提示
|
||||||
|
alertSuccess(content: string) { |
||||||
|
ElMessageBox.alert(content, '系统提示', { type: 'success' }) |
||||||
|
}, |
||||||
|
// 警告提示
|
||||||
|
alertWarning(content: string) { |
||||||
|
ElMessageBox.alert(content, '系统提示', { type: 'warning' }) |
||||||
|
}, |
||||||
|
// 通知提示
|
||||||
|
notify(content: string) { |
||||||
|
ElNotification.info(content) |
||||||
|
}, |
||||||
|
// 错误通知
|
||||||
|
notifyError(content: string, tip?: string) { |
||||||
|
ElNotification.error({ |
||||||
|
title: tip ? tip : '系统提示', |
||||||
|
message: content, |
||||||
|
}) |
||||||
|
}, |
||||||
|
// 成功通知
|
||||||
|
notifySuccess(content: string) { |
||||||
|
ElNotification.success(content) |
||||||
|
}, |
||||||
|
// 警告通知
|
||||||
|
notifyWarning(content: string) { |
||||||
|
ElNotification.warning(content) |
||||||
|
}, |
||||||
|
// 确认窗体
|
||||||
|
confirm(content: string, tip?: string) { |
||||||
|
return ElMessageBox.confirm(content, tip ? tip : '系统提示', { |
||||||
|
confirmButtonText: '确定', |
||||||
|
cancelButtonText: '取消', |
||||||
|
type: 'warning', |
||||||
|
}) |
||||||
|
}, |
||||||
|
forceConfirm(content: string, tip?: string, buttonText?: string) { |
||||||
|
return ElMessageBox.confirm(content, tip ? tip : '系统提示', { |
||||||
|
confirmButtonText: buttonText ?? '确定', |
||||||
|
showCancelButton: false, |
||||||
|
closeOnClickModal: false, |
||||||
|
closeOnPressEscape: false, |
||||||
|
showClose: false, |
||||||
|
type: 'warning', |
||||||
|
}) |
||||||
|
}, |
||||||
|
// 删除窗体
|
||||||
|
delConfirm(content?: string, tip?: string) { |
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
ElMessageBox.confirm( |
||||||
|
content ? content : '是否确认删除数据项?', |
||||||
|
tip ? tip : '系统提示', |
||||||
|
{ |
||||||
|
confirmButtonText: '确定', |
||||||
|
cancelButtonText: '取消', |
||||||
|
type: 'warning', |
||||||
|
} |
||||||
|
) |
||||||
|
.then(() => { |
||||||
|
resolve('') |
||||||
|
}) |
||||||
|
.catch(() => { |
||||||
|
reject('') |
||||||
|
}) |
||||||
|
}) |
||||||
|
}, |
||||||
|
// 导出窗体
|
||||||
|
exportConfirm(content?: string, tip?: string) { |
||||||
|
return ElMessageBox.confirm( |
||||||
|
content ? content : '是否确认导出数据项?', |
||||||
|
tip ? tip : '系统提示', |
||||||
|
{ |
||||||
|
confirmButtonText: '确定', |
||||||
|
cancelButtonText: '取消', |
||||||
|
type: 'warning', |
||||||
|
} |
||||||
|
) |
||||||
|
}, |
||||||
|
// 提交内容
|
||||||
|
prompt(content: string, tip: string) { |
||||||
|
return ElMessageBox.prompt(content, tip, { |
||||||
|
confirmButtonText: '确定', |
||||||
|
cancelButtonText: '取消', |
||||||
|
type: 'warning', |
||||||
|
}) |
||||||
|
}, |
||||||
|
|
||||||
|
promptVerify(content: string, tip: string, pattern: string, inputErrorMessage = '') { |
||||||
|
const PatternRegExp = new RegExp( |
||||||
|
`^${pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')}$` |
||||||
|
) |
||||||
|
return ElMessageBox.prompt(content, tip, { |
||||||
|
confirmButtonText: '确定', |
||||||
|
cancelButtonText: '取消', |
||||||
|
inputPattern: PatternRegExp, |
||||||
|
inputErrorMessage: inputErrorMessage, |
||||||
|
type: 'warning', |
||||||
|
}) |
||||||
|
}, |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue