菜单管理接入接口

This commit is contained in:
2023-02-08 23:19:02 +08:00
parent 05b5b2ccc3
commit 0655e21a7d
2 changed files with 11 additions and 5 deletions

View File

@@ -33,8 +33,7 @@ export default {
data() { data() {
return { return {
CirclePlus, CirclePlus,
search: {name: ""}, search: {name: null},
page: {current: 1},
tableData: [ tableData: [
{ {
id: 1, menuName: "测试", type: "菜单", status: 1, showIndex: 1, id: 1, menuName: "测试", type: "菜单", status: 1, showIndex: 1,
@@ -55,7 +54,13 @@ export default {
}, },
methods: { methods: {
getTableData() { 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) { handleDelete(row) {

View File

@@ -10,12 +10,13 @@ export const $confirm = () => {
* @param config 配置 * @param config 配置
*/ */
const $arr2tree = (list, 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) { for (const e of list) {
const id = e[key], pid = e[parent] const id = e[key], pid = e[parent]
itemMap[id] = {...e, [children]: [itemMap[id]?.[children]].flat().filter(Boolean)} itemMap[id] = {...e, [children]: [itemMap[id]?.[children]].flat().filter(Boolean)}
const treeItem = itemMap[id] const treeItem = itemMap[id]
if (!!pid && ids.indexOf(pid) > -1) { if (!!pid && ids.indexOf(`#${pid}#`) > -1) {
if (!itemMap[pid]) { if (!itemMap[pid]) {
itemMap[pid] = { itemMap[pid] = {
children: [], children: [],