11
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
import areaData from '@/untils/area';
|
||||
|
||||
function format(data) {
|
||||
const result = [];
|
||||
const children = {};
|
||||
const dic = {
|
||||
'0': {
|
||||
label: 'root',
|
||||
value: '0',
|
||||
children: result
|
||||
}
|
||||
};
|
||||
|
||||
data.forEach(item => {
|
||||
if (item.layer > 3) {
|
||||
return;
|
||||
}
|
||||
const node = {
|
||||
label: item.areaName,
|
||||
value: item.areaId,
|
||||
quickQuery: item.quickQuery,
|
||||
simpleSpelling: item.simpleSpelling,
|
||||
parentId: item.parentId
|
||||
};
|
||||
if (children.hasOwnProperty(item.parentId)) {
|
||||
children[item.parentId].push(node);
|
||||
} else {
|
||||
children[item.parentId] = [node];
|
||||
}
|
||||
if (dic.hasOwnProperty(item.areaId)) {
|
||||
dic[item.areaId].label = item.areaName;
|
||||
dic[item.areaId].value = item.areaId;
|
||||
} else {
|
||||
dic[item.areaId] = node;
|
||||
}
|
||||
});
|
||||
return {
|
||||
data: result,
|
||||
children,
|
||||
dic
|
||||
};
|
||||
}
|
||||
|
||||
let loaded = false
|
||||
|
||||
const data = format(areaData)
|
||||
const area = {
|
||||
state: {
|
||||
...data
|
||||
},
|
||||
actions: {},
|
||||
mutations: {
|
||||
SET_AREA: (state, data) => {
|
||||
state.data = data.data
|
||||
state.dic = data.dic
|
||||
},
|
||||
},
|
||||
getters: {
|
||||
getAreaParents: (state) => (id) => {
|
||||
const res = [];
|
||||
let item = state.dic[id];
|
||||
while (item && item.value !== '0') {
|
||||
id = item.parentId;
|
||||
res.unshift(item);
|
||||
item = state.dic[id];
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default area;
|
||||
Reference in New Issue
Block a user