index.vue 15 KB

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