From 3cd557fdf2c9ed4b0c03421ee4eb594b86afb0a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E4=B8=B9ab?= <1421553879@qq.com> Date: Mon, 17 Oct 2022 18:38:31 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ibeetl/jlw/web/CompetitionController.java | 7 +- .../static/js/jlw/competition/index.js | 90 +++++++++++-------- .../templates/jlw/competition/add.html | 26 ++++-- 3 files changed, 75 insertions(+), 48 deletions(-) diff --git a/web/src/main/java/com/ibeetl/jlw/web/CompetitionController.java b/web/src/main/java/com/ibeetl/jlw/web/CompetitionController.java index 31c25c56..f5092082 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/CompetitionController.java +++ b/web/src/main/java/com/ibeetl/jlw/web/CompetitionController.java @@ -88,10 +88,14 @@ public class CompetitionController{ return view; } + /** + *@author 姚丹 + *@data 2022/10/17 + */ @GetMapping(MODEL + "/add.do") @Function("competition.add") @ResponseBody - public ModelAndView add(Long competitionId) { + public ModelAndView add(Long competitionId,String sign) { ModelAndView view = new ModelAndView("/jlw/competition/add.html"); if(null != competitionId){ Competition competition = competitionService.queryById(competitionId); @@ -105,6 +109,7 @@ public class CompetitionController{ view.addObject("competition", new Competition()); view.addObject("competitionNewsList", new ArrayList()); } + view.addObject("sign", sign); return view; } diff --git a/web/src/main/resources/static/js/jlw/competition/index.js b/web/src/main/resources/static/js/jlw/competition/index.js index 6ecc37a7..24b037c4 100644 --- a/web/src/main/resources/static/js/jlw/competition/index.js +++ b/web/src/main/resources/static/js/jlw/competition/index.js @@ -91,43 +91,7 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) { initToolBar:function(){ toolbar = { add : function() { // 获取选中数据 - layer.open({ - type:1, - title: '新增大赛', - btn: ['确定', '关闭'], - btnAlign: 'c', - area: ['440px', '170px'], - content: '
' + - '
' + - ' ' + - '
' + - ' ' + - ' ' + - '
' + - '
' + - '
' - ,success: function (layero, index) { - form.render(); - }, - yes: function (index, layero) { - var type = $("input[name='type']:checked").val(); - console.log(type) - if($.isEmpty(type)){ - Common.info("请选择大赛类型!!") - return; - } - if(type == '1'||type == 1){ - var url = "/jlw/competition/add.do"; - Common.openDlg(url,"大赛管理/新增大赛"); - }else { - } - - layer.close(index); - }, - btn2: function (index, layero) { - layer.close(index); - } - }); + openF("add"); }, refresh: function () {//刷新 searchForm.reset(); @@ -144,8 +108,7 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) { }, initTableTool: table.on('tool(competitionTable)', function (obj) { var data = obj.data; if (obj.event === 'edit') { - var url = "/jlw/competition/add.do?competitionId="+data.competitionId; - Common.openDlg(url,"大赛管理/编辑大赛"); + openF("edit",data); }else if(obj.event === "del"){ layer.confirm('是否确定删除该大赛?', function (index) { var ret = Common.postAjax("/jlw/competition/delete.json", {ids: data.competitionId}); @@ -191,6 +154,55 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) { return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 });*/ + function openF(f,data){ + layer.open({ + type:1, + title: f == "add"?'新增大赛':'编辑大赛', + btn: ['确定', '关闭'], + btnAlign: 'c', + area: ['440px', '170px'], + content: '
' + + '
' + + ' ' + + '
' + + ' ' + + ' ' + + '
' + + '
' + + '
' + ,success: function (layero, index) { + form.render(); + }, + yes: function (index, layero) { + var type = $("input[name='type']:checked").val(); + if($.isEmpty(type)){ + Common.info("请选择大赛类型!!") + return; + } + if(f == "add"){ + if(type == '1'||type == 1){ + var url = "/jlw/competition/add.do?"+"sign=1"; + Common.openDlg(url,"大赛管理/新增大赛"); + }else { + var url = "/jlw/competition/add.do?"+"sign=2"; + Common.openDlg(url,"大赛管理/新增大赛"); + } + }else if(f == "edit"){ + if(type == '1'||type == 1){ + var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"sign=1"; + Common.openDlg(url,"大赛管理/编辑大赛"); + }else { + var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"sign=2"; + Common.openDlg(url,"大赛管理/编辑大赛"); + } + } + layer.close(index); + }, + btn2: function (index, layero) { + layer.close(index); + } + }); + }; exports('index',view); }); \ No newline at end of file diff --git a/web/src/main/resources/templates/jlw/competition/add.html b/web/src/main/resources/templates/jlw/competition/add.html index d011bc96..d8ff2def 100644 --- a/web/src/main/resources/templates/jlw/competition/add.html +++ b/web/src/main/resources/templates/jlw/competition/add.html @@ -80,14 +80,24 @@
From d39d2fa2a35828c60a0f1120928d6a404366b6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E4=B8=B9ab?= <1421553879@qq.com> Date: Tue, 18 Oct 2022 14:50:28 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=BB=91=E6=9E=B6?= =?UTF-8?q?=EF=BC=8C=E7=BB=91=E5=AE=9A=E6=8F=90=E4=BA=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static/js/jlw/competition/index.js | 4 +- .../jlw/resourcesApplicationCourse/index.js | 102 ++++++++++++------ .../jlw/resourcesApplicationCourse/index.html | 2 +- 3 files changed, 72 insertions(+), 36 deletions(-) diff --git a/web/src/main/resources/static/js/jlw/competition/index.js b/web/src/main/resources/static/js/jlw/competition/index.js index 24b037c4..8e8ab9d6 100644 --- a/web/src/main/resources/static/js/jlw/competition/index.js +++ b/web/src/main/resources/static/js/jlw/competition/index.js @@ -189,10 +189,10 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) { } }else if(f == "edit"){ if(type == '1'||type == 1){ - var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"sign=1"; + var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"&sign=1"; Common.openDlg(url,"大赛管理/编辑大赛"); }else { - var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"sign=2"; + var url = "/jlw/competition/add.do?competitionId="+data.competitionId+"&sign=2"; Common.openDlg(url,"大赛管理/编辑大赛"); } } diff --git a/web/src/main/resources/static/js/jlw/resourcesApplicationCourse/index.js b/web/src/main/resources/static/js/jlw/resourcesApplicationCourse/index.js index 4821f0f3..c9b9217f 100644 --- a/web/src/main/resources/static/js/jlw/resourcesApplicationCourse/index.js +++ b/web/src/main/resources/static/js/jlw/resourcesApplicationCourse/index.js @@ -6,7 +6,15 @@ layui.define(['form', 'laydate', 'table'], function (exports) { // 查询去重的标签列表 var selectList = Common.postAjax('/jlw/courseLabel/disLabelType.json').data; var courseLabelList = Common.getAjax('/jlw/courseLabel/getValues.json?courseLabelStatus=1').data; - + var tableReload = table.reload; + table.reload = function () { + var args = []; + layui.each('resourcesApplicationCourseTable', function (index, item) { + args.push(item); + }); + args[2] === undefined && (args[2] = true); + return tableReload.apply(null, args); + }; var view = { init: function () { this.initTable(); @@ -49,14 +57,14 @@ layui.define(['form', 'laydate', 'table'], function (exports) { align: "center", templet: function (d) { var prefix = '\n' + - '\n' + ' '; var content = ''; var suffix = ''; $.each(selectList, function (key, value) { var selected = value == d.courseLabelType ? "selected" : ""; - content += ''; + content += ''; }); return prefix + content + suffix; @@ -69,7 +77,7 @@ layui.define(['form', 'laydate', 'table'], function (exports) { templet: function (d) { var prefix = '\n' + - '\n' + ' '; var content = ''; var suffix = ''; @@ -77,13 +85,13 @@ layui.define(['form', 'laydate', 'table'], function (exports) { var labelList = []; // 一级类型 for (var courseLabel of courseLabelList) { - if(courseLabel.courseLabelType == d.courseLabelType) { + if (courseLabel.courseLabelType == d.courseLabelType) { labelList.push(courseLabel) } } $.each(labelList, function (key, value) { var selected = value.courseLabelId == d.courseLabelId ? "selected" : ""; - content += ''; + content += ''; }); return prefix + content + suffix; @@ -96,7 +104,7 @@ layui.define(['form', 'laydate', 'table'], function (exports) { templet: function (d) { // html字符串转对象,深拷贝操作,相当于每行copy一个下拉框进行回显选中操作 var copyHtml = $($('#selectGxmc').html()) - copyHtml.find("option[value="+d.resourcesApplicationIds+"]").attr("selected", true); + copyHtml.find("option[value=" + d.resourcesApplicationIds + "]").attr("selected", true); return copyHtml.html(); } }, @@ -111,9 +119,24 @@ layui.define(['form', 'laydate', 'table'], function (exports) { } } ]] - /* ,done: function (res, curr, count) { - - }*/ + , done: function (res, curr, count) { + var divForm = $("#" + 'resourcesApplicationCourseTable').next(); // 获取表格,tableId是表格的id + var tableCache = table.cache['resourcesApplicationCourseTable']; // 获取表格缓存数据,tableCacheId也是表格的id + var trJqs = divForm.find(".layui-table-body tr"); // 获取表格body下的所有tr标签 + trJqs.each(function () { // 遍历每个tr标签 + var trJq = $(this); // 获得当前遍历的tr标签 + var dataIndex = trJq.attr("data-index"); // 得到当前数据行的data-index,即为第几行数据 + trJq.find("td").each(function () { // 遍历tr标签下的每一个td标签 + var tdJq = $(this); // 获得当前遍历的td标签 + var fieldName = tdJq.attr("data-field"); // 获得当前td标签的字段名 + var selectJq = tdJq.find("select"); // 获得当前td标签下的select标签 + if (selectJq.length == 1) { // 判断select标签是否存在 + selectJq.eq(0).val(tableCache[dataIndex][fieldName]); // 将表格里的缓存数据赋值给select标签 + } + }); + }); + form.render('select'); // 重新加载select表单 + } }); table.on('checkbox(resourcesApplicationCourseTable)', function (obj) { @@ -162,6 +185,7 @@ layui.define(['form', 'laydate', 'table'], function (exports) { }); }, initTableTool: table.on('tool(resourcesApplicationCourseTable)', function (obj) { var data = obj.data; + //form.render('select'); // 重新加载select表单 if (obj.event === 'edit') { var url = "/jlw/resourcesApplicationCourse/add.do?courseInfoId=" + data.courseInfoId; Common.openDlg(url, ""); @@ -180,7 +204,12 @@ layui.define(['form', 'laydate', 'table'], function (exports) { }); } else if (obj.event === "binding") { layer.confirm('是否确定绑定?', function (index) { - var param = obj.data; + var param = { + courseInfoId: data.courseInfoId, + courseLabelType:data.courseLabelType, + courseLabelId:data.courseLabelId, + resourcesApplicationIds:data.resourcesApplicationIds, + }; var ret = Common.postAjax("/jlw/courseInfo/edit.json", param); layer.msg(ret.code == 0 ? "绑定成功!" : ret.msg, { offset: ['50%'], @@ -197,39 +226,46 @@ layui.define(['form', 'laydate', 'table'], function (exports) { }; //绑定课程名称选择 - form.on('select(select_courseLabelType)', function (obj) { - if(!$.isEmpty(obj.value)){ - var ret = Common.getAjax("/jlw/courseLabel/getValues.json",{courseLabelType:obj.value,courseLabelStatus:1}); - if(ret.code == 0){ + form.on('select(select_one)', function (obj) { + var tableCache = table.cache['resourcesApplicationCourseTable'], // 获得数据表格的缓存数据 + value = obj.value, // 得到下拉列表改变后的value值 + field = obj.othis.parents('td').attr('data-field'), // 获得下拉列表的父级td标签的字段名称 + dataIndex = parseInt(obj.othis.parents('tr').attr('data-index')), // 获得变化的下拉列表所在的行index + lineDate = tableCache[dataIndex]; // 获得数据表格中该行的缓存数据 + if (tableCache[dataIndex][field] != value) { // 判断数据是否发生了变化 + // 这里可以写ajax实现与后台数据的交互 + tableCache[dataIndex][field] = value; // 将修改后的数据更新到数据表格的缓存数据中 + } + if (!$.isEmpty(obj.value)) { + var ret = Common.getAjax("/jlw/courseLabel/getValues.json", { + courseLabelType: obj.value, + courseLabelStatus: 1 + }); + if (ret.code == 0) { var htm = ''; - for (var i = 0;i< ret.data.length;i++){ - htm += ''; + for (var i = 0; i < ret.data.length; i++) { + htm += ''; } $(this).parents("td").siblings('td').eq(1).find('select').empty(); $(this).parents("td").siblings('td').eq(1).find('select').append(htm); + $(obj.elem).prop('checked', !$(obj.elem).prop('checked')); form.render(); } - }else { + } else { $(this).parents("td").siblings('td').eq(1).find('select').empty(); form.render(); } }); - form.on('select(select_)', function (obj) { - var id = obj.value; - return; - var resourcesApplicationCourseId = table.cache['resourcesApplicationCourseTable'][$(this).parents("tr").attr("data-index")].resourcesApplicationCourseId; - if (!$.isEmpty(resourcesApplicationCourseId)) { - var param = { - resourcesApplicationCourseId: resourcesApplicationCourseId, - id: id, - }; - var ret = Common.postAjax("/jlw/resourcesApplicationCourse/edit.json", param); - layer.msg(ret.code == 0 ? "绑定成功!" : ret.msg, { - offset: ['50%'], - icon: ret.code == 0 ? 1 : 2, - time: 1000 //2秒关闭(如果不配置,默认是3秒) - }); + form.on('select(select_UpdateCache)', function (obj) { + var tableCache = table.cache['resourcesApplicationCourseTable'], // 获得数据表格的缓存数据 + value = obj.value, // 得到下拉列表改变后的value值 + field = obj.othis.parents('td').attr('data-field'), // 获得下拉列表的父级td标签的字段名称 + dataIndex = parseInt(obj.othis.parents('tr').attr('data-index')), // 获得变化的下拉列表所在的行index + lineDate = tableCache[dataIndex]; // 获得数据表格中该行的缓存数据 + if (tableCache[dataIndex][field] != value) { // 判断数据是否发生了变化 + // 这里可以写ajax实现与后台数据的交互 + tableCache[dataIndex][field] = value; // 将修改后的数据更新到数据表格的缓存数据中 } }); exports('index', view); diff --git a/web/src/main/resources/templates/jlw/resourcesApplicationCourse/index.html b/web/src/main/resources/templates/jlw/resourcesApplicationCourse/index.html index 69f9a14e..25415e29 100644 --- a/web/src/main/resources/templates/jlw/resourcesApplicationCourse/index.html +++ b/web/src/main/resources/templates/jlw/resourcesApplicationCourse/index.html @@ -27,7 +27,7 @@