From 0264da8d7c871081fbaa8609bd640033d6210916 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 16 Apr 2022 21:42:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E5=AD=90=E8=A1=A8=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=88=97=E6=96=B0=E5=A2=9E=E5=8D=95=E4=B8=AA=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/static/ruoyi/js/common.js | 27 ++++++++++------ .../main/resources/static/ruoyi/js/ry-ui.js | 2 +- .../templates/demo/table/subdata.html | 19 ++++++++--- .../src/main/resources/vm/html/add.html.vm | 31 ++++++++---------- .../src/main/resources/vm/html/edit.html.vm | 32 +++++++++---------- 5 files changed, 61 insertions(+), 50 deletions(-) diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js index ada827974..714719ebc 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js @@ -417,7 +417,7 @@ var storage = { // 主子表操作封装处理 var sub = { - editColumn: function() { + editRow: function() { var dataColumns = []; for (var columnIndex = 0; columnIndex < table.options.columns.length; columnIndex++) { if (table.options.columns[columnIndex].visible != false) { @@ -442,7 +442,11 @@ var sub = { } else if ($.common.isNotEmpty(textareaValue.val())) { obj[key] = textareaValue.val(); } else { - obj[key] = ""; + if (key == "index" && $.common.isNotEmpty(data[dataIndex].index)) { + obj[key] = data[dataIndex].index; + } else { + obj[key] = ""; + } } } var item = data[dataIndex]; @@ -451,8 +455,8 @@ var sub = { } $("#" + table.options.id).bootstrapTable("updateRow", params); }, - delColumn: function(column) { - sub.editColumn(); + delRow: function(column) { + sub.editRow(); var subColumn = $.common.isEmpty(column) ? "index" : column; var ids = $.table.selectColumns(subColumn); if (ids.length == 0) { @@ -461,15 +465,18 @@ var sub = { } $("#" + table.options.id).bootstrapTable('remove', { field: subColumn, values: ids }); }, - addColumn: function(row, tableId) { + delRowByIndex: function(defindex, index) { + sub.editRow(); + var value = $.common.isNotEmpty(index) ? index : defindex; + $("#" + table.options.id).bootstrapTable('remove', { field: "index", values: [value] }); + sub.editRow(); + }, + addRow: function(row, tableId) { var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; table.set(currentId); var count = $("#" + currentId).bootstrapTable('getData').length; - sub.editColumn(); - $("#" + currentId).bootstrapTable('insertRow', { - index: count + 1, - row: row - }); + sub.editRow(); + $("#" + currentId).bootstrapTable('insertRow', { index: count + 1, row: row }); } }; diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js index cf9e0b5af..3bb5182e4 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js @@ -1537,7 +1537,7 @@ var table = { common: { // 判断字符串是否为空 isEmpty: function (value) { - if (value == null || this.trim(value) == "") { + if (value == null || this.trim(value) == "" || value == undefined || value == "undefined") { return true; } return false; diff --git a/ruoyi-admin/src/main/resources/templates/demo/table/subdata.html b/ruoyi-admin/src/main/resources/templates/demo/table/subdata.html index 936d41869..923393d3e 100644 --- a/ruoyi-admin/src/main/resources/templates/demo/table/subdata.html +++ b/ruoyi-admin/src/main/resources/templates/demo/table/subdata.html @@ -62,8 +62,8 @@

商品数据

- - + +
@@ -166,7 +166,14 @@ var data = [{ index: index, type: value }]; return $("#goodsTypeTpl").tmpl(data).html(); } - }] + }, + { + title: '操作', + align: 'center', + formatter: function(value, row, index) { + return '删除'; + } + }] }; $.table.init(options); }); @@ -184,15 +191,17 @@ autoclose: true }); - function addColumn() { + function addRow() { + var count = $("#" + table.options.id).bootstrapTable('getData').length; var row = { + index: $.table.serialNumber(count), name: "", weight: "", price: "", date: "", type: "", } - sub.addColumn(row); + sub.addRow(row); } $("#bootstrap-table").on("post-body.bs.table", function (e, args) { diff --git a/ruoyi-generator/src/main/resources/vm/html/add.html.vm b/ruoyi-generator/src/main/resources/vm/html/add.html.vm index 1529b89d2..2741be7ec 100644 --- a/ruoyi-generator/src/main/resources/vm/html/add.html.vm +++ b/ruoyi-generator/src/main/resources/vm/html/add.html.vm @@ -160,8 +160,8 @@

${subTable.functionName}信息

- - + +
@@ -334,9 +334,7 @@ var name = $.common.sprintf("${subclassName}List[%s].${javaField}", index); return $.common.dictToSelect(${javaField}Datas, value, name); } -#if($foreach.count != $subTable.columns.size()) }, -#end #else { field: '${javaField}', @@ -346,34 +344,33 @@ var html = $.common.sprintf("", index, value); return html; } -#if($foreach.count != $subTable.columns.size()) }, #end #end -#end + { + title: '操作', + align: 'center', + formatter: function(value, row, index) { + return '删除'; + } }] }; $.table.init(options); }); - function addColumn() { + function addRow() { var count = $("#" + table.options.id).bootstrapTable('getData').length; - sub.editColumn(); - - $("#" + table.options.id).bootstrapTable('insertRow', { - index: count, - row: { - index: $.table.serialNumber(count), + var row = { + index: $.table.serialNumber(count), #foreach($column in $subTable.columns) #set($javaField=$column.javaField) #if($column.pk || $javaField == ${subTableFkclassName}) #else - ${javaField}: ""#if($foreach.count != $subTable.columns.size()),#end - + ${javaField}: "", #end #end - } - }); + } + sub.addRow(row); } #end diff --git a/ruoyi-generator/src/main/resources/vm/html/edit.html.vm b/ruoyi-generator/src/main/resources/vm/html/edit.html.vm index 8b405b053..bef945c3b 100644 --- a/ruoyi-generator/src/main/resources/vm/html/edit.html.vm +++ b/ruoyi-generator/src/main/resources/vm/html/edit.html.vm @@ -160,8 +160,8 @@

${subTable.functionName}信息

- - + +
@@ -345,9 +345,7 @@ var name = $.common.sprintf("${subclassName}List[%s].${javaField}", index); return $.common.dictToSelect(${javaField}Datas, value, name); } -#if($foreach.count != $subTable.columns.size()) }, -#end #else { field: '${javaField}', @@ -357,34 +355,34 @@ var html = $.common.sprintf("", index, value); return html; } -#if($foreach.count != $subTable.columns.size()) }, + #end #end -#end + { + title: '操作', + align: 'center', + formatter: function(value, row, index) { + return '删除'; + } }] }; $.table.init(options); }); - function addColumn() { + function addRow() { var count = $("#" + table.options.id).bootstrapTable('getData').length; - sub.editColumn(); - - $("#" + table.options.id).bootstrapTable('insertRow', { - index: count, - row: { - index: $.table.serialNumber(count), + var row = { + index: $.table.serialNumber(count), #foreach($column in $subTable.columns) #set($javaField=$column.javaField) #if($column.pk || $javaField == ${subTableFkclassName}) #else - ${javaField}: ""#if($foreach.count != $subTable.columns.size()),#end - + ${javaField}: "", #end #end - } - }); + } + sub.addRow(row); } #end