From 96f0fcb2cbced08e9942fcf16ffb5f23ebcf6342 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Fri, 16 Jun 2023 21:12:59 +0800 Subject: [PATCH] update Teacher Info Mod Signed-off-by: Chenx221 --- .../controller/TeacherController.class | Bin 4935 -> 6717 bytes .../cyou/chenx221/mapper/TeacherDao.class | Bin 488 -> 546 bytes .../chenx221/mapper/impl/TeacherDaoImpl.class | Bin 1283 -> 1476 bytes .../classes/cyou/chenx221/pojo/Teacher.class | Bin 4209 -> 4628 bytes .../chenx221/service/TeacherService.class | Bin 1028 -> 1165 bytes .../WEB-INF/classes/log4j.properties | 4 +- .../WEB-INF/classes/mapper/TeacherMapper.xml | 23 ++ .../WEB-INF/views/teachermanage.jsp | 220 ++++++++++-------- project2/project2.sql | 6 +- .../controller/TeacherController.java | 58 ++++- .../java/cyou/chenx221/mapper/TeacherDao.java | 3 + .../chenx221/mapper/impl/TeacherDaoImpl.java | 8 +- .../main/java/cyou/chenx221/pojo/Teacher.java | 13 ++ .../cyou/chenx221/service/TeacherService.java | 5 + .../main/resources/mapper/TeacherMapper.xml | 23 ++ project2/web/WEB-INF/views/teachermanage.jsp | 220 ++++++++++-------- 16 files changed, 372 insertions(+), 211 deletions(-) diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/TeacherController.class index dab42d285f3b21a139e921adb743aac01bb28769..cba61f9536f50a3aa9f5f103665cbd57cdad4ae8 100644 GIT binary patch literal 6717 zcmcIod3;pW89gtVGBdt;LrAsm zD6Xh=17*=l(OMNNCP1im6D+oB7i(ME+FBB@wfpiHtv&ZGvxJdf@b{~RrcaQ$};OhWp<6kZmpiqXxjUp6F7_d&+pah~ytR=9dX`LF7d6@4s%3a3jLi+!szwu>=L!am zDQ)WI#-j@ZQ7C>5c4G+6mEdhr^_rBXsWIK|DdC)o%DPOR8gwlZYpHg^C&8J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NK)YOXMsHfz|NFv?*KFfo-)9vZ#w-f%`*c);}g-x VjG35bWBz$5-Q+t)7ZSeR`VZ-Yr-c9j diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/TeacherDao.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/mapper/TeacherDao.class index 3b5189824e6ec4aa306596c47c00a5c952a45267..97665ee50c7dfe6a4982fe4c32a5483ecc0993ff 100644 GIT binary patch delta 110 zcmaFCyoiPC)W2Q(7#J9A8H6@+nKBCUmKLNWmZXNHCMIX37BMo&Py8sy=sDSzvBaL4 tg^_`kfsKKYfgPxUiGc&i=Vai5^SOb19tK{p93PnEXAl6=ARU4X3;;p>55NEb delta 52 zcmZ3)@`9P`)W2Q(7#J9A83Z@9k9|5^G=LsxRuTXW^6}y+bK$7$s z?vP4hm30~xYlV(kOreT3s#>{?CR$YV8LD8NvqN&5UFb}>r};^k{p5Ru)5oQz~ zsLLm`MME_@Fmv#OPR-5+ztym*Va1&t=Q>vDiT=b1$8kbzVVj=Py~8QOE~}1m!gKVg dp-D2Ij<8_i-aPY*ZTyR!Q`j?x{qeyEz&Ev3DA@o2 delta 329 zcmZXOOAY}+7=){PFfn?(5+m_`KW4DBv#@an=WqcFM{p5>2n#DK8^^H|)jboD*z{l3 zsrvr^p4vFh<9)pWm|?PaR>HDTK0HN2ZeP}NU4no_3W@=XI*tl`m2SZ)IUWBD;Rh$! zdpe04-!!v87BS?IL>_fIFHEC>CLMc*D$t@%klf}JY<8H_{3)kcQz-ukJMUhQk=W6P zD|AIeHCh?1B6Qbedi?Xyk6?2iq>ptCs}NjJwEke_pF7UEh1|xo6MZKZ1Y&4tmO@(Cr)y5l*>SAMQp*nf?%!#FiS_D4iVz?D~ z1>cD|g_KslRKL8wErx>R2bLPI&C82o4E^%L-<&_E$5cV(*JsqK^6lBB9hKK{E2}=z z*ZgT+vy!?MjOwEQh??8-Ca71eed}lZ-}{^+Hm2}G2uEXZ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q<6dlVyTu>81C~8Y@`><@}sk z=9%RStvA<1KdaY6Q}WW5J*}MoX}77Teq+PvH@c2~qwDCm=lb6C+n1#MinL!d@i%PS zw`|*YY}-}(?R)y|n)q$}|NSOyYx+&v=JJ|V`Pb5xSLxoYy%kp7ABg#pBFGLnc$=6Q Z_F^B`6tASbiP#ACHa0@g1xpdFZEUUfH7pDoLM-wC zK9qQ77ZgNfVCMdu^W8g-%TFu8$LISTI3yki2PSf?u~ni*-LQIpb2Yk4&XUpPb#iNH zrTeyNPG67B%nTMVEE4K&$bN#=fgqk@;^BniSeYeC+l5N6skoZ=X|b(LN*pD*4eONE zYozCe@F7xXNi|gSF0b&~+|^cW>8Q4m@%-c?Rs3WZzfl~{s90Vy*$=9kq4EXX_X3U` ixO*wyR5v>w=w delta 230 zcmeC>Y~kQK^>5cc1_lOO2DOb`=8T(b8Fw;rGczzUuri1PNr}mh%+kt|Km~jZ%s`Tt zfd$CoWZ-9z0`kNdn1Cb~gEWK8 + + UPDATE teacher + + + + name = #{name}, + + + birthday = #{birthday}, + + + course_id = #{course.CourseID}, + + + classes = #{classes} + + + + WHERE id = #{id}; + + + + \ No newline at end of file diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp index abd1bb9..424fd52 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/teachermanage.jsp @@ -173,10 +173,12 @@ ${teacher.classes}
- -
@@ -303,7 +305,7 @@
-
+
@@ -351,28 +353,28 @@
-
-
-
- - -
-
-
+ <%--
--%> + <%--
--%> + <%--
--%> + <%-- + <%-- name="course_name"/>--%> + <%-- --%> + <%--
--%> + <%--
--%> + <%--
--%>
+ for="typeText15">授课班级(1~5班)
-
@@ -452,7 +454,7 @@
- +
@@ -557,96 +559,118 @@ }); - function resetPWD(id) { - $('#typeText5').val(id); - $('#ex1-tab-2').tab('show'); - } - - - //实现按钮的点击事件(禁用/启用用户) $(document).ready(function () { - $('.btn-danger').on('click', function () { + $('.btn-danger').on('click', function () { //移除用户 var id = $(this).closest('tr').find('td:first').text(); - userdisabled(id); + // userdisabled(id); + console.log(id) // debug + }); + $('.btn-info').on('click', function () { //编辑用户 + var id = $(this).closest('tr').find('td:first').text(); + $('#ex1-tab-2').tab('show'); + $('#typeText9').val(id).focus(); // console.log(id) // debug }); - }); - $(document).ready(function () { - $('.btn-success').on('click', function () { - var id = $(this).closest('tr').find('td:first').text(); - userenabled(id); - // console.log(id) // debug + $('#modform').on('submit', function (event) { + event.preventDefault(); + $.ajax({ + url: 'mod', // 替换为您的请求 URL + method: 'POST', // 根据您的需求选择请求方法 (POST, GET, etc.) + data: $('#modform').serialize(), + success: function (response) { + $('#de_message').text(response); + $('#de_button').on('click', function () { + reloadka("reload"); + }); + $('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 + reloadka("reload"); + }); + }, + error: function (xhr, status, error) { + if (xhr.status === 400) { + $('#de_message').text(xhr.responseText); + $('#de_button').on('click', function () { + reloadka("close"); + }); + $('#exampleModal3').modal('show'); + } else { + console.log('请求失败:', error); + alert('请求请求失败,请重试'); + } + } + }); }); + }); - //使用ajax在后台发送post禁用/启用用户请求 - function userdisabled(id) { - //btn-danger - $.ajax({ - url: 'userdisabled', - type: 'post', - data: { - id: id - }, - success: function (data) { - if (data.status === 'success') { - $('#de_message').text(data.message); - $('#de_button').on('click', function () { - reloadka("reload"); - }); - $('#exampleModal3').modal('show'); - $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 - reloadka("reload"); - }); - } else { - $('#de_message').text(data.message); - $('#de_button').on('click', function () { - reloadka("close"); - }); - $('#exampleModal3').modal('show'); - } - }, - error: function (xhr, status, error) { - // 处理请求失败的逻辑 - console.log('请求失败:', error); - alert('请求请求失败,请重试'); - } - }); - } - - function userenabled(id) { - $.ajax({ - url: 'userenabled', - type: 'post', - data: { - id: id - }, - success: function (data) { - if (data.status === 'success') { - $('#de_message').text(data.message); - $('#de_button').on('click', function () { - reloadka("reload"); - }); - $('#exampleModal3').modal('show'); - $('#exampleModal3').on('hidden.bs.modal', function () { - reloadka("reload"); - }); - } else { - $('#de_message').text(data.message); - $('#de_button').on('click', function () { - reloadka("close"); - }); - $('#exampleModal3').modal('show'); - } - }, - error: function (xhr, status, error) { - // 处理请求失败的逻辑 - console.log('请求失败:', error); - alert('请求请求失败,请重试'); - } - }); - } - + // //使用ajax在后台发送post禁用/启用用户请求 + // function userdisabled(id) { + // //btn-danger + // $.ajax({ + // url: 'userdisabled', + // type: 'post', + // data: { + // id: id + // }, + // success: function (data) { + // if (data.status === 'success') { + // $('#de_message').text(data.message); + // $('#de_button').on('click', function () { + // reloadka("reload"); + // }); + // $('#exampleModal3').modal('show'); + // $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 + // reloadka("reload"); + // }); + // } else { + // $('#de_message').text(data.message); + // $('#de_button').on('click', function () { + // reloadka("close"); + // }); + // $('#exampleModal3').modal('show'); + // } + // }, + // error: function (xhr, status, error) { + // // 处理请求失败的逻辑 + // console.log('请求失败:', error); + // alert('请求请求失败,请重试'); + // } + // }); + // } + // + // function userenabled(id) { + // $.ajax({ + // url: 'userenabled', + // type: 'post', + // data: { + // id: id + // }, + // success: function (data) { + // if (data.status === 'success') { + // $('#de_message').text(data.message); + // $('#de_button').on('click', function () { + // reloadka("reload"); + // }); + // $('#exampleModal3').modal('show'); + // $('#exampleModal3').on('hidden.bs.modal', function () { + // reloadka("reload"); + // }); + // } else { + // $('#de_message').text(data.message); + // $('#de_button').on('click', function () { + // reloadka("close"); + // }); + // $('#exampleModal3').modal('show'); + // } + // }, + // error: function (xhr, status, error) { + // // 处理请求失败的逻辑 + // console.log('请求失败:', error); + // alert('请求请求失败,请重试'); + // } + // }); + // } + // //处理成功/失败后的刷新页面/关闭模态框操作 function reloadka(action) { if (action === 'reload') { diff --git a/project2/project2.sql b/project2/project2.sql index a25e1f6..6f12934 100644 --- a/project2/project2.sql +++ b/project2/project2.sql @@ -11,7 +11,7 @@ Target Server Version : 80033 (8.0.33) File Encoding : 65001 - Date: 16/06/2023 13:52:21 + Date: 16/06/2023 21:12:31 */ SET NAMES utf8mb4; @@ -1232,8 +1232,8 @@ CREATE TABLE `teacher` ( -- ---------------------------- -- Records of teacher -- ---------------------------- -INSERT INTO `teacher` VALUES (1, '韦秀英', '女', '1989-01-01', 8, '1班', 0); -INSERT INTO `teacher` VALUES (2, '蔡岚', '女', '1997-08-14', 1, '5班', 0); +INSERT INTO `teacher` VALUES (1, '无名氏', '女', '1989-01-01', 8, '1班', 0); +INSERT INTO `teacher` VALUES (2, '无名氏2', '女', '1997-08-14', 1, '5班', 0); INSERT INTO `teacher` VALUES (3, '蒋岚', '女', '1998-09-28', 9, '3班', 0); INSERT INTO `teacher` VALUES (4, '侯嘉伦', '男', '1980-05-07', 13, '3班', 0); INSERT INTO `teacher` VALUES (5, '毛子异', '男', '1995-05-03', 12, '1班', 0); diff --git a/project2/src/main/java/cyou/chenx221/controller/TeacherController.java b/project2/src/main/java/cyou/chenx221/controller/TeacherController.java index e1b7564..3a4519a 100644 --- a/project2/src/main/java/cyou/chenx221/controller/TeacherController.java +++ b/project2/src/main/java/cyou/chenx221/controller/TeacherController.java @@ -3,17 +3,14 @@ package cyou.chenx221.controller; import cyou.chenx221.helper.CsvHelper; import cyou.chenx221.helper.UsernameHelper; import cyou.chenx221.pojo.Course; -import cyou.chenx221.pojo.Score; -import cyou.chenx221.pojo.Student; import cyou.chenx221.pojo.Teacher; +import cyou.chenx221.service.CourseService; import cyou.chenx221.service.TeacherService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.sql.Date; @@ -26,10 +23,12 @@ import java.util.List; @RequestMapping("/teacher") public class TeacherController { private final TeacherService teacherService; + private final CourseService courseService; @Autowired - public TeacherController(TeacherService teacherService) { + public TeacherController(TeacherService teacherService, CourseService courseService) { this.teacherService = teacherService; + this.courseService = courseService; } @GetMapping("/manage") @@ -93,8 +92,6 @@ public class TeacherController { classes = null; } - String classesPattern = "[1-5]班";// 使用正则表达式验证班级格式 - if (id <= 0 && name == null && sex == null && birthdayBegin == null && birthdayEnd == null && course_id <= 0 && course_name == null && classes == null) { model.addAttribute("errorMessage", "ID非法或查询条件全为空"); return "redirect:/teacher/manage"; @@ -110,4 +107,47 @@ public class TeacherController { model.addAttribute("download", new CsvHelper().generateTeacherCSVFile(teachers)); return "teacherQueryResult"; } + + @ResponseBody + @PostMapping(value = "/mod",produces = "text/plain;charset=UTF-8") + public ResponseEntity postEdit(@RequestParam(value = "id") int id, + @RequestParam(value = "name", defaultValue = "null", required = false) String name, + @RequestParam(value = "birthday", defaultValue = "null", required = false) String birthday_str, + @RequestParam(value = "course_id", defaultValue = "-1", required = false) int course_id, + @RequestParam(value = "classes", defaultValue = "null", required = false) String classes) throws ParseException { + // 处理表单字段数据 + String classesPattern = "[1-5]班";// 使用正则表达式验证班级格式 + + if (id <= 0) { + return ResponseEntity.badRequest().body("ID非法"); + } else if (name.equals("null") && birthday_str.equals("null") && course_id == -1 && classes.equals("null")) { + return ResponseEntity.badRequest().body("修改内容为空"); + } + Date birthday = null; + if (!birthday_str.equals("null")) { + birthday = new Date(new SimpleDateFormat("yyyy-MM-dd").parse(birthday_str).getTime()); + } + if (!classes.equals("null")) { + if (!classes.matches(classesPattern)) { + return ResponseEntity.badRequest().body("班级格式非法"); + } + } + if(name.equals("null")){ + name=null; + } + if(classes.equals("null")){ + classes=null; + } + + //注 + //这里不考虑一个班一个科目不允许多名教师,少了个班级表+数据表外键搞得不好,所以这里偷懒了... + + Teacher teacher = new Teacher(id,name,birthday,new Course(course_id), classes); + int status_code = teacherService.updateTeacher(teacher); + if (status_code == 0) { + return ResponseEntity.badRequest().body("修改失败"); + } else { + return ResponseEntity.ok("修改成功"); + } + } } diff --git a/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java b/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java index 9d008eb..ecefd84 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java +++ b/project2/src/main/java/cyou/chenx221/mapper/TeacherDao.java @@ -10,4 +10,7 @@ public interface TeacherDao { List getAllTeachers(); List getQueryTeachers(Teacher teacher); + + + int updateTeacher(Teacher teacher); } diff --git a/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java b/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java index 5771866..d5ee388 100644 --- a/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java +++ b/project2/src/main/java/cyou/chenx221/mapper/impl/TeacherDaoImpl.java @@ -24,6 +24,12 @@ public class TeacherDaoImpl implements TeacherDao { @Override public List getQueryTeachers(Teacher teacher) { - return sqlSession.selectList("getQueryTeachers",teacher); + return sqlSession.selectList("getQueryTeachers", teacher); } + + @Override + public int updateTeacher(Teacher teacher) { + return sqlSession.update("updateTeacher", teacher); + } + } diff --git a/project2/src/main/java/cyou/chenx221/pojo/Teacher.java b/project2/src/main/java/cyou/chenx221/pojo/Teacher.java index f046d8b..b6bfdec 100644 --- a/project2/src/main/java/cyou/chenx221/pojo/Teacher.java +++ b/project2/src/main/java/cyou/chenx221/pojo/Teacher.java @@ -31,6 +31,11 @@ public class Teacher { this.birthdayEnd = birthdayEnd; } + public Teacher(Course course, String classes) { + this.course = course; + this.classes = classes; + } + public Teacher(Integer id, String name, String sex, Course course, String classes, Date birthdayBegin, Date birthdayEnd) { this.id = id; this.name = name; @@ -41,6 +46,14 @@ public class Teacher { this.birthdayEnd = birthdayEnd; } + public Teacher(Integer id, String name, Date birthday, Course course, String classes) { + this.id = id; + this.name = name; + this.birthday = birthday; + this.course = course; + this.classes = classes; + } + @Override public String toString() { return "Teacher{" + diff --git a/project2/src/main/java/cyou/chenx221/service/TeacherService.java b/project2/src/main/java/cyou/chenx221/service/TeacherService.java index 9c8131d..476f95c 100644 --- a/project2/src/main/java/cyou/chenx221/service/TeacherService.java +++ b/project2/src/main/java/cyou/chenx221/service/TeacherService.java @@ -21,4 +21,9 @@ public class TeacherService { public List getQueryTeachers(Teacher teacher) { return teacherDao.getQueryTeachers(teacher); } + + + public int updateTeacher(Teacher teacher) { + return teacherDao.updateTeacher(teacher); + } } diff --git a/project2/src/main/resources/mapper/TeacherMapper.xml b/project2/src/main/resources/mapper/TeacherMapper.xml index 1e1bbed..9e33b33 100644 --- a/project2/src/main/resources/mapper/TeacherMapper.xml +++ b/project2/src/main/resources/mapper/TeacherMapper.xml @@ -56,4 +56,27 @@ + + UPDATE teacher + + + + name = #{name}, + + + birthday = #{birthday}, + + + course_id = #{course.CourseID}, + + + classes = #{classes} + + + + WHERE id = #{id}; + + + + \ No newline at end of file diff --git a/project2/web/WEB-INF/views/teachermanage.jsp b/project2/web/WEB-INF/views/teachermanage.jsp index abd1bb9..424fd52 100644 --- a/project2/web/WEB-INF/views/teachermanage.jsp +++ b/project2/web/WEB-INF/views/teachermanage.jsp @@ -173,10 +173,12 @@ ${teacher.classes}
- -
@@ -303,7 +305,7 @@
- +
@@ -351,28 +353,28 @@
-
-
-
- - -
-
-
+ <%--
--%> + <%--
--%> + <%--
--%> + <%-- + <%-- name="course_name"/>--%> + <%-- --%> + <%--
--%> + <%--
--%> + <%--
--%>
+ for="typeText15">授课班级(1~5班)
-
@@ -452,7 +454,7 @@
- +
@@ -557,96 +559,118 @@ }); - function resetPWD(id) { - $('#typeText5').val(id); - $('#ex1-tab-2').tab('show'); - } - - - //实现按钮的点击事件(禁用/启用用户) $(document).ready(function () { - $('.btn-danger').on('click', function () { + $('.btn-danger').on('click', function () { //移除用户 var id = $(this).closest('tr').find('td:first').text(); - userdisabled(id); + // userdisabled(id); + console.log(id) // debug + }); + $('.btn-info').on('click', function () { //编辑用户 + var id = $(this).closest('tr').find('td:first').text(); + $('#ex1-tab-2').tab('show'); + $('#typeText9').val(id).focus(); // console.log(id) // debug }); - }); - $(document).ready(function () { - $('.btn-success').on('click', function () { - var id = $(this).closest('tr').find('td:first').text(); - userenabled(id); - // console.log(id) // debug + $('#modform').on('submit', function (event) { + event.preventDefault(); + $.ajax({ + url: 'mod', // 替换为您的请求 URL + method: 'POST', // 根据您的需求选择请求方法 (POST, GET, etc.) + data: $('#modform').serialize(), + success: function (response) { + $('#de_message').text(response); + $('#de_button').on('click', function () { + reloadka("reload"); + }); + $('#exampleModal3').modal('show').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 + reloadka("reload"); + }); + }, + error: function (xhr, status, error) { + if (xhr.status === 400) { + $('#de_message').text(xhr.responseText); + $('#de_button').on('click', function () { + reloadka("close"); + }); + $('#exampleModal3').modal('show'); + } else { + console.log('请求失败:', error); + alert('请求请求失败,请重试'); + } + } + }); }); + }); - //使用ajax在后台发送post禁用/启用用户请求 - function userdisabled(id) { - //btn-danger - $.ajax({ - url: 'userdisabled', - type: 'post', - data: { - id: id - }, - success: function (data) { - if (data.status === 'success') { - $('#de_message').text(data.message); - $('#de_button').on('click', function () { - reloadka("reload"); - }); - $('#exampleModal3').modal('show'); - $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 - reloadka("reload"); - }); - } else { - $('#de_message').text(data.message); - $('#de_button').on('click', function () { - reloadka("close"); - }); - $('#exampleModal3').modal('show'); - } - }, - error: function (xhr, status, error) { - // 处理请求失败的逻辑 - console.log('请求失败:', error); - alert('请求请求失败,请重试'); - } - }); - } - - function userenabled(id) { - $.ajax({ - url: 'userenabled', - type: 'post', - data: { - id: id - }, - success: function (data) { - if (data.status === 'success') { - $('#de_message').text(data.message); - $('#de_button').on('click', function () { - reloadka("reload"); - }); - $('#exampleModal3').modal('show'); - $('#exampleModal3').on('hidden.bs.modal', function () { - reloadka("reload"); - }); - } else { - $('#de_message').text(data.message); - $('#de_button').on('click', function () { - reloadka("close"); - }); - $('#exampleModal3').modal('show'); - } - }, - error: function (xhr, status, error) { - // 处理请求失败的逻辑 - console.log('请求失败:', error); - alert('请求请求失败,请重试'); - } - }); - } - + // //使用ajax在后台发送post禁用/启用用户请求 + // function userdisabled(id) { + // //btn-danger + // $.ajax({ + // url: 'userdisabled', + // type: 'post', + // data: { + // id: id + // }, + // success: function (data) { + // if (data.status === 'success') { + // $('#de_message').text(data.message); + // $('#de_button').on('click', function () { + // reloadka("reload"); + // }); + // $('#exampleModal3').modal('show'); + // $('#exampleModal3').on('hidden.bs.modal', function () { //针对点击modal外的情况的处理 + // reloadka("reload"); + // }); + // } else { + // $('#de_message').text(data.message); + // $('#de_button').on('click', function () { + // reloadka("close"); + // }); + // $('#exampleModal3').modal('show'); + // } + // }, + // error: function (xhr, status, error) { + // // 处理请求失败的逻辑 + // console.log('请求失败:', error); + // alert('请求请求失败,请重试'); + // } + // }); + // } + // + // function userenabled(id) { + // $.ajax({ + // url: 'userenabled', + // type: 'post', + // data: { + // id: id + // }, + // success: function (data) { + // if (data.status === 'success') { + // $('#de_message').text(data.message); + // $('#de_button').on('click', function () { + // reloadka("reload"); + // }); + // $('#exampleModal3').modal('show'); + // $('#exampleModal3').on('hidden.bs.modal', function () { + // reloadka("reload"); + // }); + // } else { + // $('#de_message').text(data.message); + // $('#de_button').on('click', function () { + // reloadka("close"); + // }); + // $('#exampleModal3').modal('show'); + // } + // }, + // error: function (xhr, status, error) { + // // 处理请求失败的逻辑 + // console.log('请求失败:', error); + // alert('请求请求失败,请重试'); + // } + // }); + // } + // //处理成功/失败后的刷新页面/关闭模态框操作 function reloadka(action) { if (action === 'reload') {