cdt-cli
Version:
A simple CLI for creating your projects
212 lines (200 loc) • 5.2 kB
JavaScript
import { Message, MessageBox } from "element-ui";
import store from "../store";
var GLOBAL_DELAY_FLAG = true // 全局变量
export default {
/**
* 判断返回的状态码是否是200
* @param {*} res 返回的参数
* @param {*} successMsg 成功提示语
* @param {*} successCallBack 是200的回调函数
* @param {*} errorCallBack 失败的回调函数
*/
CheckCode(res, successMsg, successCallBack, errorCallBack) {
if (res && res.code == 200) {
if (successMsg) {
Message({
message: successMsg,
type: "success",
});
}
successCallBack();
} else {
res.msg && Message({
message: res.msg,
type: "error",
duration: 1500
});
errorCallBack && errorCallBack()
}
},
/**
* 操作提示
* @Function {*} successCallBack 确认后回调函数
* @String {*} title 提示语
*/
handleConfirm(successCallBack, title) {
MessageBox.confirm(title || "此操作将永久删除该数据, 是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
successCallBack();
})
.catch(() => {
Message({
type: "info",
message: "已取消"
});
});
},
/**
* 根据 dmlb 或者 lbmc 获取数据字典
* @param {*} key
*/
getDic(key) {
let list = [];
if (key) {
if (store.state.dicList) {
store.state.dicList.forEach((item, index) => {
if (item.dmlb == key || item.lbmc == key) {
if (key == 'QYBAZLLB' || key == 'RJBAZLLB') {
item.xjsj.forEach(item2 => {
list.push({
cllx: item2.dmbh,
wjmc: item2.dmmc,
plsx: item2.plsx,
jllx: item2.jllx,
dmlb: item2.dmlb,
});
})
} else if (key == 'FZJG') {
item.xjsj.forEach(item2 => {
list.push({
value: item2.dmmc,
label: item2.dmmc,
plsx: item2.plsx,
jllx: item2.jllx,
dmlb: item2.dmlb
});
})
} else if (key == 'mon_supervise_yjxtlb') {
item.xjsj.forEach(item2 => {
list.push({
value: item2.dmbh,
label: item2.dmmc,
plsx: item2.plsx,
jllx: item2.jllx,
dmlb: item2.dmlb,
icon: item2.bz
});
})
} else {
item.xjsj.forEach(item2 => {
list.push({
value: item2.dmbh,
label: item2.dmmc,
plsx: item2.plsx,
jllx: item2.jllx,
dmlb: item2.dmlb
});
});
}
}
});
} else {
this.getDic(key);
}
}
if (key == 'mon_supervise_yjxtlb') {
let arr = []
list.sort(this.compare("plsx")).forEach((item, index) => {
if (store.state.userInfo.userExpForm.yhlx.indexOf(item.value) != -1) {
arr.push(item)
}
})
return arr
} else {
return list.sort(this.compare("plsx"));
}
},
/**
* 根据数据字典类别和数据值翻译对应的中文
* @param {*} zdlb
* @param {*} val
*/
FormatDic(zdlb, val) {
let arr = this.getDic(zdlb)
let label = "";
arr.forEach(item => {
if (item.value == val) {
label = item.label;
}
});
return label || '暂无';
},
/**
* 根据参数名 获取store里面的state对应的参数名的值
* @param {*} state
*/
getStoreState (modules, state) {
if (store.state[modules]) {
if (store.state[modules].hasOwnProperty(state)) {
if (store.state[modules][state]) {
return store.state[modules][state]
} else {
this.getStoreState(modules, state)
}
}
}
},
/**
* 根据数组中对象的某一个属性值进行排序
* 用法 arr.sort(compare('age'))
* @param {*} key
*/
compare(key) {
return function(a, b) {
let value1 = a[key];
let value2 = b[key];
return value1 - value2;
};
},
/**
* 根据glbm代码转中文
*/
FormatGlbm(dwdm) {
return store.state.config.glbmDwdm[dwdm] || dwdm
},
/**
* 格式化时间
* @param {*} val - 时间戳
*/
FormatDate(val) {
return new Date(val).format("yyyy-MM-dd hh:mm:ss");
},
/**
* 深度克隆
* @param {*} obj
*/
DeepClone (obj) {
let _tmp, result
_tmp = JSON.stringify(obj)
result = JSON.parse(_tmp)
return result
},
/**
* 延迟调用
* @param {*} callback - 需要调用的方法
* @param {*} time - 延迟的实际,默认300毫秒
*/
DelayCall (callback, time) {
if (GLOBAL_DELAY_FLAG) {
GLOBAL_DELAY_FLAG = false
callback()
setTimeout(() => {
GLOBAL_DELAY_FLAG = true
}, time || 500)
}
}
};