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.
87 lines
1.5 KiB
87 lines
1.5 KiB
2 years ago
|
import {
|
||
|
ElLoading,
|
||
|
ElMessage,
|
||
|
ElNotification,
|
||
|
ElMessageBox,
|
||
|
Action,
|
||
|
} from 'element-plus';
|
||
|
let curMsg;
|
||
|
let count = 0;
|
||
|
let instance;
|
||
|
|
||
|
export function loading() {
|
||
|
if (count === 0) {
|
||
|
instance = ElLoading.service({
|
||
|
lock: true,
|
||
|
text: '加载中...',
|
||
|
spinner: 'el-icon-loading',
|
||
|
background: 'rgba(0, 0, 0, 0.3)',
|
||
|
});
|
||
|
}
|
||
|
count++;
|
||
|
}
|
||
|
|
||
|
export function close() {
|
||
|
if (count <= 0) {
|
||
|
return;
|
||
|
}
|
||
|
if (--count === 0) {
|
||
|
instance.close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function showMessage(type, info, unClose) {
|
||
|
if (curMsg != null) {
|
||
|
curMsg.close();
|
||
|
}
|
||
|
const tmp = ElMessage({
|
||
|
type: type,
|
||
|
showClose: true,
|
||
|
message: info,
|
||
|
duration: 3000,
|
||
|
offset: 50,
|
||
|
});
|
||
|
if (!unClose) {
|
||
|
curMsg = tmp;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export function showNotify(type, title, message, position) {
|
||
|
if (position == null) {
|
||
|
position = 'top-right';
|
||
|
}
|
||
|
ElNotification({
|
||
|
title: title,
|
||
|
type: type,
|
||
|
message: message,
|
||
|
position: position,
|
||
|
duration: 0,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function warning(msg) {
|
||
|
showMessage('warning', msg, false);
|
||
|
}
|
||
|
|
||
|
export function error(msg) {
|
||
|
showMessage('error', msg, false);
|
||
|
}
|
||
|
|
||
|
export function success(msg) {
|
||
|
showMessage('success', msg, false);
|
||
|
}
|
||
|
|
||
|
export const confirm = (msg: string, title: string) => {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
ElMessageBox.confirm(msg, title, {
|
||
|
confirmButtonText: '确定',
|
||
|
cancelButtonText: '取消',
|
||
|
buttonSize: 'default',
|
||
|
confirmButtonClass: 'el-button--info',
|
||
|
type: 'warning',
|
||
|
})
|
||
|
.then(resolve)
|
||
|
.catch(reject);
|
||
|
});
|
||
|
};
|