作者 RuoYi

角色管理新增分配用户功能

@@ -17,6 +17,7 @@ import com.ruoyi.common.constant.UserConstants; @@ -17,6 +17,7 @@ import com.ruoyi.common.constant.UserConstants;
17 import com.ruoyi.common.core.controller.BaseController; 17 import com.ruoyi.common.core.controller.BaseController;
18 import com.ruoyi.common.core.domain.AjaxResult; 18 import com.ruoyi.common.core.domain.AjaxResult;
19 import com.ruoyi.common.core.domain.entity.SysRole; 19 import com.ruoyi.common.core.domain.entity.SysRole;
  20 +import com.ruoyi.common.core.domain.entity.SysUser;
20 import com.ruoyi.common.core.domain.model.LoginUser; 21 import com.ruoyi.common.core.domain.model.LoginUser;
21 import com.ruoyi.common.core.page.TableDataInfo; 22 import com.ruoyi.common.core.page.TableDataInfo;
22 import com.ruoyi.common.enums.BusinessType; 23 import com.ruoyi.common.enums.BusinessType;
@@ -26,6 +27,7 @@ import com.ruoyi.common.utils.StringUtils; @@ -26,6 +27,7 @@ import com.ruoyi.common.utils.StringUtils;
26 import com.ruoyi.common.utils.poi.ExcelUtil; 27 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;
  30 +import com.ruoyi.system.domain.SysUserRole;
29 import com.ruoyi.system.service.ISysRoleService; 31 import com.ruoyi.system.service.ISysRoleService;
30 import com.ruoyi.system.service.ISysUserService; 32 import com.ruoyi.system.service.ISysUserService;
31 33
@@ -179,4 +181,59 @@ public class SysRoleController extends BaseController @@ -179,4 +181,59 @@ public class SysRoleController extends BaseController
179 { 181 {
180 return AjaxResult.success(roleService.selectRoleAll()); 182 return AjaxResult.success(roleService.selectRoleAll());
181 } 183 }
  184 +
  185 + /**
  186 + * 查询已分配用户角色列表
  187 + */
  188 + @PreAuthorize("@ss.hasPermi('system:role:list')")
  189 + @GetMapping("/authUser/allocatedList")
  190 + public TableDataInfo allocatedList(SysUser user)
  191 + {
  192 + startPage();
  193 + List<SysUser> list = userService.selectAllocatedList(user);
  194 + return getDataTable(list);
  195 + }
  196 +
  197 + /**
  198 + * 查询未分配用户角色列表
  199 + */
  200 + @PreAuthorize("@ss.hasPermi('system:role:list')")
  201 + @GetMapping("/authUser/unallocatedList")
  202 + public TableDataInfo unallocatedList(SysUser user)
  203 + {
  204 + startPage();
  205 + List<SysUser> list = userService.selectUnallocatedList(user);
  206 + return getDataTable(list);
  207 + }
  208 +
  209 + /**
  210 + * 取消授权用户
  211 + */
  212 + @PreAuthorize("@ss.hasPermi('system:role:edit')")
  213 + @Log(title = "角色管理", businessType = BusinessType.GRANT)
  214 + @PutMapping("/authUser/cancel")
  215 + public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
  216 + {
  217 + return toAjax(roleService.deleteAuthUser(userRole));
  218 + }
  219 +
  220 + /**
  221 + * 批量取消授权用户
  222 + */
  223 + @Log(title = "角色管理", businessType = BusinessType.GRANT)
  224 + @PutMapping("/authUser/cancelAll")
  225 + public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
  226 + {
  227 + return toAjax(roleService.deleteAuthUsers(roleId, userIds));
  228 + }
  229 +
  230 + /**
  231 + * 批量选择用户授权
  232 + */
  233 + @Log(title = "角色管理", businessType = BusinessType.GRANT)
  234 + @PutMapping("/authUser/selectAll")
  235 + public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
  236 + {
  237 + return toAjax(roleService.insertAuthUsers(roleId, userIds));
  238 + }
182 } 239 }
@@ -92,6 +92,9 @@ public class SysUser extends BaseEntity @@ -92,6 +92,9 @@ public class SysUser extends BaseEntity
92 /** 岗位组 */ 92 /** 岗位组 */
93 private Long[] postIds; 93 private Long[] postIds;
94 94
  95 + /** 角色ID */
  96 + private Long roleId;
  97 +
95 public SysUser() 98 public SysUser()
96 { 99 {
97 100
@@ -300,6 +303,16 @@ public class SysUser extends BaseEntity @@ -300,6 +303,16 @@ public class SysUser extends BaseEntity
300 this.postIds = postIds; 303 this.postIds = postIds;
301 } 304 }
302 305
  306 + public Long getRoleId()
  307 + {
  308 + return roleId;
  309 + }
  310 +
  311 + public void setRoleId(Long roleId)
  312 + {
  313 + this.roleId = roleId;
  314 + }
  315 +
303 @Override 316 @Override
304 public String toString() { 317 public String toString() {
305 return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) 318 return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -20,6 +20,22 @@ public interface SysUserMapper @@ -20,6 +20,22 @@ public interface SysUserMapper
20 public List<SysUser> selectUserList(SysUser sysUser); 20 public List<SysUser> selectUserList(SysUser sysUser);
21 21
22 /** 22 /**
  23 + * 根据条件分页查询未已配用户角色列表
  24 + *
  25 + * @param user 用户信息
  26 + * @return 用户信息集合信息
  27 + */
  28 + public List<SysUser> selectAllocatedList(SysUser user);
  29 +
  30 + /**
  31 + * 根据条件分页查询未分配用户角色列表
  32 + *
  33 + * @param user 用户信息
  34 + * @return 用户信息集合信息
  35 + */
  36 + public List<SysUser> selectUnallocatedList(SysUser user);
  37 +
  38 + /**
23 * 通过用户名查询用户 39 * 通过用户名查询用户
24 * 40 *
25 * @param userName 用户名 41 * @param userName 用户名
@@ -3,6 +3,7 @@ package com.ruoyi.system.service; @@ -3,6 +3,7 @@ package com.ruoyi.system.service;
3 import java.util.List; 3 import java.util.List;
4 import java.util.Set; 4 import java.util.Set;
5 import com.ruoyi.common.core.domain.entity.SysRole; 5 import com.ruoyi.common.core.domain.entity.SysRole;
  6 +import com.ruoyi.system.domain.SysUserRole;
6 7
7 /** 8 /**
8 * 角色业务层 9 * 角色业务层
@@ -136,4 +137,30 @@ public interface ISysRoleService @@ -136,4 +137,30 @@ public interface ISysRoleService
136 * @return 结果 137 * @return 结果
137 */ 138 */
138 public int deleteRoleByIds(Long[] roleIds); 139 public int deleteRoleByIds(Long[] roleIds);
  140 +
  141 + /**
  142 + * 取消授权用户角色
  143 + *
  144 + * @param userRole 用户和角色关联信息
  145 + * @return 结果
  146 + */
  147 + public int deleteAuthUser(SysUserRole userRole);
  148 +
  149 + /**
  150 + * 批量取消授权用户角色
  151 + *
  152 + * @param roleId 角色ID
  153 + * @param userIds 需要取消授权的用户数据ID
  154 + * @return 结果
  155 + */
  156 + public int deleteAuthUsers(Long roleId, Long[] userIds);
  157 +
  158 + /**
  159 + * 批量选择授权用户角色
  160 + *
  161 + * @param roleId 角色ID
  162 + * @param userIds 需要删除的用户数据ID
  163 + * @return 结果
  164 + */
  165 + public int insertAuthUsers(Long roleId, Long[] userIds);
139 } 166 }
@@ -19,6 +19,22 @@ public interface ISysUserService @@ -19,6 +19,22 @@ public interface ISysUserService
19 public List<SysUser> selectUserList(SysUser user); 19 public List<SysUser> selectUserList(SysUser user);
20 20
21 /** 21 /**
  22 + * 根据条件分页查询已分配用户角色列表
  23 + *
  24 + * @param user 用户信息
  25 + * @return 用户信息集合信息
  26 + */
  27 + public List<SysUser> selectAllocatedList(SysUser user);
  28 +
  29 + /**
  30 + * 根据条件分页查询未分配用户角色列表
  31 + *
  32 + * @param user 用户信息
  33 + * @return 用户信息集合信息
  34 + */
  35 + public List<SysUser> selectUnallocatedList(SysUser user);
  36 +
  37 + /**
22 * 通过用户名查询用户 38 * 通过用户名查询用户
23 * 39 *
24 * @param userName 用户名 40 * @param userName 用户名
@@ -16,6 +16,7 @@ import com.ruoyi.common.utils.StringUtils; @@ -16,6 +16,7 @@ import com.ruoyi.common.utils.StringUtils;
16 import com.ruoyi.common.utils.spring.SpringUtils; 16 import com.ruoyi.common.utils.spring.SpringUtils;
17 import com.ruoyi.system.domain.SysRoleDept; 17 import com.ruoyi.system.domain.SysRoleDept;
18 import com.ruoyi.system.domain.SysRoleMenu; 18 import com.ruoyi.system.domain.SysRoleMenu;
  19 +import com.ruoyi.system.domain.SysUserRole;
19 import com.ruoyi.system.mapper.SysRoleDeptMapper; 20 import com.ruoyi.system.mapper.SysRoleDeptMapper;
20 import com.ruoyi.system.mapper.SysRoleMapper; 21 import com.ruoyi.system.mapper.SysRoleMapper;
21 import com.ruoyi.system.mapper.SysRoleMenuMapper; 22 import com.ruoyi.system.mapper.SysRoleMenuMapper;
@@ -350,4 +351,51 @@ public class SysRoleServiceImpl implements ISysRoleService @@ -350,4 +351,51 @@ public class SysRoleServiceImpl implements ISysRoleService
350 roleDeptMapper.deleteRoleDept(roleIds); 351 roleDeptMapper.deleteRoleDept(roleIds);
351 return roleMapper.deleteRoleByIds(roleIds); 352 return roleMapper.deleteRoleByIds(roleIds);
352 } 353 }
  354 +
  355 + /**
  356 + * 取消授权用户角色
  357 + *
  358 + * @param userRole 用户和角色关联信息
  359 + * @return 结果
  360 + */
  361 + @Override
  362 + public int deleteAuthUser(SysUserRole userRole)
  363 + {
  364 + return userRoleMapper.deleteUserRoleInfo(userRole);
  365 + }
  366 +
  367 + /**
  368 + * 批量取消授权用户角色
  369 + *
  370 + * @param roleId 角色ID
  371 + * @param userIds 需要取消授权的用户数据ID
  372 + * @return 结果
  373 + */
  374 + @Override
  375 + public int deleteAuthUsers(Long roleId, Long[] userIds)
  376 + {
  377 + return userRoleMapper.deleteUserRoleInfos(roleId, userIds);
  378 + }
  379 +
  380 + /**
  381 + * 批量选择授权用户角色
  382 + *
  383 + * @param roleId 角色ID
  384 + * @param userIds 需要删除的用户数据ID
  385 + * @return 结果
  386 + */
  387 + @Override
  388 + public int insertAuthUsers(Long roleId, Long[] userIds)
  389 + {
  390 + // 新增用户与角色管理
  391 + List<SysUserRole> list = new ArrayList<SysUserRole>();
  392 + for (Long userId : userIds)
  393 + {
  394 + SysUserRole ur = new SysUserRole();
  395 + ur.setUserId(userId);
  396 + ur.setRoleId(roleId);
  397 + list.add(ur);
  398 + }
  399 + return userRoleMapper.batchUserRole(list);
  400 + }
353 } 401 }
@@ -67,6 +67,32 @@ public class SysUserServiceImpl implements ISysUserService @@ -67,6 +67,32 @@ public class SysUserServiceImpl implements ISysUserService
67 } 67 }
68 68
69 /** 69 /**
  70 + * 根据条件分页查询已分配用户角色列表
  71 + *
  72 + * @param user 用户信息
  73 + * @return 用户信息集合信息
  74 + */
  75 + @Override
  76 + @DataScope(deptAlias = "d", userAlias = "u")
  77 + public List<SysUser> selectAllocatedList(SysUser user)
  78 + {
  79 + return userMapper.selectAllocatedList(user);
  80 + }
  81 +
  82 + /**
  83 + * 根据条件分页查询未分配用户角色列表
  84 + *
  85 + * @param user 用户信息
  86 + * @return 用户信息集合信息
  87 + */
  88 + @Override
  89 + @DataScope(deptAlias = "d", userAlias = "u")
  90 + public List<SysUser> selectUnallocatedList(SysUser user)
  91 + {
  92 + return userMapper.selectUnallocatedList(user);
  93 + }
  94 +
  95 + /**
70 * 通过用户名查询用户 96 * 通过用户名查询用户
71 * 97 *
72 * @param userName 用户名 98 * @param userName 用户名
@@ -248,6 +274,7 @@ public class SysUserServiceImpl implements ISysUserService @@ -248,6 +274,7 @@ public class SysUserServiceImpl implements ISysUserService
248 * @param userId 用户ID 274 * @param userId 用户ID
249 * @param roleIds 角色组 275 * @param roleIds 角色组
250 */ 276 */
  277 + @Override
251 public void insertUserAuth(Long userId, Long[] roleIds) 278 public void insertUserAuth(Long userId, Long[] roleIds)
252 { 279 {
253 userRoleMapper.deleteUserRoleByUserId(userId); 280 userRoleMapper.deleteUserRoleByUserId(userId);
@@ -81,6 +81,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -81,6 +81,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
81 ${params.dataScope} 81 ${params.dataScope}
82 </select> 82 </select>
83 83
  84 + <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
  85 + select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
  86 + from sys_user u
  87 + left join sys_dept d on u.dept_id = d.dept_id
  88 + left join sys_user_role ur on u.user_id = ur.user_id
  89 + left join sys_role r on r.role_id = ur.role_id
  90 + where u.del_flag = '0' and r.role_id = #{roleId}
  91 + <if test="userName != null and userName != ''">
  92 + AND u.user_name like concat('%', #{userName}, '%')
  93 + </if>
  94 + <if test="phonenumber != null and phonenumber != ''">
  95 + AND u.phonenumber like concat('%', #{phonenumber}, '%')
  96 + </if>
  97 + <!-- 数据范围过滤 -->
  98 + ${params.dataScope}
  99 + </select>
  100 +
  101 + <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
  102 + select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
  103 + from sys_user u
  104 + left join sys_dept d on u.dept_id = d.dept_id
  105 + left join sys_user_role ur on u.user_id = ur.user_id
  106 + left join sys_role r on r.role_id = ur.role_id
  107 + where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
  108 + and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId})
  109 + <if test="userName != null and userName != ''">
  110 + AND u.user_name like concat('%', #{userName}, '%')
  111 + </if>
  112 + <if test="phonenumber != null and phonenumber != ''">
  113 + AND u.phonenumber like concat('%', #{phonenumber}, '%')
  114 + </if>
  115 + <!-- 数据范围过滤 -->
  116 + ${params.dataScope}
  117 + </select>
  118 +
84 <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult"> 119 <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
85 <include refid="selectUserVo"/> 120 <include refid="selectUserVo"/>
86 where u.user_name = #{userName} 121 where u.user_name = #{userName}
@@ -73,3 +73,48 @@ export function exportRole(query) { @@ -73,3 +73,48 @@ export function exportRole(query) {
73 params: query 73 params: query
74 }) 74 })
75 } 75 }
  76 +
  77 +// 查询角色已授权用户列表
  78 +export function allocatedUserList(query) {
  79 + return request({
  80 + url: '/system/role/authUser/allocatedList',
  81 + method: 'get',
  82 + params: query
  83 + })
  84 +}
  85 +
  86 +// 查询角色未授权用户列表
  87 +export function unallocatedUserList(query) {
  88 + return request({
  89 + url: '/system/role/authUser/unallocatedList',
  90 + method: 'get',
  91 + params: query
  92 + })
  93 +}
  94 +
  95 +// 取消用户授权角色
  96 +export function authUserCancel(data) {
  97 + return request({
  98 + url: '/system/role/authUser/cancel',
  99 + method: 'put',
  100 + data: data
  101 + })
  102 +}
  103 +
  104 +// 批量取消用户授权角色
  105 +export function authUserCancelAll(data) {
  106 + return request({
  107 + url: '/system/role/authUser/cancelAll',
  108 + method: 'put',
  109 + params: data
  110 + })
  111 +}
  112 +
  113 +// 授权用户选择
  114 +export function authUserSelectAll(data) {
  115 + return request({
  116 + url: '/system/role/authUser/selectAll',
  117 + method: 'put',
  118 + params: data
  119 + })
  120 +}
@@ -94,6 +94,19 @@ export const constantRoutes = [ @@ -94,6 +94,19 @@ export const constantRoutes = [
94 ] 94 ]
95 }, 95 },
96 { 96 {
  97 + path: '/auth',
  98 + component: Layout,
  99 + hidden: true,
  100 + children: [
  101 + {
  102 + path: 'user/:roleId(\\d+)',
  103 + component: (resolve) => require(['@/views/system/role/authUser'], resolve),
  104 + name: 'AuthUser',
  105 + meta: { title: '分配用户'}
  106 + }
  107 + ]
  108 + },
  109 + {
97 path: '/dict', 110 path: '/dict',
98 component: Layout, 111 component: Layout,
99 hidden: true, 112 hidden: true,
  1 +<template>
  2 + <div class="app-container">
  3 + <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
  4 + <el-form-item label="用户名称" prop="userName">
  5 + <el-input
  6 + v-model="queryParams.userName"
  7 + placeholder="请输入用户名称"
  8 + clearable
  9 + size="small"
  10 + style="width: 240px"
  11 + @keyup.enter.native="handleQuery"
  12 + />
  13 + </el-form-item>
  14 + <el-form-item label="手机号码" prop="phonenumber">
  15 + <el-input
  16 + v-model="queryParams.phonenumber"
  17 + placeholder="请输入手机号码"
  18 + clearable
  19 + size="small"
  20 + style="width: 240px"
  21 + @keyup.enter.native="handleQuery"
  22 + />
  23 + </el-form-item>
  24 + <el-form-item>
  25 + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  26 + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  27 + </el-form-item>
  28 + </el-form>
  29 +
  30 + <el-row :gutter="10" class="mb8">
  31 + <el-col :span="1.5">
  32 + <el-button
  33 + type="primary"
  34 + plain
  35 + icon="el-icon-plus"
  36 + size="mini"
  37 + @click="openSelectUser"
  38 + v-hasPermi="['system:role:add']"
  39 + >添加用户</el-button>
  40 + </el-col>
  41 + <el-col :span="1.5">
  42 + <el-button
  43 + type="danger"
  44 + plain
  45 + icon="el-icon-circle-close"
  46 + size="mini"
  47 + :disabled="multiple"
  48 + @click="cancelAuthUserAll"
  49 + v-hasPermi="['system:role:remove']"
  50 + >批量取消授权</el-button>
  51 + </el-col>
  52 + <el-col :span="1.5">
  53 + <el-button
  54 + type="warning"
  55 + plain
  56 + icon="el-icon-close"
  57 + size="mini"
  58 + @click="handleClose"
  59 + >关闭</el-button>
  60 + </el-col>
  61 + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  62 + </el-row>
  63 +
  64 + <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  65 + <el-table-column type="selection" width="55" align="center" />
  66 + <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
  67 + <el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true" />
  68 + <el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" />
  69 + <el-table-column label="手机" prop="phonenumber" :show-overflow-tooltip="true" />
  70 + <el-table-column label="状态" align="center" prop="status">
  71 + <template slot-scope="scope">
  72 + <dict-tag :options="statusOptions" :value="scope.row.status"/>
  73 + </template>
  74 + </el-table-column>
  75 + <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  76 + <template slot-scope="scope">
  77 + <span>{{ parseTime(scope.row.createTime) }}</span>
  78 + </template>
  79 + </el-table-column>
  80 + <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  81 + <template slot-scope="scope">
  82 + <el-button
  83 + size="mini"
  84 + type="text"
  85 + icon="el-icon-circle-close"
  86 + @click="cancelAuthUser(scope.row)"
  87 + v-hasPermi="['system:role:remove']"
  88 + >取消授权</el-button>
  89 + </template>
  90 + </el-table-column>
  91 + </el-table>
  92 +
  93 + <pagination
  94 + v-show="total>0"
  95 + :total="total"
  96 + :page.sync="queryParams.pageNum"
  97 + :limit.sync="queryParams.pageSize"
  98 + @pagination="getList"
  99 + />
  100 + <select-user ref="select" :roleId="queryParams.roleId" @ok="handleQuery" />
  101 + </div>
  102 +</template>
  103 +
  104 +<script>
  105 +import { allocatedUserList, authUserCancel, authUserCancelAll } from "@/api/system/role";
  106 +import selectUser from "./selectUser";
  107 +
  108 +export default {
  109 + name: "AuthUser",
  110 + components: { selectUser },
  111 + data() {
  112 + return {
  113 + // 遮罩层
  114 + loading: true,
  115 + // 选中用户组
  116 + userIds: [],
  117 + // 非多个禁用
  118 + multiple: true,
  119 + // 显示搜索条件
  120 + showSearch: true,
  121 + // 总条数
  122 + total: 0,
  123 + // 用户表格数据
  124 + userList: [],
  125 + // 状态数据字典
  126 + statusOptions: [],
  127 + // 查询参数
  128 + queryParams: {
  129 + pageNum: 1,
  130 + pageSize: 10,
  131 + roleId: undefined,
  132 + userName: undefined,
  133 + phonenumber: undefined
  134 + }
  135 + };
  136 + },
  137 + created() {
  138 + const roleId = this.$route.params && this.$route.params.roleId;
  139 + if (roleId) {
  140 + this.queryParams.roleId = roleId;
  141 + this.getList();
  142 + this.getDicts("sys_normal_disable").then(response => {
  143 + this.statusOptions = response.data;
  144 + });
  145 + }
  146 + },
  147 + methods: {
  148 + /** 查询授权用户列表 */
  149 + getList() {
  150 + this.loading = true;
  151 + allocatedUserList(this.queryParams).then(response => {
  152 + this.userList = response.rows;
  153 + this.total = response.total;
  154 + this.loading = false;
  155 + }
  156 + );
  157 + },
  158 + // 返回按钮
  159 + handleClose() {
  160 + this.$store.dispatch("tagsView/delView", this.$route);
  161 + this.$router.push({ path: "/system/role" });
  162 + },
  163 + /** 搜索按钮操作 */
  164 + handleQuery() {
  165 + this.queryParams.pageNum = 1;
  166 + this.getList();
  167 + },
  168 + /** 重置按钮操作 */
  169 + resetQuery() {
  170 + this.resetForm("queryForm");
  171 + this.handleQuery();
  172 + },
  173 + // 多选框选中数据
  174 + handleSelectionChange(selection) {
  175 + this.userIds = selection.map(item => item.userId)
  176 + this.multiple = !selection.length
  177 + },
  178 + /** 打开授权用户表弹窗 */
  179 + openSelectUser() {
  180 + this.$refs.select.show();
  181 + },
  182 + /** 取消授权按钮操作 */
  183 + cancelAuthUser(row) {
  184 + const roleId = this.queryParams.roleId;
  185 + this.$confirm('确认要取消该用户"' + row.userName + '"角色吗?', "警告", {
  186 + confirmButtonText: "确定",
  187 + cancelButtonText: "取消",
  188 + type: "warning"
  189 + }).then(function() {
  190 + return authUserCancel({ userId: row.userId, roleId: roleId });
  191 + }).then(() => {
  192 + this.getList();
  193 + this.msgSuccess("取消授权成功");
  194 + }).catch(() => {});
  195 + },
  196 + /** 批量取消授权按钮操作 */
  197 + cancelAuthUserAll(row) {
  198 + const roleId = this.queryParams.roleId;
  199 + const userIds = this.userIds.join(",");
  200 + this.$confirm('是否取消选中用户授权数据项?', "警告", {
  201 + confirmButtonText: "确定",
  202 + cancelButtonText: "取消",
  203 + type: "warning"
  204 + }).then(() => {
  205 + return authUserCancelAll({ roleId: roleId, userIds: userIds });
  206 + }).then(() => {
  207 + this.getList();
  208 + this.msgSuccess("取消授权成功");
  209 + }).catch(() => {});
  210 + }
  211 + }
  212 +};
  213 +</script>
@@ -135,17 +135,21 @@ @@ -135,17 +135,21 @@
135 <el-button 135 <el-button
136 size="mini" 136 size="mini"
137 type="text" 137 type="text"
138 - icon="el-icon-circle-check"  
139 - @click="handleDataScope(scope.row)"  
140 - v-hasPermi="['system:role:edit']"  
141 - >数据权限</el-button>  
142 - <el-button  
143 - size="mini"  
144 - type="text"  
145 icon="el-icon-delete" 138 icon="el-icon-delete"
146 @click="handleDelete(scope.row)" 139 @click="handleDelete(scope.row)"
147 v-hasPermi="['system:role:remove']" 140 v-hasPermi="['system:role:remove']"
148 >删除</el-button> 141 >删除</el-button>
  142 + <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
  143 + <span class="el-dropdown-link">
  144 + <i class="el-icon-d-arrow-right el-icon--right"></i>更多
  145 + </span>
  146 + <el-dropdown-menu slot="dropdown">
  147 + <el-dropdown-item command="handleDataScope" icon="el-icon-circle-check"
  148 + v-hasPermi="['system:role:edit']">数据权限</el-dropdown-item>
  149 + <el-dropdown-item command="handleAuthUser" icon="el-icon-user"
  150 + v-hasPermi="['system:role:edit']">分配用户</el-dropdown-item>
  151 + </el-dropdown-menu>
  152 + </el-dropdown>
149 </template> 153 </template>
150 </el-table-column> 154 </el-table-column>
151 </el-table> 155 </el-table>
@@ -469,6 +473,19 @@ export default { @@ -469,6 +473,19 @@ export default {
469 this.single = selection.length!=1 473 this.single = selection.length!=1
470 this.multiple = !selection.length 474 this.multiple = !selection.length
471 }, 475 },
  476 + // 更多操作触发
  477 + handleCommand(command, row) {
  478 + switch (command) {
  479 + case "handleDataScope":
  480 + this.handleDataScope(row);
  481 + break;
  482 + case "handleAuthUser":
  483 + this.handleAuthUser(row);
  484 + break;
  485 + default:
  486 + break;
  487 + }
  488 + },
472 // 树权限(展开/折叠) 489 // 树权限(展开/折叠)
473 handleCheckedTreeExpand(value, type) { 490 handleCheckedTreeExpand(value, type) {
474 if (type == 'menu') { 491 if (type == 'menu') {
@@ -548,6 +565,11 @@ export default { @@ -548,6 +565,11 @@ export default {
548 this.title = "分配数据权限"; 565 this.title = "分配数据权限";
549 }); 566 });
550 }, 567 },
  568 + /** 分配用户操作 */
  569 + handleAuthUser: function(row) {
  570 + const roleId = row.roleId;
  571 + this.$router.push("/auth/user/" + roleId);
  572 + },
551 /** 提交按钮 */ 573 /** 提交按钮 */
552 submitForm: function() { 574 submitForm: function() {
553 this.$refs["form"].validate(valid => { 575 this.$refs["form"].validate(valid => {
  1 +<template>
  2 + <!-- 授权用户 -->
  3 + <el-dialog title="选择用户" :visible.sync="visible" width="800px" top="5vh" append-to-body>
  4 + <el-form :model="queryParams" ref="queryForm" :inline="true">
  5 + <el-form-item label="用户名称" prop="userName">
  6 + <el-input
  7 + v-model="queryParams.userName"
  8 + placeholder="请输入用户名称"
  9 + clearable
  10 + size="small"
  11 + @keyup.enter.native="handleQuery"
  12 + />
  13 + </el-form-item>
  14 + <el-form-item label="手机号码" prop="phonenumber">
  15 + <el-input
  16 + v-model="queryParams.phonenumber"
  17 + placeholder="请输入手机号码"
  18 + clearable
  19 + size="small"
  20 + @keyup.enter.native="handleQuery"
  21 + />
  22 + </el-form-item>
  23 + <el-form-item>
  24 + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25 + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26 + </el-form-item>
  27 + </el-form>
  28 + <el-row>
  29 + <el-table @row-click="clickRow" ref="table" :data="userList" @selection-change="handleSelectionChange" height="260px">
  30 + <el-table-column type="selection" width="55"></el-table-column>
  31 + <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
  32 + <el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true" />
  33 + <el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" />
  34 + <el-table-column label="手机" prop="phonenumber" :show-overflow-tooltip="true" />
  35 + <el-table-column label="状态" align="center" prop="status">
  36 + <template slot-scope="scope">
  37 + <dict-tag :options="statusOptions" :value="scope.row.status"/>
  38 + </template>
  39 + </el-table-column>
  40 + <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  41 + <template slot-scope="scope">
  42 + <span>{{ parseTime(scope.row.createTime) }}</span>
  43 + </template>
  44 + </el-table-column>
  45 + </el-table>
  46 + <pagination
  47 + v-show="total>0"
  48 + :total="total"
  49 + :page.sync="queryParams.pageNum"
  50 + :limit.sync="queryParams.pageSize"
  51 + @pagination="getList"
  52 + />
  53 + </el-row>
  54 + <div slot="footer" class="dialog-footer">
  55 + <el-button type="primary" @click="handleSelectUser">确 定</el-button>
  56 + <el-button @click="visible = false">取 消</el-button>
  57 + </div>
  58 + </el-dialog>
  59 +</template>
  60 +
  61 +<script>
  62 +import { unallocatedUserList, authUserSelectAll } from "@/api/system/role";
  63 +export default {
  64 + props: {
  65 + // 角色编号
  66 + roleId: {
  67 + type: Number
  68 + }
  69 + },
  70 + data() {
  71 + return {
  72 + // 遮罩层
  73 + visible: false,
  74 + // 选中数组值
  75 + userIds: [],
  76 + // 总条数
  77 + total: 0,
  78 + // 未授权用户数据
  79 + userList: [],
  80 + // 状态数据字典
  81 + statusOptions: [],
  82 + // 查询参数
  83 + queryParams: {
  84 + pageNum: 1,
  85 + pageSize: 10,
  86 + roleId: undefined,
  87 + userName: undefined,
  88 + phonenumber: undefined
  89 + }
  90 + };
  91 + },
  92 + created() {
  93 + this.getDicts("sys_normal_disable").then(response => {
  94 + this.statusOptions = response.data;
  95 + });
  96 + },
  97 + methods: {
  98 + // 显示弹框
  99 + show() {
  100 + this.queryParams.roleId = this.roleId;
  101 + this.getList();
  102 + this.visible = true;
  103 + },
  104 + clickRow(row) {
  105 + this.$refs.table.toggleRowSelection(row);
  106 + },
  107 + // 多选框选中数据
  108 + handleSelectionChange(selection) {
  109 + this.userIds = selection.map(item => item.userId);
  110 + },
  111 + // 查询表数据
  112 + getList() {
  113 + unallocatedUserList(this.queryParams).then(res => {
  114 + this.userList = res.rows;
  115 + this.total = res.total;
  116 + });
  117 + },
  118 + /** 搜索按钮操作 */
  119 + handleQuery() {
  120 + this.queryParams.pageNum = 1;
  121 + this.getList();
  122 + },
  123 + /** 重置按钮操作 */
  124 + resetQuery() {
  125 + this.resetForm("queryForm");
  126 + this.handleQuery();
  127 + },
  128 + /** 选择授权用户操作 */
  129 + handleSelectUser() {
  130 + const roleId = this.queryParams.roleId;
  131 + const userIds = this.userIds.join(",");
  132 + authUserSelectAll({ roleId: roleId, userIds: userIds }).then(res => {
  133 + this.msgSuccess(res.msg);
  134 + if (res.code === 200) {
  135 + this.visible = false;
  136 + this.$emit("ok");
  137 + }
  138 + });
  139 + }
  140 + }
  141 +};
  142 +</script>