UserManage.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="user-manage">
  3. <div class="part-box part-box-filter">
  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.loginName"
  9. placeholder="请输入内容"
  10. clearable
  11. ></el-input>
  12. </el-form-item>
  13. <el-form-item label="角色:" label-width="55px">
  14. <el-select
  15. v-model="filter.roleCode"
  16. style="width: 142px;"
  17. placeholder="请选择"
  18. clearable
  19. >
  20. <el-option
  21. v-for="item in roles"
  22. :key="item.roleCode"
  23. :value="item.roleCode"
  24. :label="item.roleName"
  25. ></el-option>
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item label="状态:" label-width="55px">
  29. <el-select
  30. v-model="filter.enable"
  31. style="width: 142px;"
  32. placeholder="请选择"
  33. clearable
  34. >
  35. <el-option
  36. v-for="(val, key) in ABLE_TYPE"
  37. :key="key"
  38. :value="key"
  39. :label="val"
  40. ></el-option>
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item label-width="0px">
  44. <el-button type="primary" icon="icon icon-search" @click="toPage(1)"
  45. >查询</el-button
  46. >
  47. <upload-button
  48. btn-icon="icon icon-share"
  49. btn-type="warning"
  50. btn-content="导入"
  51. :upload-url="uploadUrl"
  52. :format="['xls', 'xlsx']"
  53. :upload-data="uploadData"
  54. @upload-error="uplaodError"
  55. @upload-success="uploadSuccess"
  56. >
  57. </upload-button>
  58. <el-button icon="icon icon-download-act">
  59. <a :href="downloadUrl" download="用户导入模板.xlsx"
  60. >用户导入模板下载</a
  61. >
  62. </el-button>
  63. </el-form-item>
  64. </el-form>
  65. </div>
  66. <div class="part-box">
  67. <el-table ref="TableList" :data="users" border stripe>
  68. <el-table-column
  69. type="index"
  70. label="序号"
  71. width="70"
  72. align="center"
  73. :index="indexMethod"
  74. ></el-table-column>
  75. <el-table-column prop="loginName" label="用户名"></el-table-column>
  76. <el-table-column prop="name" label="姓名"></el-table-column>
  77. <el-table-column prop="roleName" label="角色"></el-table-column>
  78. <el-table-column prop="phone" label="手机号"></el-table-column>
  79. <el-table-column
  80. prop="courseNameCode"
  81. label="科目名称(编码)"
  82. ></el-table-column>
  83. <el-table-column prop="enable" label="状态">
  84. <template slot-scope="scope">
  85. {{ ABLE_TYPE[scope.row.enable + ""] }}
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="操作" align="center" width="120px">
  89. <template slot-scope="scope">
  90. <el-button
  91. class="btn-table-icon"
  92. type="text"
  93. :icon="
  94. scope.row.enable
  95. ? 'icon icon-circle-stop'
  96. : 'icon icon-circle-caret-right'
  97. "
  98. @click="toEnable(scope.row)"
  99. :title="scope.row.enable ? '禁用' : '启用'"
  100. ></el-button>
  101. <el-button
  102. class="btn-table-icon"
  103. type="text"
  104. icon="icon icon-edit"
  105. @click="toEdit(scope.row)"
  106. title="编辑"
  107. ></el-button>
  108. <el-button
  109. class="btn-table-icon"
  110. type="text"
  111. icon="icon icon-circle-lock"
  112. @click="toResetPwd(scope.row)"
  113. title="重置密码"
  114. ></el-button>
  115. </template>
  116. </el-table-column>
  117. </el-table>
  118. <div class="part-page">
  119. <el-pagination
  120. background
  121. layout="prev, pager, next"
  122. :current-page="current"
  123. :total="total"
  124. :page-size="size"
  125. @current-change="toPage"
  126. >
  127. </el-pagination>
  128. </div>
  129. </div>
  130. </div>
  131. </template>
  132. <script>
  133. import { ABLE_TYPE } from "@/constants/enumerate";
  134. import { userListPage, ableUser, updatePwd, roleList } from "../api";
  135. import UploadButton from "@/components/UploadButton";
  136. import { AES } from "@/plugins/crypto";
  137. import { logout } from "@/modules/login/api";
  138. export default {
  139. name: "user-manage",
  140. components: { UploadButton },
  141. data() {
  142. return {
  143. filter: {
  144. loginName: "",
  145. roleCode: "",
  146. enable: ""
  147. },
  148. current: 1,
  149. size: this.GLOBAL.pageSize,
  150. total: 0,
  151. visible: false,
  152. ABLE_TYPE,
  153. roles: [],
  154. users: [],
  155. downloadUrl: "/temps/用户导入模版.xlsx",
  156. // import
  157. uploadUrl: "/api/print/basic/user/add",
  158. uploadData: {
  159. schoolId: this.$ls.get("schoolId"),
  160. userId: this.$ls.get("user", { id: "" }).id
  161. }
  162. };
  163. },
  164. created() {
  165. this.getRoleList();
  166. this.getList();
  167. },
  168. methods: {
  169. indexMethod(index) {
  170. return (this.current - 1) * this.size + index + 1;
  171. },
  172. async getRoleList() {
  173. const data = await roleList();
  174. this.roles = data.records;
  175. },
  176. async getList() {
  177. const datas = {
  178. ...this.filter,
  179. pageNumber: this.current,
  180. pageSize: this.size
  181. };
  182. const data = await userListPage(datas);
  183. this.users = data.records;
  184. this.total = data.total;
  185. },
  186. toPage(page) {
  187. this.current = page;
  188. this.getList();
  189. },
  190. async toEnable(row) {
  191. const enable = Number(!row.enable);
  192. await ableUser({
  193. id: row.id,
  194. enable
  195. });
  196. row.enable = enable;
  197. },
  198. toEdit(row) {
  199. this.$router.push({
  200. name: "UserEdit",
  201. params: {
  202. userId: row.id
  203. }
  204. });
  205. },
  206. async toResetPwd(row) {
  207. await updatePwd({
  208. id: row.id,
  209. newPassword: AES("123456")
  210. });
  211. this.$message.success("密码重置成功!");
  212. // 修改自己时,会强制重新登录
  213. const userId = this.$ls.get("user", { id: "" }).id;
  214. if (row.id !== userId) return;
  215. this.toLogout(userId);
  216. },
  217. async toLogout(userId) {
  218. await logout(userId);
  219. this.$ls.clear();
  220. this.$router.push({ name: "Login" });
  221. this.$message.info("您的密码已经变更,请重新登录系统!");
  222. },
  223. uplaodError(errorData) {
  224. this.$notify.error({ title: "错误提示", message: errorData.message });
  225. },
  226. uploadSuccess(res) {
  227. this.$message.success("上传成功!");
  228. this.getList();
  229. }
  230. }
  231. };
  232. </script>