diff --git a/web/src/apps/AppMenu.vue b/web/src/apps/AppMenu.vue index f27e835..4027b70 100644 --- a/web/src/apps/AppMenu.vue +++ b/web/src/apps/AppMenu.vue @@ -33,8 +33,7 @@ export default { data() { return { CirclePlus, - search: {name: ""}, - page: {current: 1}, + search: {name: null}, tableData: [ { id: 1, menuName: "测试", type: "菜单", status: 1, showIndex: 1, @@ -55,7 +54,13 @@ export default { }, methods: { getTableData() { - + this.$http.post("/api/menu/list", null, { + params: {...this.search, size: 9999} + }).then(res => { + if (res?.data) { + this.tableData = this.$arr2tree(res.data.records, {parent: 'parent'}) + } + }) }, handleDelete(row) { diff --git a/web/src/utils/tools.js b/web/src/utils/tools.js index 0bbf401..b8473a6 100644 --- a/web/src/utils/tools.js +++ b/web/src/utils/tools.js @@ -10,12 +10,13 @@ export const $confirm = () => { * @param config 配置 */ const $arr2tree = (list, config = {}) => { - const {key = 'id', parent = 'parentId', children = 'children'} = config, result = [], itemMap = {}, ids = list?.map(e => `${e[key]}`)?.toString() + 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 (!!pid && ids.indexOf(`#${pid}#`) > -1) { if (!itemMap[pid]) { itemMap[pid] = { children: [],