authUser.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. <select-user ref="select" :roleId="queryParams.roleId" @ok="handleQuery" />
  96. </div>
  97. </template>
  98. <script>
  99. import { allocatedUserList, authUserCancel, authUserCancelAll } from "@/api/system/role";
  100. import selectUser from "./selectUser";
  101. export default {
  102. name: "AuthUser",
  103. dicts: ['sys_normal_disable'],
  104. components: { selectUser },
  105. data() {
  106. return {
  107. // 遮罩层
  108. loading: true,
  109. // 选中用户组
  110. userIds: [],
  111. // 非多个禁用
  112. multiple: true,
  113. // 显示搜索条件
  114. showSearch: true,
  115. // 总条数
  116. total: 0,
  117. // 用户表格数据
  118. userList: [],
  119. // 查询参数
  120. queryParams: {
  121. pageNum: 1,
  122. pageSize: 10,
  123. roleId: undefined,
  124. userName: undefined,
  125. phonenumber: undefined
  126. }
  127. };
  128. },
  129. created() {
  130. const roleId = this.$route.params && this.$route.params.roleId;
  131. if (roleId) {
  132. this.queryParams.roleId = roleId;
  133. this.getList();
  134. }
  135. },
  136. methods: {
  137. /** 查询授权用户列表 */
  138. getList() {
  139. this.loading = true;
  140. allocatedUserList(this.queryParams).then(response => {
  141. this.userList = response.rows;
  142. this.total = response.total;
  143. this.loading = false;
  144. }
  145. );
  146. },
  147. // 返回按钮
  148. handleClose() {
  149. const obj = { path: "/system/role" };
  150. this.$tab.closeOpenPage(obj);
  151. },
  152. /** 搜索按钮操作 */
  153. handleQuery() {
  154. this.queryParams.pageNum = 1;
  155. this.getList();
  156. },
  157. /** 重置按钮操作 */
  158. resetQuery() {
  159. this.resetForm("queryForm");
  160. this.handleQuery();
  161. },
  162. // 多选框选中数据
  163. handleSelectionChange(selection) {
  164. this.userIds = selection.map(item => item.userId)
  165. this.multiple = !selection.length
  166. },
  167. /** 打开授权用户表弹窗 */
  168. openSelectUser() {
  169. this.$refs.select.show();
  170. },
  171. /** 取消授权按钮操作 */
  172. cancelAuthUser(row) {
  173. const roleId = this.queryParams.roleId;
  174. this.$modal.confirm('确认要取消该用户"' + row.userName + '"角色吗?').then(function() {
  175. return authUserCancel({ userId: row.userId, roleId: roleId });
  176. }).then(() => {
  177. this.getList();
  178. this.$modal.msgSuccess("取消授权成功");
  179. }).catch(() => {});
  180. },
  181. /** 批量取消授权按钮操作 */
  182. cancelAuthUserAll(row) {
  183. const roleId = this.queryParams.roleId;
  184. const userIds = this.userIds.join(",");
  185. this.$modal.confirm('是否取消选中用户授权数据项?').then(function() {
  186. return authUserCancelAll({ roleId: roleId, userIds: userIds });
  187. }).then(() => {
  188. this.getList();
  189. this.$modal.msgSuccess("取消授权成功");
  190. }).catch(() => {});
  191. }
  192. }
  193. };
  194. </script>