index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--用户数据1-->
  5. <el-col :xs="24">
  6. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
  7. <el-form-item label="学号" prop="className">
  8. <el-input
  9. v-model="queryParams.className"
  10. placeholder="请输入学号"
  11. clearable
  12. style="width: 150px"
  13. @keyup.enter.native="handleQuery"
  14. />
  15. </el-form-item>
  16. <el-form-item label="姓名" prop="className">
  17. <el-input
  18. v-model="queryParams.className"
  19. placeholder="请输入姓名"
  20. clearable
  21. style="width: 150px"
  22. @keyup.enter.native="handleQuery"
  23. />
  24. </el-form-item>
  25. <el-form-item label="班级名称" prop="className">
  26. <el-input
  27. v-model="queryParams.className"
  28. placeholder="请输入班级名称"
  29. clearable
  30. style="width: 200px"
  31. @keyup.enter.native="handleQuery"
  32. />
  33. </el-form-item>
  34. <el-form-item label="专业名称" prop="majorName">
  35. <el-input
  36. v-model="queryParams.userName"
  37. placeholder="请输入专业名称"
  38. clearable
  39. style="width: 200px"
  40. @keyup.enter.native="handleQuery"
  41. />
  42. </el-form-item>
  43. <el-form-item label="创建时间">
  44. <el-date-picker
  45. v-model="dateRange"
  46. style="width: 240px"
  47. value-format="yyyy-MM-dd"
  48. type="daterange"
  49. range-separator="-"
  50. start-placeholder="开始日期"
  51. end-placeholder="结束日期"
  52. ></el-date-picker>
  53. </el-form-item>
  54. <el-form-item>
  55. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  56. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  57. </el-form-item>
  58. </el-form>
  59. <el-row :gutter="10" class="mb8">
  60. <el-col :span="1.5">
  61. <el-button
  62. type="primary"
  63. plain
  64. icon="el-icon-plus"
  65. size="mini"
  66. @click="handleAdd"
  67. v-hasPermi="['system:user:add']"
  68. >新增</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="success"
  73. plain
  74. icon="el-icon-edit"
  75. size="mini"
  76. :disabled="single"
  77. @click="handleUpdate"
  78. v-hasPermi="['system:user:edit']"
  79. >修改</el-button>
  80. </el-col>
  81. <el-col :span="1.5">
  82. <el-button
  83. type="danger"
  84. plain
  85. icon="el-icon-delete"
  86. size="mini"
  87. :disabled="multiple"
  88. @click="handleDelete"
  89. v-hasPermi="['system:user:remove']"
  90. >删除</el-button>
  91. </el-col>
  92. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
  93. </el-row>
  94. <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
  95. <el-table-column type="selection" width="50" align="center" />
  96. <el-table-column label="编号" align="center" key="userId" prop="userId" v-if="columns[0].visible" />
  97. <el-table-column label="学号" align="center" key="xuehao" prop="xuehao" v-if="columns[1].visible" />
  98. <el-table-column label="姓名" align="center" key="xingming" prop="xingming" v-if="columns[2].visible" />
  99. <el-table-column label="区队/班级" align="center" key="className" prop="className" v-if="columns[3].visible" :show-overflow-tooltip="true" />
  100. <el-table-column label="专业名称" align="center" key="majorName" prop="majorName" v-if="columns[4].visible" :show-overflow-tooltip="true" />
  101. <el-table-column label="备注" align="center" key="remark" prop="remark" v-if="columns[5].visible" :show-overflow-tooltip="true" />
  102. <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[6].visible" width="160">
  103. <template slot-scope="scope">
  104. <span>{{ parseTime(scope.row.createTime) }}</span>
  105. </template>
  106. </el-table-column>
  107. <el-table-column
  108. label="操作"
  109. align="center"
  110. width="160"
  111. class-name="small-padding fixed-width"
  112. >
  113. <template slot-scope="scope">
  114. <el-button
  115. size="mini"
  116. type="text"
  117. icon="el-icon-edit"
  118. @click="handleUpdate(scope.row)"
  119. v-hasPermi="['system:user:edit']"
  120. >修改</el-button>
  121. <el-button
  122. size="mini"
  123. type="text"
  124. icon="el-icon-delete"
  125. @click="handleDelete(scope.row)"
  126. v-hasPermi="['system:user:remove']"
  127. >删除</el-button>
  128. <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['simulator:user:resetPwd', 'simulator:user:edit']">
  129. <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
  130. <el-dropdown-menu slot="dropdown">
  131. <el-dropdown-item command="handleResetPwd" icon="el-icon-key"
  132. v-hasPermi="['simulator:user:resetPwd']">重置密码</el-dropdown-item>
  133. </el-dropdown-menu>
  134. </el-dropdown>
  135. </template>
  136. </el-table-column>
  137. </el-table>
  138. <pagination
  139. v-show="total>0"
  140. :total="total"
  141. :page.sync="queryParams.pageNum"
  142. :limit.sync="queryParams.pageSize"
  143. @pagination="getList"
  144. />
  145. </el-col>
  146. </el-row>
  147. <!-- 添加或修改用户配置对话框 -->
  148. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  149. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  150. <el-row>
  151. <el-col :span="24">
  152. <el-form-item label="班级名称" prop="nickName">
  153. <el-input v-model="form.nickName" placeholder="请输入班级名称" maxlength="30" />
  154. </el-form-item>
  155. </el-col>
  156. </el-row>
  157. <el-row>
  158. <el-col :span="24">
  159. <el-form-item label="专业" prop="nickName">
  160. <el-input v-model="form.nickName" placeholder="请输入专业" maxlength="30" />
  161. </el-form-item>
  162. </el-col>
  163. </el-row>
  164. <el-row>
  165. <el-col :span="24">
  166. <el-form-item label="备注">
  167. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  168. </el-form-item>
  169. </el-col>
  170. </el-row>
  171. </el-form>
  172. <div slot="footer" class="dialog-footer">
  173. <el-button type="primary" @click="submitForm">确 定</el-button>
  174. <el-button @click="cancel">取 消</el-button>
  175. </div>
  176. </el-dialog>
  177. </div>
  178. </template>
  179. <script>
  180. import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect } from "@/api/system/user";
  181. import { getToken } from "@/utils/auth";
  182. import Treeselect from "@riophae/vue-treeselect";
  183. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  184. export default {
  185. name: "User",
  186. dicts: ['sys_normal_disable', 'sys_user_sex'],
  187. components: { Treeselect },
  188. data() {
  189. return {
  190. // 遮罩层
  191. loading: true,
  192. // 选中数组
  193. ids: [],
  194. // 非单个禁用
  195. single: true,
  196. // 非多个禁用
  197. multiple: true,
  198. // 显示搜索条件
  199. showSearch: true,
  200. // 总条数
  201. total: 0,
  202. // 用户表格数据
  203. userList: null,
  204. // 弹出层标题
  205. title: "",
  206. // 是否显示弹出层
  207. open: false,
  208. // 部门名称
  209. deptName: undefined,
  210. // 默认密码
  211. initPassword: undefined,
  212. // 日期范围
  213. dateRange: [],
  214. // 岗位选项
  215. postOptions: [],
  216. // 角色选项
  217. roleOptions: [],
  218. // 表单参数
  219. form: {},
  220. defaultProps: {
  221. children: "children",
  222. label: "label"
  223. },
  224. // 用户导入参数
  225. upload: {
  226. // 是否显示弹出层(用户导入)
  227. open: false,
  228. // 弹出层标题(用户导入)
  229. title: "",
  230. // 是否禁用上传
  231. isUploading: false,
  232. // 是否更新已经存在的用户数据
  233. updateSupport: 0,
  234. // 设置上传的请求头部
  235. headers: { Authorization: "Bearer " + getToken() },
  236. // 上传的地址
  237. url: process.env.VUE_APP_BASE_API + "/system/user/importData"
  238. },
  239. // 查询参数
  240. queryParams: {
  241. pageNum: 1,
  242. pageSize: 10,
  243. userName: undefined,
  244. phonenumber: undefined,
  245. status: undefined,
  246. deptId: undefined
  247. },
  248. // 列信息
  249. columns: [
  250. { key: 0, label: `编号`, visible: true },
  251. { key: 1, label: `编号`, visible: true },
  252. { key: 2, label: `姓名`, visible: true },
  253. { key: 3, label: `班级名称`, visible: true },
  254. { key: 4, label: `专业`, visible: true },
  255. { key: 5, label: `备注`, visible: true },
  256. { key: 6, label: `创建时间`, visible: true }
  257. ],
  258. // 表单校验
  259. rules: {
  260. userName: [
  261. { required: true, message: "用户名称不能为空", trigger: "blur" },
  262. { min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur' }
  263. ],
  264. nickName: [
  265. { required: true, message: "用户昵称不能为空", trigger: "blur" }
  266. ],
  267. password: [
  268. { required: true, message: "用户密码不能为空", trigger: "blur" },
  269. { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' },
  270. { pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符:< > \" ' \\\ |", trigger: "blur" }
  271. ],
  272. email: [
  273. {
  274. type: "email",
  275. message: "请输入正确的邮箱地址",
  276. trigger: ["blur", "change"]
  277. }
  278. ],
  279. phonenumber: [
  280. {
  281. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  282. message: "请输入正确的手机号码",
  283. trigger: "blur"
  284. }
  285. ]
  286. }
  287. };
  288. },
  289. watch: {
  290. // 根据名称筛选部门树
  291. deptName(val) {
  292. this.$refs.tree.filter(val);
  293. }
  294. },
  295. created() {
  296. this.getList();
  297. // this.getDeptTree();
  298. this.getConfigKey("sys.user.initPassword").then(response => {
  299. this.initPassword = response.msg;
  300. });
  301. },
  302. methods: {
  303. /** 查询用户列表 */
  304. getList() {
  305. this.loading = true;
  306. listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  307. this.userList = response.rows;
  308. this.total = response.total;
  309. this.loading = false;
  310. }
  311. );
  312. },
  313. // 筛选节点
  314. filterNode(value, data) {
  315. if (!value) return true;
  316. return data.label.indexOf(value) !== -1;
  317. },
  318. // 用户状态修改
  319. handleStatusChange(row) {
  320. let text = row.status === "0" ? "启用" : "停用";
  321. this.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗?').then(function() {
  322. return changeUserStatus(row.userId, row.status);
  323. }).then(() => {
  324. this.$modal.msgSuccess(text + "成功");
  325. }).catch(function() {
  326. row.status = row.status === "0" ? "1" : "0";
  327. });
  328. },
  329. // 取消按钮
  330. cancel() {
  331. this.open = false;
  332. this.reset();
  333. },
  334. // 表单重置
  335. reset() {
  336. this.form = {
  337. userId: undefined,
  338. deptId: undefined,
  339. userName: undefined,
  340. nickName: undefined,
  341. password: undefined,
  342. phonenumber: undefined,
  343. email: undefined,
  344. sex: undefined,
  345. status: "0",
  346. remark: undefined,
  347. postIds: [],
  348. roleIds: []
  349. };
  350. this.resetForm("form");
  351. },
  352. /** 搜索按钮操作 */
  353. handleQuery() {
  354. this.queryParams.pageNum = 1;
  355. this.getList();
  356. },
  357. /** 重置按钮操作 */
  358. resetQuery() {
  359. this.dateRange = [];
  360. this.resetForm("queryForm");
  361. this.queryParams.deptId = undefined;
  362. this.$refs.tree.setCurrentKey(null);
  363. },
  364. // 多选框选中数据
  365. handleSelectionChange(selection) {
  366. this.ids = selection.map(item => item.userId);
  367. this.single = selection.length != 1;
  368. this.multiple = !selection.length;
  369. },
  370. // 更多操作触发
  371. handleCommand(command, row) {
  372. switch (command) {
  373. case "handleResetPwd":
  374. this.handleResetPwd(row);
  375. break;
  376. case "handleAuthRole":
  377. this.handleAuthRole(row);
  378. break;
  379. default:
  380. break;
  381. }
  382. },
  383. /** 新增按钮操作 */
  384. handleAdd() {
  385. this.reset();
  386. getUser().then(response => {
  387. this.postOptions = response.posts;
  388. this.roleOptions = response.roles;
  389. this.open = true;
  390. this.title = "添加用户";
  391. this.form.password = this.initPassword;
  392. });
  393. },
  394. /** 修改按钮操作 */
  395. handleUpdate(row) {
  396. this.reset();
  397. const userId = row.userId || this.ids;
  398. getUser(userId).then(response => {
  399. this.form = response.data;
  400. this.postOptions = response.posts;
  401. this.roleOptions = response.roles;
  402. this.$set(this.form, "postIds", response.postIds);
  403. this.$set(this.form, "roleIds", response.roleIds);
  404. this.open = true;
  405. this.title = "修改用户";
  406. this.form.password = "";
  407. });
  408. },
  409. /** 重置密码按钮操作 */
  410. handleResetPwd(row) {
  411. this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
  412. confirmButtonText: "确定",
  413. cancelButtonText: "取消",
  414. closeOnClickModal: false,
  415. inputPattern: /^.{5,20}$/,
  416. inputErrorMessage: "用户密码长度必须介于 5 和 20 之间",
  417. inputValidator: (value) => {
  418. if (/<|>|"|'|\||\\/.test(value)) {
  419. return "不能包含非法字符:< > \" ' \\\ |"
  420. }
  421. },
  422. }).then(({ value }) => {
  423. resetUserPwd(row.userId, value).then(response => {
  424. this.$modal.msgSuccess("修改成功,新密码是:" + value);
  425. });
  426. }).catch(() => {});
  427. },
  428. /** 分配角色操作 */
  429. handleAuthRole: function(row) {
  430. const userId = row.userId;
  431. this.$router.push("/system/user-auth/role/" + userId);
  432. },
  433. /** 提交按钮 */
  434. submitForm: function() {
  435. this.$refs["form"].validate(valid => {
  436. if (valid) {
  437. if (this.form.userId != undefined) {
  438. updateUser(this.form).then(response => {
  439. this.$modal.msgSuccess("修改成功");
  440. this.open = false;
  441. this.getList();
  442. });
  443. } else {
  444. addUser(this.form).then(response => {
  445. this.$modal.msgSuccess("新增成功");
  446. this.open = false;
  447. this.getList();
  448. });
  449. }
  450. }
  451. });
  452. },
  453. /** 删除按钮操作 */
  454. handleDelete(row) {
  455. const userIds = row.userId || this.ids;
  456. this.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项?').then(function() {
  457. return delUser(userIds);
  458. }).then(() => {
  459. this.getList();
  460. this.$modal.msgSuccess("删除成功");
  461. }).catch(() => {});
  462. },
  463. /** 导出按钮操作 */
  464. handleExport() {
  465. this.download('system/user/export', {
  466. ...this.queryParams
  467. }, `user_${new Date().getTime()}.xlsx`)
  468. },
  469. /** 导入按钮操作 */
  470. handleImport() {
  471. this.upload.title = "用户导入";
  472. this.upload.open = true;
  473. },
  474. /** 下载模板操作 */
  475. importTemplate() {
  476. this.download('system/user/importTemplate', {
  477. }, `user_template_${new Date().getTime()}.xlsx`)
  478. },
  479. // 文件上传中处理
  480. handleFileUploadProgress(event, file, fileList) {
  481. this.upload.isUploading = true;
  482. },
  483. // 文件上传成功处理
  484. handleFileSuccess(response, file, fileList) {
  485. this.upload.open = false;
  486. this.upload.isUploading = false;
  487. this.$refs.upload.clearFiles();
  488. this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
  489. this.getList();
  490. },
  491. // 提交上传文件
  492. submitFileForm() {
  493. this.$refs.upload.submit();
  494. }
  495. }
  496. };
  497. </script>