From 0655e21a7d7b648c41645c5ae4e5a49483020d1b Mon Sep 17 00:00:00 2001 From: kubbo <390378816@qq.com> Date: Wed, 8 Feb 2023 23:19:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=AE=A1=E7=90=86=E6=8E=A5?= =?UTF-8?q?=E5=85=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/apps/AppMenu.vue | 11 ++++++++--- web/src/utils/tools.js | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) 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: [],