再次封装Msg组件,扫码功能增加中转页面
This commit is contained in:
162
utils/MsgPops.js
Normal file
162
utils/MsgPops.js
Normal file
@ -0,0 +1,162 @@
|
||||
var MsgType = {
|
||||
error: "error",
|
||||
succ: "succ",
|
||||
warn: "warn"
|
||||
}
|
||||
var time = null;
|
||||
// 显示成功
|
||||
export const MsgSuccess = (msg, btnTxt, ev) => {
|
||||
|
||||
if (!ev) {
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!ev.$refs.msgPop) {
|
||||
|
||||
return null;
|
||||
}
|
||||
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.succ);
|
||||
|
||||
createClear(ev);
|
||||
return option;
|
||||
}
|
||||
//显示失败
|
||||
export const MsgError = (msg, btnTxt, ev) => {
|
||||
|
||||
if (!ev) {
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!ev.$refs.msgPop) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.error);
|
||||
createClear(ev);
|
||||
return option;
|
||||
}
|
||||
//显示警告
|
||||
export const MsgWarning = (msg, btnTxt, ev, isClear) => {
|
||||
if (!ev) {
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!ev.$refs.msgPop) {
|
||||
|
||||
return null;
|
||||
}
|
||||
let option = ev.$refs.msgPop.showMsg(msg, btnTxt, MsgType.warn);
|
||||
if (isClear === undefined || isClear) {
|
||||
createClear(ev);
|
||||
}
|
||||
|
||||
return option;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 隐藏loading
|
||||
export const MsgClose = (options, ev) => {
|
||||
|
||||
|
||||
if (!ev) {
|
||||
|
||||
return;
|
||||
}
|
||||
if (!ev.$refs.msgPop) {
|
||||
|
||||
return;
|
||||
}
|
||||
if (typeof(options) == 'string') {
|
||||
options = {
|
||||
key: options
|
||||
}
|
||||
}
|
||||
ev.$refs.msgPop.closePop(options);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const showPop = (options, ev, isClear) => {
|
||||
|
||||
|
||||
if (!ev) {
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!ev.$refs.msgPop) {
|
||||
|
||||
return null;
|
||||
}
|
||||
let option = ev.$refs.msgPop.showPop(options);
|
||||
|
||||
if (isClear === undefined || isClear) {
|
||||
createClear(ev);
|
||||
}
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
const createClear = (ev) => {
|
||||
let cnt = getPops(ev);
|
||||
if (cnt >= 5) {
|
||||
clearTimeout(time);
|
||||
time = setTimeout(() => {
|
||||
let key = new Date().getTime();
|
||||
showPop({
|
||||
key: key,
|
||||
message: "消息太多, 是否全部关闭",
|
||||
iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png",
|
||||
borderColor: "#e034344d",
|
||||
buttonBgColor: "#E03434",
|
||||
buttonText: '全部关闭',
|
||||
buttonTextColor: '#232323de',
|
||||
showCancel: true,
|
||||
buttonCancelText: "取消",
|
||||
cancelCallback: () => {
|
||||
|
||||
MsgClose(key, ev);
|
||||
},
|
||||
okCallback: function() {
|
||||
|
||||
MsgClear(ev);
|
||||
}
|
||||
|
||||
}, ev, false);
|
||||
}, 500);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//获取当前弹窗数量
|
||||
export const getPops = (ev) => {
|
||||
if (!ev) {
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!ev.$refs.msgPop) {
|
||||
|
||||
return null;
|
||||
}
|
||||
return ev.$refs.msgPop.getPops();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//清空所有弹窗
|
||||
export const MsgClear = (ev) => {
|
||||
if (!ev) {
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!ev.$refs.msgPop) {
|
||||
|
||||
return null;
|
||||
}
|
||||
return ev.$refs.msgPop.clearPops();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user