作者 RuoYi

优化多角色数据权限匹配规则

正在显示 21 个修改的文件 包含 198 行增加61 行删除
@@ -79,29 +79,6 @@ public class SysDeptController extends BaseController @@ -79,29 +79,6 @@ public class SysDeptController extends BaseController
79 } 79 }
80 80
81 /** 81 /**
82 - * 获取部门下拉树列表  
83 - */  
84 - @GetMapping("/treeselect")  
85 - public AjaxResult treeselect(SysDept dept)  
86 - {  
87 - List<SysDept> depts = deptService.selectDeptList(dept);  
88 - return AjaxResult.success(deptService.buildDeptTreeSelect(depts));  
89 - }  
90 -  
91 - /**  
92 - * 加载对应角色部门列表树  
93 - */  
94 - @GetMapping(value = "/roleDeptTreeselect/{roleId}")  
95 - public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)  
96 - {  
97 - List<SysDept> depts = deptService.selectDeptList(new SysDept());  
98 - AjaxResult ajax = AjaxResult.success();  
99 - ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));  
100 - ajax.put("depts", deptService.buildDeptTreeSelect(depts));  
101 - return ajax;  
102 - }  
103 -  
104 - /**  
105 * 新增部门 82 * 新增部门
106 */ 83 */
107 @PreAuthorize("@ss.hasPermi('system:dept:add')") 84 @PreAuthorize("@ss.hasPermi('system:dept:add')")
@@ -17,6 +17,7 @@ import com.ruoyi.common.annotation.Log; @@ -17,6 +17,7 @@ import com.ruoyi.common.annotation.Log;
17 import com.ruoyi.common.constant.UserConstants; 17 import com.ruoyi.common.constant.UserConstants;
18 import com.ruoyi.common.core.controller.BaseController; 18 import com.ruoyi.common.core.controller.BaseController;
19 import com.ruoyi.common.core.domain.AjaxResult; 19 import com.ruoyi.common.core.domain.AjaxResult;
  20 +import com.ruoyi.common.core.domain.entity.SysDept;
20 import com.ruoyi.common.core.domain.entity.SysRole; 21 import com.ruoyi.common.core.domain.entity.SysRole;
21 import com.ruoyi.common.core.domain.entity.SysUser; 22 import com.ruoyi.common.core.domain.entity.SysUser;
22 import com.ruoyi.common.core.domain.model.LoginUser; 23 import com.ruoyi.common.core.domain.model.LoginUser;
@@ -27,6 +28,7 @@ import com.ruoyi.common.utils.poi.ExcelUtil; @@ -27,6 +28,7 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
27 import com.ruoyi.framework.web.service.SysPermissionService; 28 import com.ruoyi.framework.web.service.SysPermissionService;
28 import com.ruoyi.framework.web.service.TokenService; 29 import com.ruoyi.framework.web.service.TokenService;
29 import com.ruoyi.system.domain.SysUserRole; 30 import com.ruoyi.system.domain.SysUserRole;
  31 +import com.ruoyi.system.service.ISysDeptService;
30 import com.ruoyi.system.service.ISysRoleService; 32 import com.ruoyi.system.service.ISysRoleService;
31 import com.ruoyi.system.service.ISysUserService; 33 import com.ruoyi.system.service.ISysUserService;
32 34
@@ -51,6 +53,9 @@ public class SysRoleController extends BaseController @@ -51,6 +53,9 @@ public class SysRoleController extends BaseController
51 @Autowired 53 @Autowired
52 private ISysUserService userService; 54 private ISysUserService userService;
53 55
  56 + @Autowired
  57 + private ISysDeptService deptService;
  58 +
54 @PreAuthorize("@ss.hasPermi('system:role:list')") 59 @PreAuthorize("@ss.hasPermi('system:role:list')")
55 @GetMapping("/list") 60 @GetMapping("/list")
56 public TableDataInfo list(SysRole role) 61 public TableDataInfo list(SysRole role)
@@ -242,4 +247,18 @@ public class SysRoleController extends BaseController @@ -242,4 +247,18 @@ public class SysRoleController extends BaseController
242 roleService.checkRoleDataScope(roleId); 247 roleService.checkRoleDataScope(roleId);
243 return toAjax(roleService.insertAuthUsers(roleId, userIds)); 248 return toAjax(roleService.insertAuthUsers(roleId, userIds));
244 } 249 }
  250 +
  251 + /**
  252 + * 获取对应角色部门树列表
  253 + */
  254 + @PreAuthorize("@ss.hasPermi('system:role:list')")
  255 + @GetMapping(value = "/deptTree/{roleId}")
  256 + public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
  257 + {
  258 + AjaxResult ajax = AjaxResult.success();
  259 + ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
  260 + ajax.put("depts", deptService.selectDeptTreeList(new SysDept()));
  261 + return ajax;
  262 + }
  263 +
245 } 264 }
@@ -20,6 +20,7 @@ import com.ruoyi.common.annotation.Log; @@ -20,6 +20,7 @@ import com.ruoyi.common.annotation.Log;
20 import com.ruoyi.common.constant.UserConstants; 20 import com.ruoyi.common.constant.UserConstants;
21 import com.ruoyi.common.core.controller.BaseController; 21 import com.ruoyi.common.core.controller.BaseController;
22 import com.ruoyi.common.core.domain.AjaxResult; 22 import com.ruoyi.common.core.domain.AjaxResult;
  23 +import com.ruoyi.common.core.domain.entity.SysDept;
23 import com.ruoyi.common.core.domain.entity.SysRole; 24 import com.ruoyi.common.core.domain.entity.SysRole;
24 import com.ruoyi.common.core.domain.entity.SysUser; 25 import com.ruoyi.common.core.domain.entity.SysUser;
25 import com.ruoyi.common.core.page.TableDataInfo; 26 import com.ruoyi.common.core.page.TableDataInfo;
@@ -27,6 +28,7 @@ import com.ruoyi.common.enums.BusinessType; @@ -27,6 +28,7 @@ import com.ruoyi.common.enums.BusinessType;
27 import com.ruoyi.common.utils.SecurityUtils; 28 import com.ruoyi.common.utils.SecurityUtils;
28 import com.ruoyi.common.utils.StringUtils; 29 import com.ruoyi.common.utils.StringUtils;
29 import com.ruoyi.common.utils.poi.ExcelUtil; 30 import com.ruoyi.common.utils.poi.ExcelUtil;
  31 +import com.ruoyi.system.service.ISysDeptService;
30 import com.ruoyi.system.service.ISysPostService; 32 import com.ruoyi.system.service.ISysPostService;
31 import com.ruoyi.system.service.ISysRoleService; 33 import com.ruoyi.system.service.ISysRoleService;
32 import com.ruoyi.system.service.ISysUserService; 34 import com.ruoyi.system.service.ISysUserService;
@@ -47,6 +49,9 @@ public class SysUserController extends BaseController @@ -47,6 +49,9 @@ public class SysUserController extends BaseController
47 private ISysRoleService roleService; 49 private ISysRoleService roleService;
48 50
49 @Autowired 51 @Autowired
  52 + private ISysDeptService deptService;
  53 +
  54 + @Autowired
50 private ISysPostService postService; 55 private ISysPostService postService;
51 56
52 /** 57 /**
@@ -234,4 +239,14 @@ public class SysUserController extends BaseController @@ -234,4 +239,14 @@ public class SysUserController extends BaseController
234 userService.insertUserAuth(userId, roleIds); 239 userService.insertUserAuth(userId, roleIds);
235 return success(); 240 return success();
236 } 241 }
  242 +
  243 + /**
  244 + * 获取部门树列表
  245 + */
  246 + @PreAuthorize("@ss.hasPermi('system:user:list')")
  247 + @GetMapping("/deptTree")
  248 + public AjaxResult deptTree(SysDept dept)
  249 + {
  250 + return AjaxResult.success(deptService.selectDeptTreeList(dept));
  251 + }
237 } 252 }
@@ -25,4 +25,9 @@ public @interface DataScope @@ -25,4 +25,9 @@ public @interface DataScope
25 * 用户表的别名 25 * 用户表的别名
26 */ 26 */
27 public String userAlias() default ""; 27 public String userAlias() default "";
  28 +
  29 + /**
  30 + * 权限字符(如不填默认会自动根据注解获取)
  31 + */
  32 + public String permission() default "";
28 } 33 }
@@ -12,6 +12,11 @@ public class UserConstants @@ -12,6 +12,11 @@ public class UserConstants
12 */ 12 */
13 public static final String SYS_USER = "SYS_USER"; 13 public static final String SYS_USER = "SYS_USER";
14 14
  15 + /**
  16 + * ss标记的权限字符
  17 + */
  18 + public static final String SS_PERMISSION = "SS_PERMISSION";
  19 +
15 /** 正常状态 */ 20 /** 正常状态 */
16 public static final String NORMAL = "0"; 21 public static final String NORMAL = "0";
17 22
1 package com.ruoyi.common.core.domain.entity; 1 package com.ruoyi.common.core.domain.entity;
2 2
  3 +import java.util.Set;
3 import javax.validation.constraints.NotBlank; 4 import javax.validation.constraints.NotBlank;
4 import javax.validation.constraints.Size; 5 import javax.validation.constraints.Size;
5 import org.apache.commons.lang3.builder.ToStringBuilder; 6 import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -59,6 +60,9 @@ public class SysRole extends BaseEntity @@ -59,6 +60,9 @@ public class SysRole extends BaseEntity
59 /** 部门组(数据权限) */ 60 /** 部门组(数据权限) */
60 private Long[] deptIds; 61 private Long[] deptIds;
61 62
  63 + /** 角色菜单权限 */
  64 + private Set<String> permissions;
  65 +
62 public SysRole() 66 public SysRole()
63 { 67 {
64 68
@@ -204,6 +208,16 @@ public class SysRole extends BaseEntity @@ -204,6 +208,16 @@ public class SysRole extends BaseEntity
204 this.deptIds = deptIds; 208 this.deptIds = deptIds;
205 } 209 }
206 210
  211 + public Set<String> getPermissions()
  212 + {
  213 + return permissions;
  214 + }
  215 +
  216 + public void setPermissions(Set<String> permissions)
  217 + {
  218 + this.permissions = permissions;
  219 + }
  220 +
207 @Override 221 @Override
208 public String toString() { 222 public String toString() {
209 return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) 223 return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -11,8 +11,9 @@ import com.ruoyi.common.core.domain.BaseEntity; @@ -11,8 +11,9 @@ import com.ruoyi.common.core.domain.BaseEntity;
11 import com.ruoyi.common.core.domain.entity.SysRole; 11 import com.ruoyi.common.core.domain.entity.SysRole;
12 import com.ruoyi.common.core.domain.entity.SysUser; 12 import com.ruoyi.common.core.domain.entity.SysUser;
13 import com.ruoyi.common.core.domain.model.LoginUser; 13 import com.ruoyi.common.core.domain.model.LoginUser;
14 -import com.ruoyi.common.utils.StringUtils;  
15 import com.ruoyi.common.utils.SecurityUtils; 14 import com.ruoyi.common.utils.SecurityUtils;
  15 +import com.ruoyi.common.utils.StringUtils;
  16 +import com.ruoyi.framework.security.context.PermissionContextHolder;
16 17
17 /** 18 /**
18 * 数据过滤处理 19 * 数据过滤处理
@@ -70,8 +71,9 @@ public class DataScopeAspect @@ -70,8 +71,9 @@ public class DataScopeAspect
70 // 如果是超级管理员,则不过滤数据 71 // 如果是超级管理员,则不过滤数据
71 if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) 72 if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
72 { 73 {
  74 + String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext());
73 dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), 75 dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
74 - controllerDataScope.userAlias()); 76 + controllerDataScope.userAlias(), permission);
75 } 77 }
76 } 78 }
77 } 79 }
@@ -83,8 +85,9 @@ public class DataScopeAspect @@ -83,8 +85,9 @@ public class DataScopeAspect
83 * @param user 用户 85 * @param user 用户
84 * @param deptAlias 部门别名 86 * @param deptAlias 部门别名
85 * @param userAlias 用户别名 87 * @param userAlias 用户别名
  88 + * @param permission 权限字符
86 */ 89 */
87 - public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) 90 + public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission)
88 { 91 {
89 StringBuilder sqlString = new StringBuilder(); 92 StringBuilder sqlString = new StringBuilder();
90 List<String> conditions = new ArrayList<String>(); 93 List<String> conditions = new ArrayList<String>();
@@ -96,6 +99,10 @@ public class DataScopeAspect @@ -96,6 +99,10 @@ public class DataScopeAspect
96 { 99 {
97 continue; 100 continue;
98 } 101 }
  102 + if (StringUtils.isNotEmpty(permission) && StringUtils.isNotEmpty(role.getPermissions()) && !role.getPermissions().contains(permission))
  103 + {
  104 + continue;
  105 + }
99 if (DATA_SCOPE_ALL.equals(dataScope)) 106 if (DATA_SCOPE_ALL.equals(dataScope))
100 { 107 {
101 sqlString = new StringBuilder(); 108 sqlString = new StringBuilder();
  1 +package com.ruoyi.framework.security.context;
  2 +
  3 +/**
  4 + * 权限信息
  5 + *
  6 + * @author ruoyi
  7 + */
  8 +public class PermissionContextHolder
  9 +{
  10 + private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
  11 +
  12 + public static void setContext(String permission)
  13 + {
  14 + contextHolder.set(permission);
  15 + }
  16 +
  17 + public static String getContext()
  18 + {
  19 + return contextHolder.get();
  20 + }
  21 +}
@@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.entity.SysRole; @@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.entity.SysRole;
7 import com.ruoyi.common.core.domain.model.LoginUser; 7 import com.ruoyi.common.core.domain.model.LoginUser;
8 import com.ruoyi.common.utils.SecurityUtils; 8 import com.ruoyi.common.utils.SecurityUtils;
9 import com.ruoyi.common.utils.StringUtils; 9 import com.ruoyi.common.utils.StringUtils;
  10 +import com.ruoyi.framework.security.context.PermissionContextHolder;
10 11
11 /** 12 /**
12 * RuoYi首创 自定义权限实现,ss取自SpringSecurity首字母 13 * RuoYi首创 自定义权限实现,ss取自SpringSecurity首字母
@@ -43,6 +44,7 @@ public class PermissionService @@ -43,6 +44,7 @@ public class PermissionService
43 { 44 {
44 return false; 45 return false;
45 } 46 }
  47 + PermissionContextHolder.setContext(permission);
46 return hasPermissions(loginUser.getPermissions(), permission); 48 return hasPermissions(loginUser.getPermissions(), permission);
47 } 49 }
48 50
1 package com.ruoyi.framework.web.service; 1 package com.ruoyi.framework.web.service;
2 2
3 import java.util.HashSet; 3 import java.util.HashSet;
  4 +import java.util.List;
4 import java.util.Set; 5 import java.util.Set;
5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Component;
  8 +import com.ruoyi.common.core.domain.entity.SysRole;
7 import com.ruoyi.common.core.domain.entity.SysUser; 9 import com.ruoyi.common.core.domain.entity.SysUser;
8 import com.ruoyi.system.service.ISysMenuService; 10 import com.ruoyi.system.service.ISysMenuService;
9 import com.ruoyi.system.service.ISysRoleService; 11 import com.ruoyi.system.service.ISysRoleService;
@@ -59,8 +61,22 @@ public class SysPermissionService @@ -59,8 +61,22 @@ public class SysPermissionService
59 } 61 }
60 else 62 else
61 { 63 {
  64 + List<SysRole> roles = user.getRoles();
  65 + if (!roles.isEmpty() && roles.size() > 1)
  66 + {
  67 + // 多角色设置permissions属性,以便数据权限匹配权限
  68 + for (SysRole role : roles)
  69 + {
  70 + Set<String> rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId());
  71 + role.setPermissions(rolePerms);
  72 + perms.addAll(rolePerms);
  73 + }
  74 + }
  75 + else
  76 + {
62 perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId())); 77 perms.addAll(menuService.selectMenuPermsByUserId(user.getUserId()));
63 } 78 }
  79 + }
64 return perms; 80 return perms;
65 } 81 }
66 } 82 }
@@ -35,6 +35,14 @@ public interface SysMenuMapper @@ -35,6 +35,14 @@ public interface SysMenuMapper
35 public List<SysMenu> selectMenuListByUserId(SysMenu menu); 35 public List<SysMenu> selectMenuListByUserId(SysMenu menu);
36 36
37 /** 37 /**
  38 + * 根据角色ID查询权限
  39 + *
  40 + * @param roleId 角色ID
  41 + * @return 权限列表
  42 + */
  43 + public List<String> selectMenuPermsByRoleId(Long roleId);
  44 +
  45 + /**
38 * 根据用户ID查询权限 46 * 根据用户ID查询权限
39 * 47 *
40 * @param userId 用户ID 48 * @param userId 用户ID
@@ -20,6 +20,14 @@ public interface ISysDeptService @@ -20,6 +20,14 @@ public interface ISysDeptService
20 public List<SysDept> selectDeptList(SysDept dept); 20 public List<SysDept> selectDeptList(SysDept dept);
21 21
22 /** 22 /**
  23 + * 查询部门树结构信息
  24 + *
  25 + * @param dept 部门信息
  26 + * @return 部门树信息集合
  27 + */
  28 + public List<TreeSelect> selectDeptTreeList(SysDept dept);
  29 +
  30 + /**
23 * 构建前端所需要树结构 31 * 构建前端所需要树结构
24 * 32 *
25 * @param depts 部门列表 33 * @param depts 部门列表
@@ -39,6 +39,14 @@ public interface ISysMenuService @@ -39,6 +39,14 @@ public interface ISysMenuService
39 public Set<String> selectMenuPermsByUserId(Long userId); 39 public Set<String> selectMenuPermsByUserId(Long userId);
40 40
41 /** 41 /**
  42 + * 根据角色ID查询权限
  43 + *
  44 + * @param roleId 角色ID
  45 + * @return 权限列表
  46 + */
  47 + public Set<String> selectMenuPermsByRoleId(Long roleId);
  48 +
  49 + /**
42 * 根据用户ID查询菜单树信息 50 * 根据用户ID查询菜单树信息
43 * 51 *
44 * @param userId 用户ID 52 * @param userId 用户ID
@@ -49,6 +49,19 @@ public class SysDeptServiceImpl implements ISysDeptService @@ -49,6 +49,19 @@ public class SysDeptServiceImpl implements ISysDeptService
49 } 49 }
50 50
51 /** 51 /**
  52 + * 查询部门树结构信息
  53 + *
  54 + * @param dept 部门信息
  55 + * @return 部门树信息集合
  56 + */
  57 + @Override
  58 + public List<TreeSelect> selectDeptTreeList(SysDept dept)
  59 + {
  60 + List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
  61 + return buildDeptTreeSelect(depts);
  62 + }
  63 +
  64 + /**
52 * 构建前端所需要树结构 65 * 构建前端所需要树结构
53 * 66 *
54 * @param depts 部门列表 67 * @param depts 部门列表
@@ -101,6 +101,27 @@ public class SysMenuServiceImpl implements ISysMenuService @@ -101,6 +101,27 @@ public class SysMenuServiceImpl implements ISysMenuService
101 } 101 }
102 102
103 /** 103 /**
  104 + * 根据角色ID查询权限
  105 + *
  106 + * @param roleId 角色ID
  107 + * @return 权限列表
  108 + */
  109 + @Override
  110 + public Set<String> selectMenuPermsByRoleId(Long roleId)
  111 + {
  112 + List<String> perms = menuMapper.selectMenuPermsByRoleId(roleId);
  113 + Set<String> permsSet = new HashSet<>();
  114 + for (String perm : perms)
  115 + {
  116 + if (StringUtils.isNotEmpty(perm))
  117 + {
  118 + permsSet.addAll(Arrays.asList(perm.trim().split(",")));
  119 + }
  120 + }
  121 + return permsSet;
  122 + }
  123 +
  124 + /**
104 * 根据用户ID查询菜单 125 * 根据用户ID查询菜单
105 * 126 *
106 * @param userId 用户名称 127 * @param userId 用户名称
@@ -111,6 +111,14 @@ @@ -111,6 +111,14 @@
111 where m.status = '0' and r.status = '0' and ur.user_id = #{userId} 111 where m.status = '0' and r.status = '0' and ur.user_id = #{userId}
112 </select> 112 </select>
113 113
  114 + <select id="selectMenuPermsByRoleId" parameterType="Long" resultType="String">
  115 + select distinct m.perms
  116 + from sys_menu m
  117 + left join sys_role_menu rm on m.menu_id = rm.menu_id
  118 + where m.status = '0' and rm.role_id = #{roleId}
  119 + </select>
  120 +
  121 +
114 <select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult"> 122 <select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult">
115 <include refid="selectMenuVo"/> 123 <include refid="selectMenuVo"/>
116 where menu_id = #{menuId} 124 where menu_id = #{menuId}
@@ -25,22 +25,6 @@ export function getDept(deptId) { @@ -25,22 +25,6 @@ export function getDept(deptId) {
25 }) 25 })
26 } 26 }
27 27
28 -// 查询部门下拉树结构  
29 -export function treeselect() {  
30 - return request({  
31 - url: '/system/dept/treeselect',  
32 - method: 'get'  
33 - })  
34 -}  
35 -  
36 -// 根据角色ID查询部门树结构  
37 -export function roleDeptTreeselect(roleId) {  
38 - return request({  
39 - url: '/system/dept/roleDeptTreeselect/' + roleId,  
40 - method: 'get'  
41 - })  
42 -}  
43 -  
44 // 新增部门 28 // 新增部门
45 export function addDept(data) { 29 export function addDept(data) {
46 return request({ 30 return request({
@@ -109,3 +109,11 @@ export function authUserSelectAll(data) { @@ -109,3 +109,11 @@ export function authUserSelectAll(data) {
109 params: data 109 params: data
110 }) 110 })
111 } 111 }
  112 +
  113 +// 根据角色ID查询部门树结构
  114 +export function deptTreeSelect(roleId) {
  115 + return request({
  116 + url: '/system/role/deptTree/' + roleId,
  117 + method: 'get'
  118 + })
  119 +}
@@ -125,3 +125,11 @@ export function updateAuthRole(data) { @@ -125,3 +125,11 @@ export function updateAuthRole(data) {
125 params: data 125 params: data
126 }) 126 })
127 } 127 }
  128 +
  129 +// 查询部门下拉树结构
  130 +export function deptTreeSelect() {
  131 + return request({
  132 + url: '/system/user/deptTree',
  133 + method: 'get'
  134 + })
  135 +}
@@ -254,9 +254,8 @@ @@ -254,9 +254,8 @@
254 </template> 254 </template>
255 255
256 <script> 256 <script>
257 -import { listRole, getRole, delRole, addRole, updateRole, dataScope, changeRoleStatus } from "@/api/system/role"; 257 +import { listRole, getRole, delRole, addRole, updateRole, dataScope, changeRoleStatus, deptTreeSelect } from "@/api/system/role";
258 import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu"; 258 import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu";
259 -import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";  
260 259
261 export default { 260 export default {
262 name: "Role", 261 name: "Role",
@@ -364,12 +363,6 @@ export default { @@ -364,12 +363,6 @@ export default {
364 this.menuOptions = response.data; 363 this.menuOptions = response.data;
365 }); 364 });
366 }, 365 },
367 - /** 查询部门树结构 */  
368 - getDeptTreeselect() {  
369 - deptTreeselect().then(response => {  
370 - this.deptOptions = response.data;  
371 - });  
372 - },  
373 // 所有菜单节点数据 366 // 所有菜单节点数据
374 getMenuAllCheckedKeys() { 367 getMenuAllCheckedKeys() {
375 // 目前被选中的菜单节点 368 // 目前被选中的菜单节点
@@ -396,8 +389,8 @@ export default { @@ -396,8 +389,8 @@ export default {
396 }); 389 });
397 }, 390 },
398 /** 根据角色ID查询部门树结构 */ 391 /** 根据角色ID查询部门树结构 */
399 - getRoleDeptTreeselect(roleId) {  
400 - return roleDeptTreeselect(roleId).then(response => { 392 + getDeptTree(roleId) {
  393 + return deptTreeSelect(roleId).then(response => {
401 this.deptOptions = response.depts; 394 this.deptOptions = response.depts;
402 return response; 395 return response;
403 }); 396 });
@@ -543,12 +536,12 @@ export default { @@ -543,12 +536,12 @@ export default {
543 /** 分配数据权限操作 */ 536 /** 分配数据权限操作 */
544 handleDataScope(row) { 537 handleDataScope(row) {
545 this.reset(); 538 this.reset();
546 - const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId); 539 + const deptTreeSelect = this.getDeptTree(row.roleId);
547 getRole(row.roleId).then(response => { 540 getRole(row.roleId).then(response => {
548 this.form = response.data; 541 this.form = response.data;
549 this.openDataScope = true; 542 this.openDataScope = true;
550 this.$nextTick(() => { 543 this.$nextTick(() => {
551 - roleDeptTreeselect.then(res => { 544 + deptTreeSelect.then(res => {
552 this.$refs.dept.setCheckedKeys(res.checkedKeys); 545 this.$refs.dept.setCheckedKeys(res.checkedKeys);
553 }); 546 });
554 }); 547 });
@@ -342,9 +342,8 @@ @@ -342,9 +342,8 @@
342 </template> 342 </template>
343 343
344 <script> 344 <script>
345 -import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus } from "@/api/system/user"; 345 +import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect } from "@/api/system/user";
346 import { getToken } from "@/utils/auth"; 346 import { getToken } from "@/utils/auth";
347 -import { treeselect } from "@/api/system/dept";  
348 import Treeselect from "@riophae/vue-treeselect"; 347 import Treeselect from "@riophae/vue-treeselect";
349 import "@riophae/vue-treeselect/dist/vue-treeselect.css"; 348 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
350 349
@@ -462,7 +461,7 @@ export default { @@ -462,7 +461,7 @@ export default {
462 }, 461 },
463 created() { 462 created() {
464 this.getList(); 463 this.getList();
465 - this.getTreeselect(); 464 + this.getDeptTree();
466 this.getConfigKey("sys.user.initPassword").then(response => { 465 this.getConfigKey("sys.user.initPassword").then(response => {
467 this.initPassword = response.msg; 466 this.initPassword = response.msg;
468 }); 467 });
@@ -479,8 +478,8 @@ export default { @@ -479,8 +478,8 @@ export default {
479 ); 478 );
480 }, 479 },
481 /** 查询部门下拉树结构 */ 480 /** 查询部门下拉树结构 */
482 - getTreeselect() {  
483 - treeselect().then(response => { 481 + getDeptTree() {
  482 + deptTreeSelect().then(response => {
484 this.deptOptions = response.data; 483 this.deptOptions = response.data;
485 }); 484 });
486 }, 485 },
@@ -561,7 +560,6 @@ export default { @@ -561,7 +560,6 @@ export default {
561 /** 新增按钮操作 */ 560 /** 新增按钮操作 */
562 handleAdd() { 561 handleAdd() {
563 this.reset(); 562 this.reset();
564 - this.getTreeselect();  
565 getUser().then(response => { 563 getUser().then(response => {
566 this.postOptions = response.posts; 564 this.postOptions = response.posts;
567 this.roleOptions = response.roles; 565 this.roleOptions = response.roles;
@@ -573,7 +571,6 @@ export default { @@ -573,7 +571,6 @@ export default {
573 /** 修改按钮操作 */ 571 /** 修改按钮操作 */
574 handleUpdate(row) { 572 handleUpdate(row) {
575 this.reset(); 573 this.reset();
576 - this.getTreeselect();  
577 const userId = row.userId || this.ids; 574 const userId = row.userId || this.ids;
578 getUser(userId).then(response => { 575 getUser(userId).then(response => {
579 this.form = response.data; 576 this.form = response.data;