AdminUserManage.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="user-manage">
  3. <div class="part-box part-box-filter part-box-flex">
  4. <el-form ref="FilterForm" label-position="left" label-width="85px" inline>
  5. <el-form-item label="姓名:" label-width="75px">
  6. <el-input
  7. style="width: 142px;"
  8. v-model.trim="filter.realName"
  9. placeholder="请输入内容"
  10. clearable
  11. ></el-input>
  12. </el-form-item>
  13. <el-form-item label="启用/禁用:" label-width="90px">
  14. <el-select
  15. v-model="filter.enable"
  16. style="width: 142px;"
  17. placeholder="请选择"
  18. clearable
  19. >
  20. <el-option
  21. v-for="(val, key) in ABLE_TYPE"
  22. :key="key"
  23. :value="key * 1"
  24. :label="val"
  25. ></el-option>
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item label-width="0px">
  29. <el-button type="primary" icon="el-icon-search" @click="toPage(1)"
  30. >查询</el-button
  31. >
  32. </el-form-item>
  33. </el-form>
  34. <div class="part-box-action">
  35. <el-button
  36. type="primary"
  37. icon="el-icon-circle-plus-outline"
  38. @click="toAdd"
  39. >新增用户</el-button
  40. >
  41. </div>
  42. </div>
  43. <div class="part-box">
  44. <el-table ref="TableList" :data="users" border stripe>
  45. <el-table-column
  46. type="index"
  47. label="序号"
  48. width="70"
  49. align="center"
  50. :index="indexMethod"
  51. ></el-table-column>
  52. <el-table-column prop="loginName" label="用户名"></el-table-column>
  53. <el-table-column prop="realName" label="姓名"></el-table-column>
  54. <el-table-column prop="roles" label="角色">
  55. <template slot-scope="scope">
  56. {{ scope.row.roles | rolesFilter }}
  57. </template>
  58. </el-table-column>
  59. <el-table-column prop="mobileNumber" label="手机号"></el-table-column>
  60. <el-table-column prop="enable" label="状态" width="100">
  61. <template slot-scope="scope">
  62. {{ scope.row.enable | enableFilter }}
  63. </template>
  64. </el-table-column>
  65. <el-table-column
  66. class-name="action-column"
  67. label="操作"
  68. align="center"
  69. width="120px"
  70. >
  71. <template slot-scope="scope">
  72. <el-button
  73. class="btn-table-icon"
  74. type="text"
  75. icon="icon icon-edit"
  76. @click="toEdit(scope.row)"
  77. title="编辑"
  78. ></el-button>
  79. <el-button
  80. class="btn-table-icon"
  81. type="text"
  82. :icon="
  83. scope.row.enable
  84. ? 'icon icon-circle-stop'
  85. : 'icon icon-circle-caret-right'
  86. "
  87. @click="toEnable(scope.row)"
  88. :title="scope.row.enable ? '禁用' : '启用'"
  89. ></el-button>
  90. <el-button
  91. class="btn-table-icon"
  92. type="text"
  93. icon="icon icon-circle-lock"
  94. @click="toResetPwd(scope.row)"
  95. title="重置密码"
  96. ></el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <div class="part-page">
  101. <el-pagination
  102. background
  103. layout="total,prev, pager, next"
  104. :current-page="current"
  105. :total="total"
  106. :page-size="size"
  107. @current-change="toPage"
  108. >
  109. </el-pagination>
  110. </div>
  111. </div>
  112. <!-- ModifyUser -->
  113. <modify-user
  114. ref="ModifyUser"
  115. :instance="curUser"
  116. :roles="roles"
  117. @modified="getList"
  118. ></modify-user>
  119. </div>
  120. </template>
  121. <script>
  122. import ModifyUser from "../components/ModifyUser";
  123. import { ABLE_TYPE } from "@/constants/enumerate";
  124. import { userListPage, ableUser, resetPwd, userRoleListPage } from "../api";
  125. export default {
  126. name: "user-manage",
  127. components: { ModifyUser },
  128. data() {
  129. return {
  130. filter: {
  131. realName: "",
  132. enable: ""
  133. },
  134. current: 1,
  135. size: this.GLOBAL.pageSize,
  136. total: 0,
  137. visible: false,
  138. ABLE_TYPE,
  139. roles: [],
  140. users: [],
  141. curUser: {}
  142. };
  143. },
  144. created() {
  145. this.getRoleList();
  146. this.getList();
  147. },
  148. methods: {
  149. async getRoleList() {
  150. const data = await userRoleListPage();
  151. this.roles = data || [];
  152. this.roles = this.roles
  153. .filter(item => item.type !== "ADMIN")
  154. .map(item => {
  155. return {
  156. id: item.id,
  157. name: item.name
  158. };
  159. });
  160. },
  161. async getList() {
  162. const datas = {
  163. ...this.filter,
  164. pageNumber: this.current,
  165. pageSize: this.size
  166. };
  167. if (datas.enable !== null && datas.enable !== "")
  168. datas.enable = !!datas.enable;
  169. const data = await userListPage(datas);
  170. this.users = data.records;
  171. this.total = data.total;
  172. },
  173. toPage(page) {
  174. this.current = page;
  175. this.getList();
  176. },
  177. toEnable(row) {
  178. // 自己不可以启用/禁用自己
  179. const userId = this.$ls.get("user", { id: "" }).id;
  180. if (row.id === userId) {
  181. this.$message.error("不可以启用/禁用自己!");
  182. return;
  183. }
  184. const action = row.enable ? "禁用" : "启用";
  185. this.$confirm(`确定要${action}用户【${row.realName}】吗?`, "提示", {
  186. cancelButtonClass: "el-button--danger is-plain",
  187. confirmButtonClass: "el-button--primary",
  188. type: "warning"
  189. })
  190. .then(async () => {
  191. const enable = !row.enable;
  192. await ableUser({
  193. id: row.id,
  194. enable
  195. });
  196. row.enable = enable;
  197. this.$message.success("操作成功!");
  198. })
  199. .catch(() => {});
  200. },
  201. toEdit(row) {
  202. this.curUser = row;
  203. this.$refs.ModifyUser.open();
  204. },
  205. toAdd() {
  206. this.curUser = {};
  207. this.$refs.ModifyUser.open();
  208. },
  209. async toResetPwd(row) {
  210. await resetPwd(row.id);
  211. this.$message.success("密码重置成功!");
  212. }
  213. }
  214. };
  215. </script>