Procházet zdrojové kódy

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

RuoYi před 4 roky
rodič
revize
0b0da91139

+ 13 - 1
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java

@@ -91,6 +91,9 @@ public class SysUser extends BaseEntity
91 91
     /** 岗位组 */
92 92
     private Long[] postIds;
93 93
 
94
+    /** 角色ID */
95
+    private Long roleId;
96
+
94 97
     public SysUser()
95 98
     {
96 99
 
@@ -297,7 +300,16 @@ public class SysUser extends BaseEntity
297 300
     {
298 301
         this.postIds = postIds;
299 302
     }
300
-    
303
+
304
+    public Long getRoleId()
305
+    {
306
+        return roleId;
307
+    }
308
+
309
+    public void setRoleId(Long roleId)
310
+    {
311
+        this.roleId = roleId;
312
+    }
301 313
     @Override
302 314
     public String toString() {
303 315
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 62 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysRoleController.java

@@ -23,7 +23,10 @@ import com.ruoyi.common.log.annotation.Log;
23 23
 import com.ruoyi.common.log.enums.BusinessType;
24 24
 import com.ruoyi.common.security.annotation.PreAuthorize;
25 25
 import com.ruoyi.system.api.domain.SysRole;
26
+import com.ruoyi.system.api.domain.SysUser;
27
+import com.ruoyi.system.domain.SysUserRole;
26 28
 import com.ruoyi.system.service.ISysRoleService;
29
+import com.ruoyi.system.service.ISysUserService;
27 30
 
28 31
 /**
29 32
  * 角色信息
@@ -37,6 +40,9 @@ public class SysRoleController extends BaseController
37 40
     @Autowired
38 41
     private ISysRoleService roleService;
39 42
 
43
+    @Autowired
44
+    private ISysUserService userService;
45
+
40 46
     @PreAuthorize(hasPermi = "system:role:list")
41 47
     @GetMapping("/list")
42 48
     public TableDataInfo list(SysRole role)
@@ -153,4 +159,60 @@ public class SysRoleController extends BaseController
153 159
     {
154 160
         return AjaxResult.success(roleService.selectRoleAll());
155 161
     }
162
+    /**
163
+     * 查询已分配用户角色列表
164
+     */
165
+    @PreAuthorize(hasPermi = "system:role:list")
166
+    @GetMapping("/authUser/allocatedList")
167
+    public TableDataInfo allocatedList(SysUser user)
168
+    {
169
+        startPage();
170
+        List<SysUser> list = userService.selectAllocatedList(user);
171
+        return getDataTable(list);
172
+    }
173
+
174
+    /**
175
+     * 查询未分配用户角色列表
176
+     */
177
+    @PreAuthorize(hasPermi = "system:role:list")
178
+    @GetMapping("/authUser/unallocatedList")
179
+    public TableDataInfo unallocatedList(SysUser user)
180
+    {
181
+        startPage();
182
+        List<SysUser> list = userService.selectUnallocatedList(user);
183
+        return getDataTable(list);
184
+    }
185
+
186
+    /**
187
+     * 取消授权用户
188
+     */
189
+    @PreAuthorize(hasPermi = "system:role:edit")
190
+    @Log(title = "角色管理", businessType = BusinessType.GRANT)
191
+    @PutMapping("/authUser/cancel")
192
+    public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
193
+    {
194
+        return toAjax(roleService.deleteAuthUser(userRole));
195
+    }
196
+
197
+    /**
198
+     * 批量取消授权用户
199
+     */
200
+    @PreAuthorize(hasPermi = "system:role:edit")
201
+    @Log(title = "角色管理", businessType = BusinessType.GRANT)
202
+    @PutMapping("/authUser/cancelAll")
203
+    public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
204
+    {
205
+        return toAjax(roleService.deleteAuthUsers(roleId, userIds));
206
+    }
207
+
208
+    /**
209
+     * 批量选择用户授权
210
+     */
211
+    @PreAuthorize(hasPermi = "system:role:edit")
212
+    @Log(title = "角色管理", businessType = BusinessType.GRANT)
213
+    @PutMapping("/authUser/selectAll")
214
+    public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
215
+    {
216
+        return toAjax(roleService.insertAuthUsers(roleId, userIds));
217
+    }
156 218
 }

+ 15 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java

@@ -1,9 +1,7 @@
1 1
 package com.ruoyi.system.mapper;
2 2
 
3 3
 import java.util.List;
4
-
5 4
 import org.apache.ibatis.annotations.Param;
6
-
7 5
 import com.ruoyi.system.api.domain.SysUser;
8 6
 
9 7
 /**
@@ -20,6 +18,21 @@ public interface SysUserMapper
20 18
      * @return 用户信息集合信息
21 19
      */
22 20
     public List<SysUser> selectUserList(SysUser sysUser);
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);
23 36
 
24 37
     /**
25 38
      * 通过用户名查询用户

+ 26 - 1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java

@@ -2,8 +2,8 @@ package com.ruoyi.system.service;
2 2
 
3 3
 import java.util.List;
4 4
 import java.util.Set;
5
-
6 5
 import com.ruoyi.system.api.domain.SysRole;
6
+import com.ruoyi.system.domain.SysUserRole;
7 7
 
8 8
 /**
9 9
  * 角色业务层
@@ -137,4 +137,29 @@ public interface ISysRoleService
137 137
      * @return 结果
138 138
      */
139 139
     public int deleteRoleByIds(Long[] roleIds);
140
+    /**
141
+     * 取消授权用户角色
142
+     * 
143
+     * @param userRole 用户和角色关联信息
144
+     * @return 结果
145
+     */
146
+    public int deleteAuthUser(SysUserRole userRole);
147
+
148
+    /**
149
+     * 批量取消授权用户角色
150
+     * 
151
+     * @param roleId 角色ID
152
+     * @param userIds 需要取消授权的用户数据ID
153
+     * @return 结果
154
+     */
155
+    public int deleteAuthUsers(Long roleId, Long[] userIds);
156
+
157
+    /**
158
+     * 批量选择授权用户角色
159
+     * 
160
+     * @param roleId 角色ID
161
+     * @param userIds 需要删除的用户数据ID
162
+     * @return 结果
163
+     */
164
+    public int insertAuthUsers(Long roleId, Long[] userIds);
140 165
 }

+ 16 - 1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

@@ -1,7 +1,6 @@
1 1
 package com.ruoyi.system.service;
2 2
 
3 3
 import java.util.List;
4
-
5 4
 import com.ruoyi.system.api.domain.SysUser;
6 5
 
7 6
 /**
@@ -20,6 +19,22 @@ public interface ISysUserService
20 19
     public List<SysUser> selectUserList(SysUser user);
21 20
 
22 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
+    /**
23 38
      * 通过用户名查询用户
24 39
      * 
25 40
      * @param userName 用户名

+ 48 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java

@@ -16,6 +16,7 @@ import com.ruoyi.common.datascope.annotation.DataScope;
16 16
 import com.ruoyi.system.api.domain.SysRole;
17 17
 import com.ruoyi.system.domain.SysRoleDept;
18 18
 import com.ruoyi.system.domain.SysRoleMenu;
19
+import com.ruoyi.system.domain.SysUserRole;
19 20
 import com.ruoyi.system.mapper.SysRoleDeptMapper;
20 21
 import com.ruoyi.system.mapper.SysRoleMapper;
21 22
 import com.ruoyi.system.mapper.SysRoleMenuMapper;
@@ -350,4 +351,51 @@ public class SysRoleServiceImpl implements ISysRoleService
350 351
         roleDeptMapper.deleteRoleDept(roleIds);
351 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
 }

+ 27 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -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 98
      * @param userName 用户名
@@ -248,6 +274,7 @@ public class SysUserServiceImpl implements ISysUserService
248 274
      * @param userId 用户ID
249 275
      * @param roleIds 角色组
250 276
      */
277
+    @Override
251 278
     public void insertUserAuth(Long userId, Long[] roleIds)
252 279
     {
253 280
         userRoleMapper.deleteUserRoleByUserId(userId);

+ 35 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -81,6 +81,41 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
81 81
 		${params.dataScope}
82 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 119
 	<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
85 120
 	    <include refid="selectUserVo"/>
86 121
 		where u.user_name = #{userName}

+ 44 - 0
ruoyi-ui/src/api/system/role.js

@@ -64,3 +64,47 @@ export function delRole(roleId) {
64 64
     method: 'delete'
65 65
   })
66 66
 }
67
+// 查询角色已授权用户列表
68
+export function allocatedUserList(query) {
69
+  return request({
70
+    url: '/system/role/authUser/allocatedList',
71
+    method: 'get',
72
+    params: query
73
+  })
74
+}
75
+
76
+// 查询角色未授权用户列表
77
+export function unallocatedUserList(query) {
78
+  return request({
79
+    url: '/system/role/authUser/unallocatedList',
80
+    method: 'get',
81
+    params: query
82
+  })
83
+}
84
+
85
+// 取消用户授权角色
86
+export function authUserCancel(data) {
87
+  return request({
88
+    url: '/system/role/authUser/cancel',
89
+    method: 'put',
90
+    data: data
91
+  })
92
+}
93
+
94
+// 批量取消用户授权角色
95
+export function authUserCancelAll(data) {
96
+  return request({
97
+    url: '/system/role/authUser/cancelAll',
98
+    method: 'put',
99
+    params: data
100
+  })
101
+}
102
+
103
+// 授权用户选择
104
+export function authUserSelectAll(data) {
105
+  return request({
106
+    url: '/system/role/authUser/selectAll',
107
+    method: 'put',
108
+    params: data
109
+  })
110
+}

+ 13 - 0
ruoyi-ui/src/router/index.js

@@ -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 110
     path: '/dict',
98 111
     component: Layout,
99 112
     hidden: true,

+ 213 - 0
ruoyi-ui/src/views/system/role/authUser.vue

@@ -0,0 +1,213 @@
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>

+ 30 - 8
ruoyi-ui/src/views/system/role/index.vue

@@ -123,7 +123,7 @@
123 123
         </template>
124 124
       </el-table-column>
125 125
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
126
-        <template slot-scope="scope">
126
+        <template slot-scope="scope" v-if="scope.row.roleId !== 1">
127 127
           <el-button
128 128
             size="mini"
129 129
             type="text"
@@ -134,17 +134,21 @@
134 134
           <el-button
135 135
             size="mini"
136 136
             type="text"
137
-            icon="el-icon-circle-check"
138
-            @click="handleDataScope(scope.row)"
139
-            v-hasPermi="['system:role:edit']"
140
-          >数据权限</el-button>
141
-          <el-button
142
-            size="mini"
143
-            type="text"
144 137
             icon="el-icon-delete"
145 138
             @click="handleDelete(scope.row)"
146 139
             v-hasPermi="['system:role:remove']"
147 140
           >删除</el-button>
141
+          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
142
+            <span class="el-dropdown-link">
143
+              <i class="el-icon-d-arrow-right el-icon--right"></i>更多
144
+            </span>
145
+            <el-dropdown-menu slot="dropdown">
146
+              <el-dropdown-item command="handleDataScope" icon="el-icon-circle-check"
147
+                v-hasPermi="['system:role:edit']">数据权限</el-dropdown-item>
148
+              <el-dropdown-item command="handleAuthUser" icon="el-icon-user"
149
+                v-hasPermi="['system:role:edit']">分配用户</el-dropdown-item>
150
+            </el-dropdown-menu>
151
+          </el-dropdown>
148 152
         </template>
149 153
       </el-table-column>
150 154
     </el-table>
@@ -466,6 +470,19 @@ export default {
466 470
       this.single = selection.length!=1
467 471
       this.multiple = !selection.length
468 472
     },
473
+    // 更多操作触发
474
+    handleCommand(command, row) {
475
+      switch (command) {
476
+        case "handleDataScope":
477
+          this.handleDataScope(row);
478
+          break;
479
+        case "handleAuthUser":
480
+          this.handleAuthUser(row);
481
+          break;
482
+        default:
483
+          break;
484
+      }
485
+    },
469 486
     // 树权限(展开/折叠)
470 487
     handleCheckedTreeExpand(value, type) {
471 488
       if (type == 'menu') {
@@ -545,6 +562,11 @@ export default {
545 562
         this.title = "分配数据权限";
546 563
       });
547 564
     },
565
+    /** 分配用户操作 */
566
+    handleAuthUser: function(row) {
567
+      const roleId = row.roleId;
568
+      this.$router.push("/auth/user/" + roleId);
569
+    },
548 570
     /** 提交按钮 */
549 571
     submitForm: function() {
550 572
       this.$refs["form"].validate(valid => {

+ 142 - 0
ruoyi-ui/src/views/system/role/selectUser.vue

@@ -0,0 +1,142 @@
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>

+ 9 - 7
ruoyi-ui/src/views/system/user/index.vue

@@ -166,7 +166,7 @@
166 166
             width="160"
167 167
             class-name="small-padding fixed-width"
168 168
           >
169
-            <template slot-scope="scope">
169
+            <template slot-scope="scope" v-if="scope.row.userId !== 1">
170 170
               <el-button
171 171
                 size="mini"
172 172
                 type="text"
@@ -174,13 +174,18 @@
174 174
                 @click="handleUpdate(scope.row)"
175 175
                 v-hasPermi="['system:user:edit']"
176 176
               >修改</el-button>
177
+              <el-button
178
+                size="mini"
179
+                type="text"
180
+                icon="el-icon-delete"
181
+                @click="handleDelete(scope.row)"
182
+                v-hasPermi="['system:user:remove']"
183
+              >删除</el-button>
177 184
               <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
178 185
                 <span class="el-dropdown-link">
179
-                  <i class="el-icon-d-arrow-right el-icon--right"></i>更多操作
186
+                  <i class="el-icon-d-arrow-right el-icon--right"></i>更多
180 187
                 </span>
181 188
                 <el-dropdown-menu slot="dropdown">
182
-                  <el-dropdown-item command="handleDelete" v-if="scope.row.userId !== 1" icon="el-icon-delete"
183
-                    v-hasPermi="['system:user:remove']">删除用户</el-dropdown-item>
184 189
                   <el-dropdown-item command="handleResetPwd" icon="el-icon-key"
185 190
                     v-hasPermi="['system:user:resetPwd']">重置密码</el-dropdown-item>
186 191
                   <el-dropdown-item command="handleAuthRole" icon="el-icon-circle-check"
@@ -559,9 +564,6 @@ export default {
559 564
     // 更多操作触发
560 565
     handleCommand(command, row) {
561 566
       switch (command) {
562
-        case "handleDelete":
563
-          this.handleDelete(row);
564
-          break;
565 567
         case "handleResetPwd":
566 568
           this.handleResetPwd(row);
567 569
           break;