From 36f2d2d37a10b6a138d23d138c9bbf6168f5cd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Wed, 5 Jun 2024 11:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=9D=83=E9=99=90=20getRoute?= =?UTF-8?q?rs/(1=E6=98=AF=E5=89=8D=E7=AB=AF=EF=BC=8C0=E5=90=8E=E5=8F=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysLoginController.java | 17 ++++++++--------- .../controller/system/SysMenuController.java | 7 ++++--- .../ruoyi/system/mapper/SysMenuMapper.java | 5 +++-- .../ruoyi/system/service/ISysMenuService.java | 3 ++- .../service/impl/SysMenuServiceImpl.java | 19 +++++++++++++++---- .../resources/mapper/system/SysMenuMapper.xml | 11 ++++++++--- ruoyi-ui/src/api/menu.js | 4 ++-- ruoyi-ui/src/api/system/menu.js | 4 ++-- ruoyi-ui/src/store/modules/permission.js | 2 +- 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index 9194b975..0215b5d1 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -1,24 +1,23 @@ package com.ruoyi.web.controller.system; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginBody; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.framework.web.service.SysLoginService; import com.ruoyi.framework.web.service.SysPermissionService; import com.ruoyi.system.service.ISysMenuService; import com.zc.websocket.WebSocketConfigParam; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Set; +import java.util.*; /** * 登录验证 @@ -97,11 +96,11 @@ public class SysLoginController * * @return 路由信息 */ - @GetMapping("getRouters") - public AjaxResult getRouters() + @GetMapping("getRouters/{distinguish}") + public AjaxResult getRouters(@PathVariable Long distinguish) { Long userId = SecurityUtils.getUserId(); - List menus = menuService.selectMenuTreeByUserId(userId); + List menus = menuService.selectMenuTreeByUserId(userId,distinguish); return AjaxResult.success(menuService.buildMenus(menus)); } } 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 e9e349b7..e8b34613 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 @@ -67,10 +67,11 @@ public class SysMenuController extends BaseController /** * 加载对应角色菜单列表树 */ - @GetMapping(value = "/roleMenuTreeselect/{roleId}") - public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) + @GetMapping(value = "/roleMenuTreeselect/{roleId}/{distinguish}") + public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId,@PathVariable("distinguish") Long distinguish) { - List menus = menuService.selectMenuList(getUserId()); + // List menus = menuService.selectMenuList(getUserId()); + List menus = menuService.selectMenuListDistinguish(getUserId(),distinguish); AjaxResult ajax = AjaxResult.success(); ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); ajax.put("menus", menuService.buildMenuTreeSelect(menus)); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java index 00867f92..19389cd9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java @@ -47,6 +47,7 @@ public interface SysMenuMapper * @return 菜单列表 */ public List selectMenuTreeAll(); + public List selectMenuTreeDistinguishAll(Long distinguish); /** * 根据用户ID查询菜单 @@ -54,7 +55,7 @@ public interface SysMenuMapper * @param userId 用户ID * @return 菜单列表 */ - public List selectMenuTreeByUserId(Long userId); + public List selectMenuTreeByUserId(@Param("userId") Long userId,@Param("distinguish")Long distinguish); /** * 根据角色ID查询菜单树信息 @@ -112,5 +113,5 @@ public interface SysMenuMapper * @param parentId 父菜单ID * @return 结果 */ - public SysMenu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId); + public SysMenu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId,@Param("distinguish") Long distinguish); } 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 a8f7ccb2..caedb514 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 @@ -19,6 +19,7 @@ public interface ISysMenuService * @return 菜单列表 */ public List selectMenuList(Long userId); + public List selectMenuListDistinguish(Long userId,Long distinguish); /** * 根据用户查询系统菜单列表 @@ -43,7 +44,7 @@ public interface ISysMenuService * @param userId 用户ID * @return 菜单列表 */ - public List selectMenuTreeByUserId(Long userId); + public List selectMenuTreeByUserId(Long userId,Long distinguish); /** * 根据角色ID查询菜单树信息 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 db4c51f8..ee471ced 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 @@ -55,6 +55,13 @@ public class SysMenuServiceImpl implements ISysMenuService { return selectMenuList(new SysMenu(), userId); } + @Override + public List selectMenuListDistinguish(Long userId,Long distinguish) + { + SysMenu sysMenu = new SysMenu(); + sysMenu.setDistinguish(distinguish); + return selectMenuList(sysMenu, userId); + } /** * 查询系统菜单列表 @@ -69,6 +76,7 @@ public class SysMenuServiceImpl implements ISysMenuService // 管理员显示所有菜单信息 if (SysUser.isAdmin(userId)) { + menu.setDistinguish(menu.getDistinguish()); menuList = menuMapper.selectMenuList(menu); } else @@ -107,16 +115,19 @@ public class SysMenuServiceImpl implements ISysMenuService * @return 菜单列表 */ @Override - public List selectMenuTreeByUserId(Long userId) + public List selectMenuTreeByUserId(Long userId,Long distinguish) { List menus = null; if (SecurityUtils.isAdmin(userId)) { - menus = menuMapper.selectMenuTreeAll(); + // menus = menuMapper.selectMenuTreeAll(); + menus = menuMapper.selectMenuTreeDistinguishAll(distinguish); + //menus = menuMapper.selectMenuTreeByUserId(userId,distinguish); + } else { - menus = menuMapper.selectMenuTreeByUserId(userId); + menus = menuMapper.selectMenuTreeByUserId(userId,distinguish); } return getChildPerms(menus, 0); } @@ -321,7 +332,7 @@ public class SysMenuServiceImpl implements ISysMenuService public String checkMenuNameUnique(SysMenu menu) { Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); - SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId()); + SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId(),menu.getDistinguish()); if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) { return UserConstants.NOT_UNIQUE; diff --git a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index 9f1d22b1..a265d3da 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -58,6 +58,11 @@ from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0 order by m.parent_id, m.order_num + @@ -130,7 +135,7 @@ diff --git a/ruoyi-ui/src/api/menu.js b/ruoyi-ui/src/api/menu.js index faef101c..227842e9 100644 --- a/ruoyi-ui/src/api/menu.js +++ b/ruoyi-ui/src/api/menu.js @@ -3,7 +3,7 @@ import request from '@/utils/request' // 获取路由 export const getRouters = () => { return request({ - url: '/getRouters', + url: '/getRouters/'+0, method: 'get' }) -} \ No newline at end of file +} diff --git a/ruoyi-ui/src/api/system/menu.js b/ruoyi-ui/src/api/system/menu.js index f6415c65..5367e924 100644 --- a/ruoyi-ui/src/api/system/menu.js +++ b/ruoyi-ui/src/api/system/menu.js @@ -28,7 +28,7 @@ export function treeselect() { // 根据角色ID查询菜单下拉树结构 export function roleMenuTreeselect(roleId) { return request({ - url: '/system/menu/roleMenuTreeselect/' + roleId, + url: '/system/menu/roleMenuTreeselect/' + roleId+'/1', method: 'get' }) } @@ -57,4 +57,4 @@ export function delMenu(menuId) { url: '/system/menu/' + menuId, method: 'delete' }) -} \ No newline at end of file +} diff --git a/ruoyi-ui/src/store/modules/permission.js b/ruoyi-ui/src/store/modules/permission.js index d7dc0b06..cd471a4b 100644 --- a/ruoyi-ui/src/store/modules/permission.js +++ b/ruoyi-ui/src/store/modules/permission.js @@ -38,7 +38,7 @@ const permission = { GenerateRoutes({ commit }) { return new Promise(resolve => { // 向后端请求路由数据 - getRouters().then(res => { + getRouters(1).then(res => { const sdata = JSON.parse(JSON.stringify(res.data)) const rdata = JSON.parse(JSON.stringify(res.data)) const sidebarRoutes = filterAsyncRouter(sdata)