You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.4 KiB
148 lines
4.4 KiB
import Keys from '@/api/Keys' |
|
import type { Result } from '@/api/basic/httpTypes' |
|
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: '取消', |
|
confirmButtonClass: 'el-button--success', |
|
cancelButtonClass: 'el-button--default', |
|
type: 'warning', |
|
}) |
|
}, |
|
forceConfirm(content: string, tip?: string, buttonText?: string) { |
|
return ElMessageBox.confirm(content, tip ? tip : '系统提示', { |
|
confirmButtonText: buttonText ?? '确定', |
|
showCancelButton: false, |
|
closeOnClickModal: false, |
|
closeOnPressEscape: false, |
|
confirmButtonClass: 'el-button--success', |
|
cancelButtonClass: 'el-button--default', |
|
showClose: false, |
|
type: 'warning', |
|
}) |
|
}, |
|
// 删除窗体 |
|
delConfirm(content?: string, tip?: string) { |
|
return new Promise((resolve, reject) => { |
|
ElMessageBox.confirm( |
|
content ? content : '是否确认删除数据项?', |
|
tip ? tip : '系统提示', |
|
{ |
|
confirmButtonText: '确定', |
|
cancelButtonText: '取消', |
|
type: 'warning', |
|
confirmButtonClass: 'el-button--success', |
|
cancelButtonClass: 'el-button--default', |
|
} |
|
) |
|
.then(() => { |
|
resolve('') |
|
}) |
|
.catch(() => { |
|
reject('') |
|
}) |
|
}) |
|
}, |
|
// 导出窗体 |
|
exportConfirm(content?: string, tip?: string) { |
|
return ElMessageBox.confirm( |
|
content ? content : '是否确认导出数据项?', |
|
tip ? tip : '系统提示', |
|
{ |
|
confirmButtonText: '确定', |
|
cancelButtonText: '取消', |
|
confirmButtonClass: 'el-button--success', |
|
cancelButtonClass: 'el-button--default', |
|
type: 'warning', |
|
} |
|
) |
|
}, |
|
// 提交内容 |
|
prompt(content: string, tip: string) { |
|
return ElMessageBox.prompt(content, tip, { |
|
confirmButtonText: '确定', |
|
cancelButtonText: '取消', |
|
confirmButtonClass: 'el-button--success', |
|
cancelButtonClass: 'el-button--default', |
|
type: 'warning', |
|
}) |
|
}, |
|
|
|
promptVerify(content: string, tip: string, pattern: string, inputErrorMessage = '') { |
|
const PatternRegExp = new RegExp( |
|
`^${pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')}$` |
|
) |
|
return ElMessageBox.prompt(content, tip, { |
|
confirmButtonText: '确定', |
|
cancelButtonText: '取消', |
|
confirmButtonClass: 'el-button--success', |
|
cancelButtonClass: 'el-button--default', |
|
inputPattern: PatternRegExp, |
|
inputErrorMessage: inputErrorMessage, |
|
type: 'warning', |
|
}) |
|
}, |
|
} |
|
} |
|
|
|
export function isResError(res: Result<any>, msg?: string) { |
|
if (res.code === Keys.CODE_SUCCEED || res.status === 200 || res.code === 200) |
|
return false |
|
ElMessage.error(res?.msg ?? msg) |
|
return true |
|
}
|
|
|