金五联管理系统PC前端
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.
jwl-manage-web/src/components/DictData/index.js

54 lines
1.2 KiB

2 years ago
import Vue from 'vue';
import store from '@/store';
import DataDict from '@/utils/dict';
import { getDicts as getDicts } from '@/api/system/dict/data';
3 years ago
function searchDictByKey(dict, key) {
2 years ago
if (key == null && key == '') {
return null;
3 years ago
}
try {
for (let i = 0; i < dict.length; i++) {
if (dict[i].key == key) {
2 years ago
return dict[i].value;
3 years ago
}
}
} catch (e) {
2 years ago
return null;
3 years ago
}
}
function install() {
Vue.use(DataDict, {
metas: {
'*': {
labelField: 'dictLabel',
valueField: 'dictValue',
request(dictMeta) {
2 years ago
const storeDict = searchDictByKey(store.getters.dict, dictMeta.type);
3 years ago
if (storeDict) {
2 years ago
return new Promise((resolve) => {
resolve(storeDict);
});
3 years ago
} else {
return new Promise((resolve, reject) => {
2 years ago
getDicts(dictMeta.type)
.then((res) => {
store.dispatch('dict/setDict', { key: dictMeta.type, value: res.data });
resolve(res.data);
})
.catch((error) => {
reject(error);
});
});
3 years ago
}
2 years ago
}
}
}
});
3 years ago
}
export default {
2 years ago
install
};