parent
07692aa995
commit
be947dbf30
@ -1,26 +1,49 @@
|
|||||||
import store from '@/store'
|
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)
|
return filterTown(value);
|
||||||
} 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);
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
return result[0].dictLabel
|
return result[0].dictLabel;
|
||||||
} else {
|
} else {
|
||||||
return '未匹配到'
|
return "未匹配到";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function filterTown(id) {
|
// export function filterTown(id) {
|
||||||
const townList = store.state.dict.townList
|
// const townList = store.state.dict.townList
|
||||||
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) {
|
||||||
|
ids = JSON.parse(ids);
|
||||||
|
if (ids && Array.isArray(ids)) {
|
||||||
|
let data = store.state.dict.townList;
|
||||||
|
const targetIds = ids;
|
||||||
|
const results = [];
|
||||||
|
filterNames(data, targetIds, results);
|
||||||
|
return results.join(" / ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterNames(data, targetIds, results) {
|
||||||
|
data.forEach((node, index) => {
|
||||||
|
if (targetIds.includes(node.id)) {
|
||||||
|
results.push(node.label);
|
||||||
|
}
|
||||||
|
const children = node.children;
|
||||||
|
if (Array.isArray(children) && children.length > 0) {
|
||||||
|
filterNames(children, targetIds, results);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue