getSceneData() {
Api.get('/security/category/all')
.then(res => {
const list = res.data || []
this.treeData = scene.parseTreeData(list)
})
.finally(() => {
})
}
function parseTreeData(list) { if (!Array.isArray(list)) return [] const indexMap = {} const result = list.filter(o => o.parentId === 0).map((o, i) => { indexMap[`${o.id}`] = i return { text: o.categoryName, value: o.id, categoryName: o.categoryName, parentId: o.parentId, children: [] } }) list.filter(o => o.parentId !== 0).forEach(o => { const i = indexMap[`${o.parentId}`] if (o.id === this.initValue) { if (o.parentId === 0) { this.securityValues = [o.id] return } else { this.securityValues = [o.parentId, o.id] return } } result[i].children.push({ text: o.categoryName, value: o.id, categoryName: o.categoryName, parentId: o.parentId }) }) return result } export default{ parseTreeData }