Browse Source

菜单权限 getRouters/(1是前端,0后台)

develop
王兴琳 6 months ago
parent
commit
36f2d2d37a
  1. 17
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java
  2. 7
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java
  3. 5
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java
  4. 3
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java
  5. 19
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
  6. 11
      ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml
  7. 4
      ruoyi-ui/src/api/menu.js
  8. 4
      ruoyi-ui/src/api/system/menu.js
  9. 2
      ruoyi-ui/src/store/modules/permission.js

17
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<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId,distinguish);
return AjaxResult.success(menuService.buildMenus(menus));
}
}

7
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<SysMenu> menus = menuService.selectMenuList(getUserId());
// List<SysMenu> menus = menuService.selectMenuList(getUserId());
List<SysMenu> menus = menuService.selectMenuListDistinguish(getUserId(),distinguish);
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId));
ajax.put("menus", menuService.buildMenuTreeSelect(menus));

5
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java

@ -47,6 +47,7 @@ public interface SysMenuMapper
* @return 菜单列表
*/
public List<SysMenu> selectMenuTreeAll();
public List<SysMenu> selectMenuTreeDistinguishAll(Long distinguish);
/**
* 根据用户ID查询菜单
@ -54,7 +55,7 @@ public interface SysMenuMapper
* @param userId 用户ID
* @return 菜单列表
*/
public List<SysMenu> selectMenuTreeByUserId(Long userId);
public List<SysMenu> 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);
}

3
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java

@ -19,6 +19,7 @@ public interface ISysMenuService
* @return 菜单列表
*/
public List<SysMenu> selectMenuList(Long userId);
public List<SysMenu> selectMenuListDistinguish(Long userId,Long distinguish);
/**
* 根据用户查询系统菜单列表
@ -43,7 +44,7 @@ public interface ISysMenuService
* @param userId 用户ID
* @return 菜单列表
*/
public List<SysMenu> selectMenuTreeByUserId(Long userId);
public List<SysMenu> selectMenuTreeByUserId(Long userId,Long distinguish);
/**
* 根据角色ID查询菜单树信息

19
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<SysMenu> 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<SysMenu> selectMenuTreeByUserId(Long userId)
public List<SysMenu> selectMenuTreeByUserId(Long userId,Long distinguish)
{
List<SysMenu> 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;

11
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
</select>
<select id="selectMenuTreeDistinguishAll" resultMap="SysMenuResult">
select distinct m.distinguish, m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0 AND m.distinguish = #{distinguish}
order by m.parent_id, m.order_num
</select>
<select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
@ -82,13 +87,13 @@
</select>
<select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
select distinct m.distinguish,m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
from sys_menu m
left join sys_role_menu rm on m.menu_id = rm.menu_id
left join sys_user_role ur on rm.role_id = ur.role_id
left join sys_role ro on ur.role_id = ro.role_id
left join sys_user u on ur.user_id = u.user_id
where u.user_id = #{userId} and m.menu_type in ('M', 'C') and m.status = 0 AND ro.status = 0
where u.user_id = #{userId} and m.menu_type in ('M', 'C') and m.status = 0 AND ro.status = 0 and m.distinguish=#{distinguish}
order by m.parent_id, m.order_num
</select>
@ -130,7 +135,7 @@
<select id="checkMenuNameUnique" parameterType="SysMenu" resultMap="SysMenuResult">
<include refid="selectMenuVo"/>
where menu_name=#{menuName} and parent_id = #{parentId} limit 1
where menu_name=#{menuName} and parent_id = #{parentId} and distinguish=#{distinguish} limit 1
</select>
<update id="updateMenu" parameterType="SysMenu">

4
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'
})
}
}

4
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'
})
}
}

2
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)

Loading…
Cancel
Save