element-plus ElMessage and ElMessageBox package
- Create a new message.ts under the custom folder
import {
ElNotification, ElMessage, ElMessageBox } from 'element-plus'
export const infoMsg = (msgInfo: string) => {
ElMessage({
type: 'info',
showClose: true,
dangerouslyUseHTMLString: true,
message: msgInfo,
})
}
export const succesMsg = (msgInfo: string) => {
ElMessage({
type: 'success',
showClose: true,
dangerouslyUseHTMLString: true,
message: msgInfo,
})
}
export const errorMsg = (msgInfo: string) => {
ElMessage({
type: 'error',
showClose: true,
dangerouslyUseHTMLString: true,
message: msgInfo,
})
}
export const warnMsg = (msgInfo: string) => {
ElMessage({
type: 'warning',
showClose: true,
dangerouslyUseHTMLString: true,
message: msgInfo,
})
}
export const alertBox = (msg: string, btnName: string, type: any, title?: string,) => {
let confirmName = btnName == '确定' ? '确定' : '是'
return ElMessageBox.alert(msg, title || '提示', {
type: type || 'warning',
confirmButtonText: confirmName,
buttonSize: "default",
dangerouslyUseHTMLString: true
});
}
export const confirmBox = (msg: string, btnName: string, type: any, title?: string,) => {
let confirmName = btnName == '确定' ? '确定' : '是'
let cancelsName = btnName == '确定' ? '取消' : '否'
return ElMessageBox.confirm(msg, title || '提示', {
type: type || 'warning',
confirmButtonText: confirmName,
cancelButtonText: cancelsName,
buttonSize: "default",
closeOnClickModal: false,
closeOnPressEscape: false,
dangerouslyUseHTMLString: true
})
}
- use
<script lang='ts' setup>
import {
succesMsg, confirmBox, warnMsg, errorMsg } from '/@/custom/message'
const checkEmptySelect = (rows: any[]): boolean => {
if (!rows || !rows.length) {
warnMsg('请选择至少一条数据')
return false;
}
return true;
};
</script>