authUser.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. <el-row :gutter="10" class="mb8">
  30. <el-col :span="1.5">
  31. <el-button
  32. type="primary"
  33. plain
  34. icon="el-icon-plus"
  35. size="mini"
  36. @click="openSelectUser"
  37. v-hasPermi="['system:role:add']"
  38. >添加用户</el-button>
  39. </el-col>
  40. <el-col :span="1.5">
  41. <el-button
  42. type="danger"
  43. plain
  44. icon="el-icon-circle-close"
  45. size="mini"
  46. :disabled="multiple"
  47. @click="cancelAuthUserAll"
  48. v-hasPermi="['system:role:remove']"
  49. >批量取消授权</el-button>
  50. </el-col>
  51. <el-col :span="1.5">
  52. <el-button
  53. type="warning"
  54. plain
  55. icon="el-icon-close"
  56. size="mini"
  57. @click="handleClose"
  58. >关闭</el-button>
  59. </el-col>
  60. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  61. </el-row>
  62. <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  63. <el-table-column type="selection" width="55" align="center" />
  64. <el-table-column label="用户名称" prop="userName" :show-overflow-tooltip="true" />
  65. <el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true" />
  66. <el-table-column label="邮箱" prop="email" :show-overflow-tooltip="true" />
  67. <el-table-column label="手机" prop="phonenumber" :show-overflow-tooltip="true" />
  68. <el-table-column label="状态" align="center" prop="status">
  69. <template slot-scope="scope">
  70. <dict-tag :options="statusOptions" :value="scope.row.status"/>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  74. <template slot-scope="scope">
  75. <span>{{ parseTime(scope.row.createTime) }}</span>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  79. <template slot-scope="scope">
  80. <el-button
  81. size="mini"
  82. type="text"
  83. icon="el-icon-circle-close"
  84. @click="cancelAuthUser(scope.row)"
  85. v-hasPermi="['system:role:remove']"
  86. >取消授权</el-button>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. <pagination
  91. v-show="total>0"
  92. :total="total"
  93. :page.sync="queryParams.pageNum"
  94. :limit.sync="queryParams.pageSize"
  95. @pagination="getList"
  96. />
  97. <select-user ref="select" :roleId="queryParams.roleId" @ok="handleQuery" />
  98. </div>
  99. </template>
  100. <script>
  101. import { allocatedUserList, authUserCancel, authUserCancelAll } from "@/api/system/role";
  102. import selectUser from "./selectUser";
  103. export default {
  104. name: "AuthUser",
  105. components: { selectUser },
  106. data() {
  107. return {
  108. // 遮罩层
  109. loading: true,
  110. // 选中用户组
  111. userIds: [],
  112. // 非多个禁用
  113. multiple: true,
  114. // 显示搜索条件
  115. showSearch: true,
  116. // 总条数
  117. total: 0,
  118. // 用户表格数据
  119. userList: [],
  120. // 状态数据字典
  121. statusOptions: [],
  122. // 查询参数
  123. queryParams: {
  124. pageNum: 1,
  125. pageSize: 10,
  126. roleId: undefined,
  127. userName: undefined,
  128. phonenumber: undefined
  129. }
  130. };
  131. },
  132. created() {
  133. const roleId = this.$route.params && this.$route.params.roleId;
  134. if (roleId) {
  135. this.queryParams.roleId = roleId;
  136. this.getList();
  137. this.getDicts("sys_normal_disable").then(response => {
  138. this.statusOptions = response.data;
  139. });
  140. }
  141. },
  142. methods: {
  143. /** 查询授权用户列表 */
  144. getList() {
  145. this.loading = true;
  146. allocatedUserList(this.queryParams).then(response => {
  147. this.userList = response.rows;
  148. this.total = response.total;
  149. this.loading = false;
  150. }
  151. );
  152. },
  153. // 返回按钮
  154. handleClose() {
  155. this.$store.dispatch("tagsView/delView", this.$route);
  156. this.$router.push({ path: "/system/role" });
  157. },
  158. /** 搜索按钮操作 */
  159. handleQuery() {
  160. this.queryParams.pageNum = 1;
  161. this.getList();
  162. },
  163. /** 重置按钮操作 */
  164. resetQuery() {
  165. this.resetForm("queryForm");
  166. this.handleQuery();
  167. },
  168. // 多选框选中数据
  169. handleSelectionChange(selection) {
  170. this.userIds = selection.map(item => item.userId)
  171. this.multiple = !selection.length
  172. },
  173. /** 打开授权用户表弹窗 */
  174. openSelectUser() {
  175. this.$refs.select.show();
  176. },
  177. /** 取消授权按钮操作 */
  178. cancelAuthUser(row) {
  179. const roleId = this.queryParams.roleId;
  180. this.$confirm('确认要取消该用户"' + row.userName + '"角色吗?', "警告", {
  181. confirmButtonText: "确定",
  182. cancelButtonText: "取消",
  183. type: "warning"
  184. }).then(function() {
  185. return authUserCancel({ userId: row.userId, roleId: roleId });
  186. }).then(() => {
  187. this.getList();
  188. this.msgSuccess("取消授权成功");
  189. }).catch(() => {});
  190. },
  191. /** 批量取消授权按钮操作 */
  192. cancelAuthUserAll(row) {
  193. const roleId = this.queryParams.roleId;
  194. const userIds = this.userIds.join(",");
  195. this.$confirm('是否取消选中用户授权数据项?', "警告", {
  196. confirmButtonText: "确定",
  197. cancelButtonText: "取消",
  198. type: "warning"
  199. }).then(() => {
  200. return authUserCancelAll({ roleId: roleId, userIds: userIds });
  201. }).then(() => {
  202. this.getList();
  203. this.msgSuccess("取消授权成功");
  204. }).catch(() => {});
  205. }
  206. }
  207. };
  208. </script>