authUser.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
  4. <el-form-item label="用户名称" prop="userName">
  5. <el-input
  6. v-model="queryParams.userName"
  7. placeholder="请输入用户名称"
  8. clearable
  9. style="width: 240px"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="手机号码" prop="phonenumber">
  14. <el-input
  15. v-model="queryParams.phonenumber"
  16. placeholder="请输入手机号码"
  17. clearable
  18. style="width: 240px"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  24. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  25. </el-form-item>
  26. </el-form>
  27. <el-row :gutter="10" class="mb8">
  28. <el-col :span="1.5">
  29. <el-button
  30. type="primary"
  31. plain
  32. icon="el-icon-plus"
  33. size="mini"
  34. @click="openSelectUser"
  35. v-hasPermi="['system:role:add']"
  36. >添加用户</el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button
  40. type="danger"
  41. plain
  42. icon="el-icon-circle-close"
  43. size="mini"
  44. :disabled="multiple"
  45. @click="cancelAuthUserAll"
  46. v-hasPermi="['system:role:remove']"
  47. >批量取消授权</el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="warning"
  52. plain
  53. icon="el-icon-close"
  54. size="mini"
  55. @click="handleClose"
  56. >关闭</el-button>
  57. </el-col>
  58. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  59. </el-row>
  60. <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  61. <el-table-column type="selection" width="55" align="center" />
  62. <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
  63. <el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true" />
  64. <el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" />
  65. <el-table-column label="手机" prop="phonenumber" :show-overflow-tooltip="true" />
  66. <el-table-column label="状态" align="center" prop="status">
  67. <template slot-scope="scope">
  68. <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  72. <template slot-scope="scope">
  73. <span>{{ parseTime(scope.row.createTime) }}</span>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  77. <template slot-scope="scope">
  78. <el-button
  79. size="mini"
  80. type="text"
  81. icon="el-icon-circle-close"
  82. @click="cancelAuthUser(scope.row)"
  83. v-hasPermi="['system:role:remove']"
  84. >取消授权</el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <pagination
  89. v-show="total>0"
  90. :total="total"
  91. :page.sync="queryParams.pageNum"
  92. :limit.sync="queryParams.pageSize"
  93. @pagination="getList"
  94. />
  95. <department-user-select
  96. ref="userSelect"
  97. :visible.sync="selectUserVisible"
  98. :extra-params="{ roleId: queryParams.roleId }"
  99. select-mode="single"
  100. @confirm="handleConfirm"
  101. />
  102. </div>
  103. </template>
  104. <script>
  105. import { allocatedUserList, authUserCancel, authUserCancelAll, authUserSelectAll } from "@/api/system/role";
  106. import DepartmentUserSelect from "@/components/UserSelect";
  107. export default {
  108. name: "AuthUser",
  109. dicts: ['sys_normal_disable'],
  110. components: { DepartmentUserSelect },
  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. selectUserVisible: false,
  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. }
  143. },
  144. methods: {
  145. /** 查询授权用户列表 */
  146. getList() {
  147. this.loading = true;
  148. allocatedUserList(this.queryParams).then(response => {
  149. this.userList = response.rows;
  150. this.total = response.total;
  151. this.loading = false;
  152. }
  153. );
  154. },
  155. // 返回按钮
  156. handleClose() {
  157. const obj = { path: "/system/role" };
  158. this.$tab.closeOpenPage(obj);
  159. },
  160. /** 搜索按钮操作 */
  161. handleQuery() {
  162. this.queryParams.pageNum = 1;
  163. this.getList();
  164. },
  165. /** 重置按钮操作 */
  166. resetQuery() {
  167. this.resetForm("queryForm");
  168. this.handleQuery();
  169. },
  170. // 多选框选中数据
  171. handleSelectionChange(selection) {
  172. this.userIds = selection.map(item => item.userId)
  173. this.multiple = !selection.length
  174. },
  175. /** 打开授权用户表弹窗 */
  176. openSelectUser() {
  177. this.selectUserVisible = true;
  178. },
  179. /** 处理用户选择确认 */
  180. handleConfirm(data) {
  181. const { roleId, userIds } = data;
  182. if (!userIds || userIds.length === 0) {
  183. this.$modal.msgError("请选择要分配的用户");
  184. return;
  185. }
  186. const userIdsStr = Array.isArray(userIds) ? userIds.join(",") : userIds;
  187. // 调用API授权用户
  188. authUserSelectAll({ roleId: roleId, userIds: userIdsStr }).then(res => {
  189. this.$modal.msgSuccess(res.msg);
  190. if (res.code === 200) {
  191. this.selectUserVisible = false;
  192. this.getList();
  193. }
  194. });
  195. },
  196. /** 取消授权按钮操作 */
  197. cancelAuthUser(row) {
  198. const roleId = this.queryParams.roleId;
  199. this.$modal.confirm('确认要取消该用户"' + row.userName + '"角色吗?').then(function() {
  200. return authUserCancel({ userId: row.userId, roleId: roleId });
  201. }).then(() => {
  202. this.getList();
  203. this.$modal.msgSuccess("取消授权成功");
  204. }).catch(() => {});
  205. },
  206. /** 批量取消授权按钮操作 */
  207. cancelAuthUserAll(row) {
  208. const roleId = this.queryParams.roleId;
  209. const userIds = this.userIds.join(",");
  210. this.$modal.confirm('是否取消选中用户授权数据项?').then(function() {
  211. return authUserCancelAll({ roleId: roleId, userIds: userIds });
  212. }).then(() => {
  213. this.getList();
  214. this.$modal.msgSuccess("取消授权成功");
  215. }).catch(() => {});
  216. }
  217. }
  218. };
  219. </script>