Commit 42e2fa95 authored by 水落(YangLei)'s avatar 水落(YangLei)

feat: 菜单管理优化

parent 3133e0a0
...@@ -47,25 +47,66 @@ import { request, METHOD } from '@/utils/requestUtil'; ...@@ -47,25 +47,66 @@ import { request, METHOD } from '@/utils/requestUtil';
const data = [ const data = [
{ {
key: '1', key: 1,
name: 'John Brown', name: 'John Brown sr.',
age: 32, age: 60,
address: 'New York No. 1 Lake Park', address: 'New York No. 1 Lake Park',
tags: ['nice', 'developer'], children: [
{
key: 11,
name: 'John Brown',
age: 42,
address: 'New York No. 2 Lake Park',
}, },
{ {
key: '2', key: 12,
name: 'John Brown jr.',
age: 30,
address: 'New York No. 3 Lake Park',
children: [
{
key: 121,
name: 'Jimmy Brown',
age: 16,
address: 'New York No. 3 Lake Park',
},
],
},
{
key: 13,
name: 'Jim Green sr.',
age: 72,
address: 'London No. 1 Lake Park',
children: [
{
key: 131,
name: 'Jim Green', name: 'Jim Green',
age: 42, age: 42,
address: 'London No. 1 Lake Park', address: 'London No. 2 Lake Park',
tags: ['loser'], children: [
{
key: 1311,
name: 'Jim Green jr.',
age: 25,
address: 'London No. 3 Lake Park',
},
{
key: 1312,
name: 'Jimmy Green sr.',
age: 18,
address: 'London No. 4 Lake Park',
},
],
},
],
},
],
}, },
{ {
key: '3', key: 2,
name: 'Joe Black', name: 'Joe Black',
age: 32, age: 32,
address: 'Sidney No. 1 Lake Park', address: 'Sidney No. 1 Lake Park',
tags: ['cool', 'teacher'],
}, },
]; ];
...@@ -79,6 +120,7 @@ export default { ...@@ -79,6 +120,7 @@ export default {
addBtn: { addBtn: {
type: Object, type: Object,
}, },
formatData: Function,
}, },
data() { data() {
return { return {
...@@ -89,19 +131,21 @@ export default { ...@@ -89,19 +131,21 @@ export default {
}; };
}, },
mounted() { mounted() {
console.log(this.addBtn);
this.getData(); this.getData();
}, },
methods: { methods: {
async getData() { async getData() {
console.log('查询');
this.loading = true; this.loading = true;
setTimeout(() => { try {
this.data = data;
this.loading = false;
}, 1000);
const res = await request(this.url, METHOD.GET); const res = await request(this.url, METHOD.GET);
console.log(res); if (this.formatData) this.data = this.formatData(res);
else this.data = res;
} catch (error) {
// todo
}
this.loading = false;
}, },
add() { add() {
this.addVisible = true; this.addVisible = true;
......
<template> <template>
<my-table url="/api/v1/menus" addBtn="addBtn"> <my-table url="/api/v1/menus" :addBtn="addBtn" :formatData="formatData" rowKey="menuId">
<template #search="{query}"> <template #search="{query}">
<a-form-model-item label="菜单、目录名称"> <a-form-model-item label="菜单、目录名称">
<a-input v-model="query.name" /> <a-input v-model="query.name" />
...@@ -8,13 +8,17 @@ ...@@ -8,13 +8,17 @@
<template #add> <template #add>
<a-input v-model="add.name" /> <a-input v-model="add.name" />
</template> </template>
<a-table-column title="姓名" data-index="name" /> <a-table-column title="名称" data-index="menuName" />
<a-table-column title="类型" data-index="menuTypeName" />
<a-table-column title="显示排序" data-index="viewIndex" :sorter="sorter" sortOrder="ascend" />
<a-table-column title="显示图标" data-index="menuIcon" />
<a-table-column title="模块URL" data-index="menuUrl" />
<a-table-column title="操作"> <a-table-column title="操作">
<template #default="row"> <template #default>
<span> <span>
<a> {{ row }}</a> <a>编辑</a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<a>Delete</a> <a>删除</a>
</span> </span>
</template> </template>
</a-table-column> </a-table-column>
...@@ -26,6 +30,31 @@ export default { ...@@ -26,6 +30,31 @@ export default {
data: () => ({ data: () => ({
add: {}, add: {},
addBtn: { text: '新建', title: '菜单配置' }, addBtn: { text: '新建', title: '菜单配置' },
sortOrder: 'ascend',
}), }),
methods: {
formatData(data = []) {
let menu,
res = [],
tmp = data.slice();
while ((menu = tmp.pop())) {
if (menu.parentMenuId === 0) res.push(menu);
else {
for (const resetMenu of data) {
if (menu.parentMenuId === resetMenu.menuId) {
resetMenu.children
? resetMenu.children.push(menu)
: (resetMenu.children = [menu]);
}
}
}
}
console.log(res);
return res;
},
sorter(pre, next) {
return pre.viewIndex - next.viewIndex;
},
},
}; };
</script> </script>
...@@ -17,7 +17,6 @@ axios.defaults.xsrfCookieName = xsrfHeaderName; ...@@ -17,7 +17,6 @@ axios.defaults.xsrfCookieName = xsrfHeaderName;
function loadResponseInterceptor({ router }) { function loadResponseInterceptor({ router }) {
axios.interceptors.request.use( axios.interceptors.request.use(
function(config) { function(config) {
console.log(getToken(), config);
// 在发送请求之前做些什么 // 在发送请求之前做些什么
config.headers = { config.headers = {
...config.headers, ...config.headers,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment