From fc017033910bcac63e58eeb88fd36f72edc38ce3 Mon Sep 17 00:00:00 2001 From: aguoxing <2933575030@qq.com> Date: Mon, 13 Dec 2021 11:07:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysMenuController.java | 14 ++ .../ruoyi/system/service/ISysMenuService.java | 9 ++ .../service/impl/SysMenuServiceImpl.java | 54 ++++++++ .../resources/mapper/system/SysMenuMapper.xml | 6 + ruoyi-ui/src/api/system/menu.js | 129 ++++++++++-------- ruoyi-ui/src/views/system/menu/index.vue | 20 ++- 6 files changed, 168 insertions(+), 64 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java index 9ab14d2ab..944cf6f00 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java @@ -1,6 +1,8 @@ package com.ruoyi.web.controller.system; import java.util.List; + +import com.ruoyi.common.core.page.TableDataInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; @@ -44,6 +46,18 @@ public class SysMenuController extends BaseController return AjaxResult.success(menus); } + /** + * 分页获取菜单列表 + */ + @PreAuthorize("@ss.hasPermi('system:menu:list')") + @GetMapping("/listTreeByPage") + public TableDataInfo listTreeByPage(SysMenu menu) + { + startPage(); + List menus = menuService.selectTreeByPage(menu, getUserId()); + return getDataTable(menus); + } + /** * 根据菜单编号获取详细信息 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java index 59009be01..2f54bd41f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java @@ -133,4 +133,13 @@ public interface ISysMenuService * @return 结果 */ public String checkMenuNameUnique(SysMenu menu); + + /** + * 分页查询菜单树 + * + * @param menu + * @param userId + * @return + */ + public List selectTreeByPage(SysMenu menu, Long userId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index d113cfe0e..e386e3c17 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -79,6 +79,60 @@ public class SysMenuServiceImpl implements ISysMenuService return menuList; } + /** + * 分页查询菜单树 + * + * @param menu + * @param userId + * @return + */ + @Override + public List selectTreeByPage(SysMenu menu, Long userId) + { + List menuList = null; + menu.setParentId(0L); + + // 管理员显示所有菜单信息 + if (SysUser.isAdmin(userId)) { + menuList = menuMapper.selectMenuList(menu); + } + else + { + menu.getParams().put("userId", userId); + menuList = menuMapper.selectMenuListByUserId(menu); + } + return findChildren(menuList, userId); + } + + public List findChildren(List sysMenuList, Long userId) + { + List children = null; + SysMenu menu = new SysMenu(); + + for (SysMenu sysMenu : sysMenuList) + { + menu.setParentId(sysMenu.getMenuId()); + + // 管理员显示所有菜单信息 + if (SysUser.isAdmin(userId)) + { + children = menuMapper.selectMenuList(menu); + } + else + { + menu.getParams().put("userId", userId); + children = menuMapper.selectMenuListByUserId(menu); + } + + if (StringUtils.isNotNull(children) && children.size() > 0) + { + findChildren(children, userId); + sysMenu.setChildren(children); + } + } + return sysMenuList; + } + /** * 根据用户ID查询权限 * diff --git a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index 144adb1b9..73cfea258 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -35,6 +35,9 @@