系统菜单先提交

This commit is contained in:
aixianling
2023-01-28 18:08:41 +08:00
parent bbd72b7330
commit 61fe27dfde
5 changed files with 99 additions and 8 deletions

View File

@@ -3,7 +3,29 @@ import {mainStore} from "./store";
export const getToken = () => mainStore()?.token
export const $confirm = () => {
}
/**
* 数组转tree
* @param list 待转化的数组
* @param config 配置
*/
const $arr2tree = (list, config = {}) => {
const {key = 'id', parent = 'parentId', children = 'children'} = config, result = [], itemMap = {}, ids = list?.map(e => `${e[key]}`)?.toString()
for (const e of list) {
const id = e[key], pid = e[parent]
itemMap[id] = {...e, [children]: [itemMap[id]?.[children]].flat().filter(Boolean)}
const treeItem = itemMap[id]
if (!!pid && ids.indexOf(pid) > -1) {
if (!itemMap[pid]) {
itemMap[pid] = {
children: [],
}
}
itemMap[pid].children.push(treeItem)
} else result.push(treeItem)
}
return result
}
export default {
getToken, $confirm
}
getToken, $confirm, $arr2tree
}