From 90c41d498c98ba872f20250c0025303a07bfa894 Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期一, 05 七月 2021 14:54:09 +0800 Subject: [PATCH] 角色管理新增分配用户功能 --- ruoyi-ui/src/views/system/role/selectUser.vue | 142 +++++++++++ ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml | 35 ++ ruoyi-ui/src/api/system/role.js | 45 +++ ruoyi-ui/src/views/system/role/authUser.vue | 213 +++++++++++++++++ ruoyi-ui/src/views/system/role/index.vue | 36 ++ ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java | 27 ++ ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java | 27 ++ ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java | 57 ++++ ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java | 16 + ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java | 13 + ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java | 16 + ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java | 48 ++++ ruoyi-ui/src/router/index.js | 13 + 13 files changed, 681 insertions(+), 7 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java index a7cce44..d479805 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRoleController.java @@ -17,6 +17,7 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; @@ -26,6 +27,7 @@ import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.web.service.SysPermissionService; import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.domain.SysUserRole; import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysUserService; @@ -179,4 +181,59 @@ { return AjaxResult.success(roleService.selectRoleAll()); } + + /** + * 鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛� + */ + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/authUser/allocatedList") + public TableDataInfo allocatedList(SysUser user) + { + startPage(); + List<SysUser> list = userService.selectAllocatedList(user); + return getDataTable(list); + } + + /** + * 鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛� + */ + @PreAuthorize("@ss.hasPermi('system:role:list')") + @GetMapping("/authUser/unallocatedList") + public TableDataInfo unallocatedList(SysUser user) + { + startPage(); + List<SysUser> list = userService.selectUnallocatedList(user); + return getDataTable(list); + } + + /** + * 鍙栨秷鎺堟潈鐢ㄦ埛 + */ + @PreAuthorize("@ss.hasPermi('system:role:edit')") + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancel") + public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole) + { + return toAjax(roleService.deleteAuthUser(userRole)); + } + + /** + * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛 + */ + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/cancelAll") + public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds) + { + return toAjax(roleService.deleteAuthUsers(roleId, userIds)); + } + + /** + * 鎵归噺閫夋嫨鐢ㄦ埛鎺堟潈 + */ + @Log(title = "瑙掕壊绠$悊", businessType = BusinessType.GRANT) + @PutMapping("/authUser/selectAll") + public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds) + { + return toAjax(roleService.insertAuthUsers(roleId, userIds)); + } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java index 4c35925..7504f02 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java @@ -92,6 +92,9 @@ /** 宀椾綅缁� */ private Long[] postIds; + /** 瑙掕壊ID */ + private Long roleId; + public SysUser() { @@ -300,6 +303,16 @@ this.postIds = postIds; } + public Long getRoleId() + { + return roleId; + } + + public void setRoleId(Long roleId) + { + this.roleId = roleId; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index b9937f3..9190c9e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -20,6 +20,22 @@ public List<SysUser> selectUserList(SysUser sysUser); /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鏈凡閰嶇敤鎴疯鑹插垪琛� + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + public List<SysUser> selectAllocatedList(SysUser user); + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛� + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + public List<SysUser> selectUnallocatedList(SysUser user); + + /** * 閫氳繃鐢ㄦ埛鍚嶆煡璇㈢敤鎴� * * @param userName 鐢ㄦ埛鍚� diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java index 846ef6e..05824bc 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.Set; import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.system.domain.SysUserRole; /** * 瑙掕壊涓氬姟灞� @@ -136,4 +137,30 @@ * @return 缁撴灉 */ public int deleteRoleByIds(Long[] roleIds); + + /** + * 鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param userRole 鐢ㄦ埛鍜岃鑹插叧鑱斾俊鎭� + * @return 缁撴灉 + */ + public int deleteAuthUser(SysUserRole userRole); + + /** + * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇�瑕佸彇娑堟巿鏉冪殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + public int deleteAuthUsers(Long roleId, Long[] userIds); + + /** + * 鎵归噺閫夋嫨鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇�瑕佸垹闄ょ殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + public int insertAuthUsers(Long roleId, Long[] userIds); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java index 5bf1488..d284e96 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java @@ -19,6 +19,22 @@ public List<SysUser> selectUserList(SysUser user); /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛� + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + public List<SysUser> selectAllocatedList(SysUser user); + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛� + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + public List<SysUser> selectUnallocatedList(SysUser user); + + /** * 閫氳繃鐢ㄦ埛鍚嶆煡璇㈢敤鎴� * * @param userName 鐢ㄦ埛鍚� diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index 409baf0..2d36686 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -16,6 +16,7 @@ import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.domain.SysRoleDept; import com.ruoyi.system.domain.SysRoleMenu; +import com.ruoyi.system.domain.SysUserRole; import com.ruoyi.system.mapper.SysRoleDeptMapper; import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.mapper.SysRoleMenuMapper; @@ -350,4 +351,51 @@ roleDeptMapper.deleteRoleDept(roleIds); return roleMapper.deleteRoleByIds(roleIds); } + + /** + * 鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param userRole 鐢ㄦ埛鍜岃鑹插叧鑱斾俊鎭� + * @return 缁撴灉 + */ + @Override + public int deleteAuthUser(SysUserRole userRole) + { + return userRoleMapper.deleteUserRoleInfo(userRole); + } + + /** + * 鎵归噺鍙栨秷鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇�瑕佸彇娑堟巿鏉冪殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + @Override + public int deleteAuthUsers(Long roleId, Long[] userIds) + { + return userRoleMapper.deleteUserRoleInfos(roleId, userIds); + } + + /** + * 鎵归噺閫夋嫨鎺堟潈鐢ㄦ埛瑙掕壊 + * + * @param roleId 瑙掕壊ID + * @param userIds 闇�瑕佸垹闄ょ殑鐢ㄦ埛鏁版嵁ID + * @return 缁撴灉 + */ + @Override + public int insertAuthUsers(Long roleId, Long[] userIds) + { + // 鏂板鐢ㄦ埛涓庤鑹茬鐞� + List<SysUserRole> list = new ArrayList<SysUserRole>(); + for (Long userId : userIds) + { + SysUserRole ur = new SysUserRole(); + ur.setUserId(userId); + ur.setRoleId(roleId); + list.add(ur); + } + return userRoleMapper.batchUserRole(list); + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index 3da7490..81b350a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -67,6 +67,32 @@ } /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛� + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + @Override + @DataScope(deptAlias = "d", userAlias = "u") + public List<SysUser> selectAllocatedList(SysUser user) + { + return userMapper.selectAllocatedList(user); + } + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛� + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + @Override + @DataScope(deptAlias = "d", userAlias = "u") + public List<SysUser> selectUnallocatedList(SysUser user) + { + return userMapper.selectUnallocatedList(user); + } + + /** * 閫氳繃鐢ㄦ埛鍚嶆煡璇㈢敤鎴� * * @param userName 鐢ㄦ埛鍚� @@ -248,6 +274,7 @@ * @param userId 鐢ㄦ埛ID * @param roleIds 瑙掕壊缁� */ + @Override public void insertUserAuth(Long userId, Long[] roleIds) { userRoleMapper.deleteUserRoleByUserId(userId); diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index 13e1bea..9dddd39 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -81,6 +81,41 @@ ${params.dataScope} </select> + <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult"> + select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time + from sys_user u + left join sys_dept d on u.dept_id = d.dept_id + left join sys_user_role ur on u.user_id = ur.user_id + left join sys_role r on r.role_id = ur.role_id + where u.del_flag = '0' and r.role_id = #{roleId} + <if test="userName != null and userName != ''"> + AND u.user_name like concat('%', #{userName}, '%') + </if> + <if test="phonenumber != null and phonenumber != ''"> + AND u.phonenumber like concat('%', #{phonenumber}, '%') + </if> + <!-- 鏁版嵁鑼冨洿杩囨护 --> + ${params.dataScope} + </select> + + <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult"> + select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time + from sys_user u + left join sys_dept d on u.dept_id = d.dept_id + left join sys_user_role ur on u.user_id = ur.user_id + left join sys_role r on r.role_id = ur.role_id + where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL) + 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}) + <if test="userName != null and userName != ''"> + AND u.user_name like concat('%', #{userName}, '%') + </if> + <if test="phonenumber != null and phonenumber != ''"> + AND u.phonenumber like concat('%', #{phonenumber}, '%') + </if> + <!-- 鏁版嵁鑼冨洿杩囨护 --> + ${params.dataScope} + </select> + <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult"> <include refid="selectUserVo"/> where u.user_name = #{userName} diff --git a/ruoyi-ui/src/api/system/role.js b/ruoyi-ui/src/api/system/role.js index 736708c..aa426df 100644 --- a/ruoyi-ui/src/api/system/role.js +++ b/ruoyi-ui/src/api/system/role.js @@ -72,4 +72,49 @@ method: 'get', params: query }) +} + +// 鏌ヨ瑙掕壊宸叉巿鏉冪敤鎴峰垪琛� +export function allocatedUserList(query) { + return request({ + url: '/system/role/authUser/allocatedList', + method: 'get', + params: query + }) +} + +// 鏌ヨ瑙掕壊鏈巿鏉冪敤鎴峰垪琛� +export function unallocatedUserList(query) { + return request({ + url: '/system/role/authUser/unallocatedList', + method: 'get', + params: query + }) +} + +// 鍙栨秷鐢ㄦ埛鎺堟潈瑙掕壊 +export function authUserCancel(data) { + return request({ + url: '/system/role/authUser/cancel', + method: 'put', + data: data + }) +} + +// 鎵归噺鍙栨秷鐢ㄦ埛鎺堟潈瑙掕壊 +export function authUserCancelAll(data) { + return request({ + url: '/system/role/authUser/cancelAll', + method: 'put', + params: data + }) +} + +// 鎺堟潈鐢ㄦ埛閫夋嫨 +export function authUserSelectAll(data) { + return request({ + url: '/system/role/authUser/selectAll', + method: 'put', + params: data + }) } \ No newline at end of file diff --git a/ruoyi-ui/src/router/index.js b/ruoyi-ui/src/router/index.js index 67fca82..0de4c2f 100644 --- a/ruoyi-ui/src/router/index.js +++ b/ruoyi-ui/src/router/index.js @@ -94,6 +94,19 @@ ] }, { + path: '/auth', + component: Layout, + hidden: true, + children: [ + { + path: 'user/:roleId(\\d+)', + component: (resolve) => require(['@/views/system/role/authUser'], resolve), + name: 'AuthUser', + meta: { title: '鍒嗛厤鐢ㄦ埛'} + } + ] + }, + { path: '/dict', component: Layout, hidden: true, diff --git a/ruoyi-ui/src/views/system/role/authUser.vue b/ruoyi-ui/src/views/system/role/authUser.vue new file mode 100644 index 0000000..a65ccbf --- /dev/null +++ b/ruoyi-ui/src/views/system/role/authUser.vue @@ -0,0 +1,213 @@ +<template> + <div class="app-container"> + <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true"> + <el-form-item label="鐢ㄦ埛鍚嶇О" prop="userName"> + <el-input + v-model="queryParams.userName" + placeholder="璇疯緭鍏ョ敤鎴峰悕绉�" + clearable + size="small" + style="width: 240px" + @keyup.enter.native="handleQuery" + /> + </el-form-item> + <el-form-item label="鎵嬫満鍙风爜" prop="phonenumber"> + <el-input + v-model="queryParams.phonenumber" + placeholder="璇疯緭鍏ユ墜鏈哄彿鐮�" + clearable + size="small" + style="width: 240px" + @keyup.enter.native="handleQuery" + /> + </el-form-item> + <el-form-item> + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">鎼滅储</el-button> + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">閲嶇疆</el-button> + </el-form-item> + </el-form> + + <el-row :gutter="10" class="mb8"> + <el-col :span="1.5"> + <el-button + type="primary" + plain + icon="el-icon-plus" + size="mini" + @click="openSelectUser" + v-hasPermi="['system:role:add']" + >娣诲姞鐢ㄦ埛</el-button> + </el-col> + <el-col :span="1.5"> + <el-button + type="danger" + plain + icon="el-icon-circle-close" + size="mini" + :disabled="multiple" + @click="cancelAuthUserAll" + v-hasPermi="['system:role:remove']" + >鎵归噺鍙栨秷鎺堟潈</el-button> + </el-col> + <el-col :span="1.5"> + <el-button + type="warning" + plain + icon="el-icon-close" + size="mini" + @click="handleClose" + >鍏抽棴</el-button> + </el-col> + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> + </el-row> + + <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange"> + <el-table-column type="selection" width="55" align="center" /> + <el-table-column label="鐢ㄦ埛鍚嶇О" prop="userName" :show-overflow-tooltip="true" /> + <el-table-column label="鐢ㄦ埛鏄电О" prop="nickName" :show-overflow-tooltip="true" /> + <el-table-column label="閭" prop="email" :show-overflow-tooltip="true" /> + <el-table-column label="鎵嬫満" prop="phonenumber" :show-overflow-tooltip="true" /> + <el-table-column label="鐘舵��" align="center" prop="status"> + <template slot-scope="scope"> + <dict-tag :options="statusOptions" :value="scope.row.status"/> + </template> + </el-table-column> + <el-table-column label="鍒涘缓鏃堕棿" align="center" prop="createTime" width="180"> + <template slot-scope="scope"> + <span>{{ parseTime(scope.row.createTime) }}</span> + </template> + </el-table-column> + <el-table-column label="鎿嶄綔" align="center" class-name="small-padding fixed-width"> + <template slot-scope="scope"> + <el-button + size="mini" + type="text" + icon="el-icon-circle-close" + @click="cancelAuthUser(scope.row)" + v-hasPermi="['system:role:remove']" + >鍙栨秷鎺堟潈</el-button> + </template> + </el-table-column> + </el-table> + + <pagination + v-show="total>0" + :total="total" + :page.sync="queryParams.pageNum" + :limit.sync="queryParams.pageSize" + @pagination="getList" + /> + <select-user ref="select" :roleId="queryParams.roleId" @ok="handleQuery" /> + </div> +</template> + +<script> +import { allocatedUserList, authUserCancel, authUserCancelAll } from "@/api/system/role"; +import selectUser from "./selectUser"; + +export default { + name: "AuthUser", + components: { selectUser }, + data() { + return { + // 閬僵灞� + loading: true, + // 閫変腑鐢ㄦ埛缁� + userIds: [], + // 闈炲涓鐢� + multiple: true, + // 鏄剧ず鎼滅储鏉′欢 + showSearch: true, + // 鎬绘潯鏁� + total: 0, + // 鐢ㄦ埛琛ㄦ牸鏁版嵁 + userList: [], + // 鐘舵�佹暟鎹瓧鍏� + statusOptions: [], + // 鏌ヨ鍙傛暟 + queryParams: { + pageNum: 1, + pageSize: 10, + roleId: undefined, + userName: undefined, + phonenumber: undefined + } + }; + }, + created() { + const roleId = this.$route.params && this.$route.params.roleId; + if (roleId) { + this.queryParams.roleId = roleId; + this.getList(); + this.getDicts("sys_normal_disable").then(response => { + this.statusOptions = response.data; + }); + } + }, + methods: { + /** 鏌ヨ鎺堟潈鐢ㄦ埛鍒楄〃 */ + getList() { + this.loading = true; + allocatedUserList(this.queryParams).then(response => { + this.userList = response.rows; + this.total = response.total; + this.loading = false; + } + ); + }, + // 杩斿洖鎸夐挳 + handleClose() { + this.$store.dispatch("tagsView/delView", this.$route); + this.$router.push({ path: "/system/role" }); + }, + /** 鎼滅储鎸夐挳鎿嶄綔 */ + handleQuery() { + this.queryParams.pageNum = 1; + this.getList(); + }, + /** 閲嶇疆鎸夐挳鎿嶄綔 */ + resetQuery() { + this.resetForm("queryForm"); + this.handleQuery(); + }, + // 澶氶�夋閫変腑鏁版嵁 + handleSelectionChange(selection) { + this.userIds = selection.map(item => item.userId) + this.multiple = !selection.length + }, + /** 鎵撳紑鎺堟潈鐢ㄦ埛琛ㄥ脊绐� */ + openSelectUser() { + this.$refs.select.show(); + }, + /** 鍙栨秷鎺堟潈鎸夐挳鎿嶄綔 */ + cancelAuthUser(row) { + const roleId = this.queryParams.roleId; + this.$confirm('纭瑕佸彇娑堣鐢ㄦ埛"' + row.userName + '"瑙掕壊鍚楋紵', "璀﹀憡", { + confirmButtonText: "纭畾", + cancelButtonText: "鍙栨秷", + type: "warning" + }).then(function() { + return authUserCancel({ userId: row.userId, roleId: roleId }); + }).then(() => { + this.getList(); + this.msgSuccess("鍙栨秷鎺堟潈鎴愬姛"); + }).catch(() => {}); + }, + /** 鎵归噺鍙栨秷鎺堟潈鎸夐挳鎿嶄綔 */ + cancelAuthUserAll(row) { + const roleId = this.queryParams.roleId; + const userIds = this.userIds.join(","); + this.$confirm('鏄惁鍙栨秷閫変腑鐢ㄦ埛鎺堟潈鏁版嵁椤�?', "璀﹀憡", { + confirmButtonText: "纭畾", + cancelButtonText: "鍙栨秷", + type: "warning" + }).then(() => { + return authUserCancelAll({ roleId: roleId, userIds: userIds }); + }).then(() => { + this.getList(); + this.msgSuccess("鍙栨秷鎺堟潈鎴愬姛"); + }).catch(() => {}); + } + } +}; +</script> \ No newline at end of file diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index 70c1dc4..af824da 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -135,17 +135,21 @@ <el-button size="mini" type="text" - icon="el-icon-circle-check" - @click="handleDataScope(scope.row)" - v-hasPermi="['system:role:edit']" - >鏁版嵁鏉冮檺</el-button> - <el-button - size="mini" - type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:role:remove']" >鍒犻櫎</el-button> + <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"> + <span class="el-dropdown-link"> + <i class="el-icon-d-arrow-right el-icon--right"></i>鏇村 + </span> + <el-dropdown-menu slot="dropdown"> + <el-dropdown-item command="handleDataScope" icon="el-icon-circle-check" + v-hasPermi="['system:role:edit']">鏁版嵁鏉冮檺</el-dropdown-item> + <el-dropdown-item command="handleAuthUser" icon="el-icon-user" + v-hasPermi="['system:role:edit']">鍒嗛厤鐢ㄦ埛</el-dropdown-item> + </el-dropdown-menu> + </el-dropdown> </template> </el-table-column> </el-table> @@ -469,6 +473,19 @@ this.single = selection.length!=1 this.multiple = !selection.length }, + // 鏇村鎿嶄綔瑙﹀彂 + handleCommand(command, row) { + switch (command) { + case "handleDataScope": + this.handleDataScope(row); + break; + case "handleAuthUser": + this.handleAuthUser(row); + break; + default: + break; + } + }, // 鏍戞潈闄愶紙灞曞紑/鎶樺彔锛� handleCheckedTreeExpand(value, type) { if (type == 'menu') { @@ -548,6 +565,11 @@ this.title = "鍒嗛厤鏁版嵁鏉冮檺"; }); }, + /** 鍒嗛厤鐢ㄦ埛鎿嶄綔 */ + handleAuthUser: function(row) { + const roleId = row.roleId; + this.$router.push("/auth/user/" + roleId); + }, /** 鎻愪氦鎸夐挳 */ submitForm: function() { this.$refs["form"].validate(valid => { diff --git a/ruoyi-ui/src/views/system/role/selectUser.vue b/ruoyi-ui/src/views/system/role/selectUser.vue new file mode 100644 index 0000000..14ae0bb --- /dev/null +++ b/ruoyi-ui/src/views/system/role/selectUser.vue @@ -0,0 +1,142 @@ +<template> + <!-- 鎺堟潈鐢ㄦ埛 --> + <el-dialog title="閫夋嫨鐢ㄦ埛" :visible.sync="visible" width="800px" top="5vh" append-to-body> + <el-form :model="queryParams" ref="queryForm" :inline="true"> + <el-form-item label="鐢ㄦ埛鍚嶇О" prop="userName"> + <el-input + v-model="queryParams.userName" + placeholder="璇疯緭鍏ョ敤鎴峰悕绉�" + clearable + size="small" + @keyup.enter.native="handleQuery" + /> + </el-form-item> + <el-form-item label="鎵嬫満鍙风爜" prop="phonenumber"> + <el-input + v-model="queryParams.phonenumber" + placeholder="璇疯緭鍏ユ墜鏈哄彿鐮�" + clearable + size="small" + @keyup.enter.native="handleQuery" + /> + </el-form-item> + <el-form-item> + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">鎼滅储</el-button> + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">閲嶇疆</el-button> + </el-form-item> + </el-form> + <el-row> + <el-table @row-click="clickRow" ref="table" :data="userList" @selection-change="handleSelectionChange" height="260px"> + <el-table-column type="selection" width="55"></el-table-column> + <el-table-column label="鐢ㄦ埛鍚嶇О" prop="userName" :show-overflow-tooltip="true" /> + <el-table-column label="鐢ㄦ埛鏄电О" prop="nickName" :show-overflow-tooltip="true" /> + <el-table-column label="閭" prop="email" :show-overflow-tooltip="true" /> + <el-table-column label="鎵嬫満" prop="phonenumber" :show-overflow-tooltip="true" /> + <el-table-column label="鐘舵��" align="center" prop="status"> + <template slot-scope="scope"> + <dict-tag :options="statusOptions" :value="scope.row.status"/> + </template> + </el-table-column> + <el-table-column label="鍒涘缓鏃堕棿" align="center" prop="createTime" width="180"> + <template slot-scope="scope"> + <span>{{ parseTime(scope.row.createTime) }}</span> + </template> + </el-table-column> + </el-table> + <pagination + v-show="total>0" + :total="total" + :page.sync="queryParams.pageNum" + :limit.sync="queryParams.pageSize" + @pagination="getList" + /> + </el-row> + <div slot="footer" class="dialog-footer"> + <el-button type="primary" @click="handleSelectUser">纭� 瀹�</el-button> + <el-button @click="visible = false">鍙� 娑�</el-button> + </div> + </el-dialog> +</template> + +<script> +import { unallocatedUserList, authUserSelectAll } from "@/api/system/role"; +export default { + props: { + // 瑙掕壊缂栧彿 + roleId: { + type: Number + } + }, + data() { + return { + // 閬僵灞� + visible: false, + // 閫変腑鏁扮粍鍊� + userIds: [], + // 鎬绘潯鏁� + total: 0, + // 鏈巿鏉冪敤鎴锋暟鎹� + userList: [], + // 鐘舵�佹暟鎹瓧鍏� + statusOptions: [], + // 鏌ヨ鍙傛暟 + queryParams: { + pageNum: 1, + pageSize: 10, + roleId: undefined, + userName: undefined, + phonenumber: undefined + } + }; + }, + created() { + this.getDicts("sys_normal_disable").then(response => { + this.statusOptions = response.data; + }); + }, + methods: { + // 鏄剧ず寮规 + show() { + this.queryParams.roleId = this.roleId; + this.getList(); + this.visible = true; + }, + clickRow(row) { + this.$refs.table.toggleRowSelection(row); + }, + // 澶氶�夋閫変腑鏁版嵁 + handleSelectionChange(selection) { + this.userIds = selection.map(item => item.userId); + }, + // 鏌ヨ琛ㄦ暟鎹� + getList() { + unallocatedUserList(this.queryParams).then(res => { + this.userList = res.rows; + this.total = res.total; + }); + }, + /** 鎼滅储鎸夐挳鎿嶄綔 */ + handleQuery() { + this.queryParams.pageNum = 1; + this.getList(); + }, + /** 閲嶇疆鎸夐挳鎿嶄綔 */ + resetQuery() { + this.resetForm("queryForm"); + this.handleQuery(); + }, + /** 閫夋嫨鎺堟潈鐢ㄦ埛鎿嶄綔 */ + handleSelectUser() { + const roleId = this.queryParams.roleId; + const userIds = this.userIds.join(","); + authUserSelectAll({ roleId: roleId, userIds: userIds }).then(res => { + this.msgSuccess(res.msg); + if (res.code === 200) { + this.visible = false; + this.$emit("ok"); + } + }); + } + } +}; +</script> -- Gitblit v1.9.3