rt-sim-training-client/src/scripts/GlobalPlugin.js

117 lines
3.7 KiB
JavaScript
Raw Normal View History

2019-07-25 10:30:30 +08:00
import Vue from 'vue';
import QueryListPage from '@/components/QueryListPage/QueryListPage';
import DataForm from '@/components/QueryListPage/DataForm';
import TurnbackBar from '@/components/TurnbackBar';
import ConstConfig from '@/scripts/ConstConfig';
import Dictionary from '@/scripts/DictionaryData';
import Theme from '@/jmapNew/theme/factory';
2019-07-02 16:29:52 +08:00
// 全局组件
2019-07-25 10:30:30 +08:00
Vue.component('DataForm', DataForm);
Vue.component('QueryListPage', QueryListPage);
Vue.component('TurnbackBar', TurnbackBar);
2019-07-02 16:29:52 +08:00
Vue.prototype.$ConstSelect = (function() {
2019-11-18 12:28:08 +08:00
ConstConfig.ConstSelect.translate = function(value, codeName) {
if (codeName) {
const obj = this[codeName].filter(function(item) {
return item.value === value;
})[0];
return obj && obj.label;
}
};
return ConstConfig.ConstSelect;
2019-07-25 10:30:30 +08:00
})();
2019-07-02 16:29:52 +08:00
2019-07-25 10:30:30 +08:00
Vue.prototype.$Dictionary = Dictionary;
Vue.prototype.__windowResizeFlag = false;
2019-07-02 16:29:52 +08:00
Vue.prototype.$addWindowResizeListener = function(cb) {
2019-11-18 12:28:08 +08:00
window.addEventListener('resize', function() {
if (!Vue.__windowResizeFlag) {
Vue.__windowResizeFlag = true;
setTimeout(function() {
Vue.__windowResizeFlag = false;
cb();
}, 100);
}
});
2019-07-25 10:30:30 +08:00
};
Vue.prototype.$theme = new Theme();
2020-03-31 18:50:16 +08:00
Vue.prototype.$messageBox = function(msge, title, type) {
2019-11-18 12:28:08 +08:00
if (this.$confirm) {
2020-03-31 18:50:16 +08:00
this.$confirm(`${msge || this.$t('global.processFailure')}`, title || this.$t('global.tips'), {
2019-11-18 12:28:08 +08:00
confirmButtonText: this.$t('global.confirm'),
2020-03-31 18:50:16 +08:00
type: type || 'warning',
2019-11-18 12:28:08 +08:00
showCancelButton: false,
center: true
}).then(() => {
}).catch(() => {
});
}
};
Vue.prototype.$convertField = function(fieldValue, enumList, converFormat, isList = false) {
2019-11-18 12:28:08 +08:00
const arr = [];
if (enumList && converFormat && converFormat.length >= 2) {
const value = converFormat[0];
const label = converFormat[1];
if (isList) {
enumList.forEach((element, i) => {
fieldValue.forEach((v) => {
if (v == element[value]) {
arr.push(element[label]);
2019-11-18 12:28:08 +08:00
}
});
});
} else {
for (let i = 0; i < enumList.length; i++) {
if ('' + fieldValue == '' + enumList[i][value]) {
2019-11-18 12:28:08 +08:00
return enumList[i][label];
}
}
}
}
2019-11-18 12:28:08 +08:00
return isList ? arr : '';
};
2019-08-13 16:59:38 +08:00
Vue.prototype.$convertSpecifiedField = function(dataDict, enumList, key, value, fieldList) {
2019-11-18 12:28:08 +08:00
if (dataDict && enumList && fieldList && enumList.length && fieldList.length) {
fieldList.forEach(field => {
for (let i = 0; i < enumList.length; i++) {
if (enumList[i][key] === dataDict[field]) {
dataDict[field] = enumList[i][value];
return;
2019-11-18 12:28:08 +08:00
}
}
2019-11-18 12:28:08 +08:00
});
}
2019-10-22 13:41:23 +08:00
};
2019-08-13 16:59:38 +08:00
Vue.prototype.$convertList = function(FromList, ToList, checktypeFunction) {
2019-11-18 12:28:08 +08:00
if (FromList) {
ToList.length = 0;
FromList.forEach(elem => {
if (checktypeFunction(elem)) {
ToList.push({ value: elem.code, label: elem.name });
}
});
}
};
2020-04-17 13:30:58 +08:00
// 对象2 复制到 对象1上 并保留对象1原有字段
Vue.prototype.$copyClone = function(obj1, obj2 = {}) {
for (const keys in obj1) {
if (obj1.hasOwnProperty(keys)) {
if (obj1[keys] && typeof obj1[keys] === 'object') { // 如果值是对象,就递归一下
obj1[keys] = Vue.prototype.$copyClone(obj1[keys], obj2[keys]);
} else {
obj1[keys] = obj2[keys];
}
}
}
return obj1;
};