efview
Version:
A high quality Service UI components Library with Vue.js
293 lines (289 loc) • 11.9 kB
JavaScript
export default {
name:'uibase',
data() {
return {
uiconfigpro:{
classPrefix:'',
resources:'',
response:'',
layoutType:'',
billisworkflow:'',
billwfstartflag:''
},
fariyconfigpro:{
method:'',
fairyType:'',
resources:'',
response:''
},
billisworkflow:'N',
dictkey:[],
dictgroupkey:[],
selectkey:[],
globaluiproperty:{}
};
},
methods:{
getFairyConfig(selectkey, result) {
if (result == undefined) {
result = {};
}
let data = this.$Method.getLocalStorage('fairyConfig_' + selectkey);
if (data) {
this.doFairyConfig(data, result);
} else {
let para = {};
para.selectkey = selectkey;
let self = this;
self.synchroPost(self.OmdUrl.uidespath, 'usercenter.fairyconfig.getFairyConfig', para, function (response) {
self.$Method.setLocalStorage('fairyConfig_' + selectkey , response, self.OmdUrl.fairyConfigExpire);
self.doFairyConfig(response,result);
});
}
let temp = [];
if (this.selectkey.length > 0) {
this.selectkey.forEach(el => {
if (result[el] === undefined) {
if (typeof selectkey !== 'string') {
let tempFlag = true;
selectkey.some(el2 => {
if (el === el2) {
tempFlag = false;
return true;
}
});
if (tempFlag) {
temp.push(el);
}
} else {
if (el !== selectkey) {
temp.push(el);
}
}
}
});
}
if (temp.length > 0) {
return this.getFairyConfig(temp,result);
} else {
return result;
}
},
doFairyConfig (data,result) {
for (let pro in data) {
if (JSON.stringify(data[pro]) !== '{}') {
result[pro] = this.createUiConfig(data[pro], this.fariyconfigpro,'fairyconfig');
if (result[pro].fairyType === 'PopTreeBox') {
result[pro].isTree = true;
}
result[pro].isConfig = true;
}
}
},
getUiCongfig (moduleCode) {
let result = {};
let data = this.$Method.getLocalStorage('uiConfig_' + moduleCode);
if (data) {
result = this.doUiCongfig(data);
} else {
let para = {};
para.moduleCode = moduleCode;
let self = this;
self.synchroPost(self.OmdUrl.uidespath, 'usercenter.uiconfig.getUiConfig', para, function (response) {
self.$Method.setLocalStorage('uiConfig_' + moduleCode , response, self.OmdUrl.uiConfigExpire);
result = self.doUiCongfig(response);
});
}
return result;
},
doUiCongfig (data) {
this.setGlobaluiProperty(data.globaluiproperty);
return this.createUiConfig(data,this.uiconfigpro,'uiconfig');
},
setGlobaluiProperty (data) {
this.globaluiproperty = {};
if (data && data.length > 0) {
data.forEach(el => {
if (el.propertyName) {
let list = el.propertyName.split('_');
if (list.length > 1) {
if (this.globaluiproperty[list[0]] === undefined) {
this.globaluiproperty[list[0]] = {};
}
let value = el.propertyValue;
let type = Number(el.propertyType);
if (type === 2) {
value = Number(value);
}
if (type === 3) {
value = value === 'Y';
}
if (type === 4) {
value = JSON.parse(value);
}
this.globaluiproperty[list[0]][list[1]] = value;
}
}
});
}
},
createUiConfig (info, uiconfigpro,name) {
let config = {};
for (let pro in uiconfigpro) {
config[pro] = info[name][0][pro];
}
if (config.billisworkflow) {
this.billisworkflow = config.billisworkflow;
}
let index = info.uiclass.findIndex(el => el.itemClass === 1);
if (index > -1) {
Object.assign(config, this.getUiItemPro(info.uiproperty, info.uiclass[index].itemId, info.uiclass[index].itemType));
if (name === 'fairyconfig') {
if (config.title === undefined) {
config.title = info[name][0]['fairyName'];
}
}
this.doCommonUiConfig(info,config,info.uiclass[index]);
}
return config;
},
doCommonUiConfig(info, config, obj, flag) {
Object.assign(config, this.getUiItemPro(info.uiproperty, obj.itemId, obj.itemType));
this.doItemPro(config,obj,flag);
let items = this.getUiItems(info.uiclass, obj.itemId);
if (items.length > 0) {
if (this.checkItemType(obj)) {
if (obj.itemType != 'titleItems') {
config.items = [];
} else {
config.label = obj.itemName;
config.children = [];
}
items.forEach(el => {
let temp = {};
this.doCommonUiConfig(info, temp, el);
if (obj.itemType != 'titleItems') {
config.items.push(temp);
} else {
if (temp.width === undefined) {
temp.width = 100;
}
config.children.push(temp);
}
});
} else {
items.forEach(el => {
let temp = {};
this.doCommonUiConfig(info, temp, el);
if (this.checkItemType(el)) {
Object.assign(config, temp);
} else {
config[el.itemCode] = temp;
}
});
}
} else {
if (obj.itemType !== 'Occupancy' && obj.itemType !== 'GridOccupancy') {
if (obj.itemType === 'button') {
config.name = obj.itemCode;
config.text = obj.itemName;
} else {
config.name = obj.itemCode;
config.label = obj.itemName;
config.type = obj.itemType;
}
} else {
if (obj.itemType === 'GridOccupancy') {
config.label = ' ';
}
}
}
},
checkItemType (obj) {
if (obj.itemType === 'formItems' ||
obj.itemType === 'gridItems' ||
obj.itemType === 'conditionItems' ||
obj.itemType === 'titleItems' ||
obj.itemType === 'formboxItems' ||
obj.itemType === 'gridboxItems' ||
obj.itemType === 'buttonItems') {
return true;
} else {
return false;
}
},
doItemPro (config, obj) {
if (obj.itemType === 'FormCardGroupBox' || obj.itemType === 'EditGridCard' || obj.itemType === 'DetailsBox' || obj.itemType === 'FormCardBox' || obj.itemType === 'AppendixBox') {
config.type = obj.itemType;
if (config.title === undefined) {
if (obj.itemName) {
config.title = obj.itemName;
}
}
config.name = obj.itemCode;
}
},
getUiItems (data, itemId) {
let result = [];
data.forEach(el => {
if (el.pItemId === itemId) {
result.push(el);
}
});
result.sort((a, b) => a.sort - b.sort);
return result;
},
getUiItemPro (data, itemId, itemType) {
let obj = {};
let self = this;
data.forEach(el => {
if (el.itemId === itemId) {
let value = el.propertyValue;
let type = Number(el.propertyType);
if (type === 2) {
value = Number(value);
}
if (type === 3) {
value = value === 'Y';
}
if (type === 4) {
value = JSON.parse(value);
}
if (type === 5) {
if (self[value]) {
obj[el.propertyName] = self[value];
}
} else {
if (el.propertyName === 'dictkey') {
let index = self.dictkey.findIndex(el => el === value);
if (index === -1) {
self.dictkey.push(value);
}
}
obj[el.propertyName] = value;
}
if (el.propertyName === 'selectkey') {
obj.getDictData = self.getDictData;
let index2 = self.selectkey.findIndex(el => el === value);
if (index2 === -1) {
self.selectkey.push(value);
}
}
}
});
if (obj.workflow === 'Y' && this.billisworkflow){
if (this.billisworkflow.startsWith('Y')) {
if (obj.dictgroupkey) {
if (obj.dictgroupkey.indexOf('BPM') === -1) {
obj.dictgroupkey = obj.dictgroupkey +',BPM';
}
}
}
}
if (itemType && this.globaluiproperty[itemType]) {
obj = Object.assign({},this.globaluiproperty[itemType], obj);
}
return obj;
},
}
};