前端菜单加载优化

This commit is contained in:
不做码农 2022-05-25 08:21:43 +08:00
parent ae3cd6899e
commit bdf46a6036
2 changed files with 25 additions and 6 deletions

View File

@ -8,7 +8,13 @@ export function listMenu(query) {
params: query params: query
}) })
} }
// 查询菜单列表
export function listMenuById(menuId) {
return request({
url: '/system/menu/list/' + menuId,
method: 'get',
})
}
// 查询菜单详细 // 查询菜单详细
export function getMenu(menuId) { export function getMenu(menuId) {
return request({ return request({
@ -75,4 +81,4 @@ export const getRouters = (query) => {
method: 'get', method: 'get',
params: query params: query
}) })
} }

View File

@ -25,7 +25,11 @@
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
<el-table v-if="refreshTable" v-loading="loading" :data="menuList" :default-expand-all="isExpandAll" row-key="menuId" border <el-table v-if="refreshTable" v-loading="loading" :data="menuList" :default-expand-all="isExpandAll"
row-key="menuId"
border
lazy
:load="loadMenu"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"> :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
<el-table-column prop="menuName" label="菜单名称" :show-overflow-tooltip="true" width="160"></el-table-column> <el-table-column prop="menuName" label="菜单名称" :show-overflow-tooltip="true" width="160"></el-table-column>
<el-table-column prop="icon" label="图标" align="center" width="80"> <el-table-column prop="icon" label="图标" align="center" width="80">
@ -217,6 +221,7 @@ import {
addMenu, addMenu,
changeMenuSort, changeMenuSort,
updateMenu, updateMenu,
listMenuById
} from "@/api/system/menu"; } from "@/api/system/menu";
import Treeselect from "@riophae/vue-treeselect"; import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css"; import "@riophae/vue-treeselect/dist/vue-treeselect.css";
@ -228,7 +233,7 @@ export default {
data() { data() {
return { return {
// //
loading: true, loading: false,
// //
showSearch: true, showSearch: true,
// //
@ -274,13 +279,16 @@ export default {
}; };
}, },
created() { created() {
this.getList(); // this.getList();
this.getDicts("sys_show_hide").then((response) => { this.getDicts("sys_show_hide").then((response) => {
this.visibleOptions = response.data; this.visibleOptions = response.data;
}); });
this.getDicts("sys_normal_disable").then((response) => { this.getDicts("sys_normal_disable").then((response) => {
this.statusOptions = response.data; this.statusOptions = response.data;
}); });
listMenuById(0).then((response) => {
this.menuList = response.data
})
}, },
methods: { methods: {
// //
@ -309,7 +317,7 @@ export default {
}, },
/** 查询菜单下拉树结构 */ /** 查询菜单下拉树结构 */
getTreeselect() { getTreeselect() {
listMenu().then((response) => { listMenu({ menuTypeIds: 'M,C,F' }).then((response) => {
this.menuOptions = []; this.menuOptions = [];
const menu = { menuId: 0, menuName: "根菜单", children: [] }; const menu = { menuId: 0, menuName: "根菜单", children: [] };
menu.children = response.data; menu.children = response.data;
@ -453,6 +461,11 @@ export default {
this.refreshTable = true; this.refreshTable = true;
}); });
}, },
loadMenu (row, treeNode, resolve) {
listMenuById(row.menuId).then((res) => {
resolve(res.data)
})
}
}, },
}; };
</script> </script>