From f65fb669e96bf32abf347c49cc85a3c82ed2450f Mon Sep 17 00:00:00 2001 From: awinx Date: Sat, 21 Dec 2024 22:22:51 +0800 Subject: [PATCH] update --- src/views/student/studentList.vue | 201 +++++++++++++++++++++++++++++- 1 file changed, 198 insertions(+), 3 deletions(-) diff --git a/src/views/student/studentList.vue b/src/views/student/studentList.vue index 07d29d0..a5b0e00 100644 --- a/src/views/student/studentList.vue +++ b/src/views/student/studentList.vue @@ -1,7 +1,7 @@ @@ -106,6 +151,8 @@ export default { pageSize: 10, total: 0 }, + studentEditDialogVisible: false, + studentEditForm: {id: -1, code: '', name: '', sex: '', grade: '', major: '', detail: ''}, } }, methods: { @@ -155,16 +202,164 @@ export default { }; this.studentListGet(); }, - studentEdit(student) { console.log('编辑学生:', student) }, - studentDelete(student) { console.log('删除学生:', student) }, + studentEdit(student) { console.log('编辑学生:', student) + this.studentEditDialogVisible = true; + this.studentEditForm = student; + }, + studentDelete(student) { + this.$confirm( + '确定要删除学生'+student.name+'吗?', + '提示', + { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + } + ).then(()=>{ + $.ajax({ + url: this.$apiUrl + "/studentAction/delete", + method: 'POST', + data: student, + success: (data)=>{ + if (data.success){ + this.$message({ + type: 'success', + message: '删除成功', + showClose: true + }); + this.studentListGet(); + }else{ + this.$message({ + type: 'error', + message: '删除失败', + showClose: true + }); + } + }, + error:(xhr)=>{ + this.$message({ + type: 'error', + message: '请求数据失败,code=' + xhr.status, + showClose: true + }); + } + }); + }).catch(()=>{ + this.$message({ + type: 'info', + message: '取消删除', + showClose: true + }); + }); + }, handleSizeChange(val) { this.studentList.pageSize = val; + this.studentList.page = 1; this.studentListGet(); }, handleCurrentChange(val) { this.studentList.page = val; this.studentListGet(); }, + studentAdd(){ + this.studentEditForm = { id: -1, code: '', name: '', sex: '', grade: '', major: '', detail: '' }; + this.studentEditDialogVisible = true; + }, + studentSubmit(){ + if(this.studentEditForm.id===-1){ + this.$confirm( + "确定要添加学生"+this.studentEditForm.name+"吗?", + '提示', + { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + } + ).then(()=>{ + $.ajax({ + url: this.$apiUrl + '/studentAction/add', + method: "POST", + data: this.studentEditForm, + success: (data) => { + if (data.success) { + this.$message({ + type: 'success', + message: '保存成功', + showClose: true, + }); + this.studentEditDialogVisible = false; + this.studentListGet(); + } else { + this.$message({ + type: 'error', + message: data.msg, + showClose: true, + }); + } + }, + error: (xhr) => { + this.$message({ + type: 'error', + message: '请求数据失败,code=' + xhr.status, + showClose: true, + }); + } + }); + }).catch(()=>{ + this.$message({ + type: 'info', + message: '取消添加', + showClose: true + }); + }); + }else{ + this.$confirm( + "确定要修改学生" + this.studentEditForm.name + "吗?", + '提示', + { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + } + ).then(() => { + $.ajax({ + url: this.$apiUrl + '/studentAction/edit', + method: "POST", + data: this.studentEditForm, + success: (data) => { + if (data.success) { + this.$message({ + type: 'success', + message: '修改成功', + showClose: true, + }); + this.studentEditDialogVisible = false; + this.studentListGet(); + } else { + this.$message({ + type: 'error', + message: data.msg, + showClose: true, + }); + } + }, + error: (xhr) => { + this.$message({ + type: 'error', + message: '请求数据失败,code=' + xhr.status, + showClose: true, + }); + } + }); + }).catch(() => { + this.$message({ + type: 'info', + message: '取消保存', + showClose: true + }); + }); + } + }, }, mounted(){ this.studentListGet();