字典修复

lijinlong
许宏杰 2 years ago
parent be947dbf30
commit 978b480e35

@ -12,6 +12,7 @@ const dict = {
state: { state: {
dictObject: {}, dictObject: {},
townList: [], townList: [],
townList2: [],
}, },
mutations: { mutations: {
SET_DICT: (state, dict) => { SET_DICT: (state, dict) => {
@ -20,6 +21,9 @@ const dict = {
SET_TOWN: (state, town) => { SET_TOWN: (state, town) => {
state.townList = town; state.townList = town;
}, },
SET_TOWN2: (state, town) => {
state.townList2 = town;
},
}, },
actions: { actions: {
getDictType({ commit }) { getDictType({ commit }) {
@ -35,6 +39,10 @@ const dict = {
commit("SET_TOWN", town); commit("SET_TOWN", town);
resolve(); resolve();
}); });
// getownList2().then((town) => {
// commit("SET_TOWN2", town);
// resolve();
// });
}) })
.catch((error) => { .catch((error) => {
reject(error); reject(error);
@ -56,4 +64,19 @@ function getownList() {
}); });
}); });
} }
function getownList2() {
return new Promise((resolve, reject) => {
const lsit = [];
listTown({ pageNum: 1, pageSize: 200 })
.then((res) => {
res.rows.forEach((item) => {
lsit.push({ value: item.id, label: item.name });
});
resolve(lsit);
})
.catch((error) => {
reject(error);
});
});
}
export default dict; export default dict;

@ -3,7 +3,13 @@ import store from "@/store";
export function filterDict(type, value, isTown = false) { export function filterDict(type, value, isTown = false) {
if (!value) return; if (!value) return;
if (isTown) { if (isTown) {
return filterTown(value); let ids = JSON.parse(value);
if (Array.isArray(ids)) {
return filterTown(ids);
} else {
// return filterTowns(ids);
return filterTown([ids]);
}
} else { } else {
const dict = store.getters.dictObject; const dict = store.getters.dictObject;
const result = dict[type].filter((item) => item.dictValue == value); const result = dict[type].filter((item) => item.dictValue == value);
@ -15,18 +21,17 @@ export function filterDict(type, value, isTown = false) {
} }
} }
// export function filterTown(id) { // export function filterTowns(id) {
// const townList = store.state.dict.townList // const townList = store.state.dict.townList2;
// const result = townList.filter((item) => item.value == id) // const result = townList.filter((item) => item.value == id);
// if (result.length > 0) { // if (result.length > 0) {
// return result[0].label // return result[0].label;
// } else { // } else {
// return '未匹配到' // return "未匹配到";
// } // }
// } // }
function filterTown(ids) { function filterTown(ids) {
ids = JSON.parse(ids);
if (ids && Array.isArray(ids)) { if (ids && Array.isArray(ids)) {
let data = store.state.dict.townList; let data = store.state.dict.townList;
const targetIds = ids; const targetIds = ids;

Loading…
Cancel
Save