diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/DynamicFormFormShowFieldDTO.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/DynamicFormFormShowFieldDTO.java index 485afb7..e71016a 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/DynamicFormFormShowFieldDTO.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/dynamic/DynamicFormFormShowFieldDTO.java @@ -33,6 +33,12 @@ public class DynamicFormFormShowFieldDTO { private String verifyType; @ApiModelProperty(name = "verifyRegular", value = "校验正则") private String verifyRegular; + @ApiModelProperty(name = "joinTable", value = "联表表名") + private String joinTable; + @ApiModelProperty(name = "joinTableField", value = "联表字段") + private String joinTableField; + @ApiModelProperty(name = "joinTableFormShow", value = "联表显示字段") + private String joinTableFormShow; public String getFieldName() { return fieldName == null ? "" : fieldName.trim(); @@ -90,6 +96,30 @@ public class DynamicFormFormShowFieldDTO { this.verifyRegular = verifyRegular; } + public String getJoinTable() { + return joinTable == null ? "" : joinTable.trim(); + } + + public void setJoinTable(String joinTable) { + this.joinTable = joinTable; + } + + public String getJoinTableField() { + return joinTableField == null ? "" : joinTableField.trim(); + } + + public void setJoinTableField(String joinTableField) { + this.joinTableField = joinTableField; + } + + public String getJoinTableFormShow() { + return joinTableFormShow == null ? "" : joinTableFormShow.trim(); + } + + public void setJoinTableFormShow(String joinTableFormShow) { + this.joinTableFormShow = joinTableFormShow; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); @@ -107,6 +137,12 @@ public class DynamicFormFormShowFieldDTO { .append("\"").append(verifyType).append("\""); sb.append(",\"verifyRegular\":") .append("\"").append(verifyRegular).append("\""); + sb.append(",\"joinTable\":") + .append("\"").append(joinTable).append("\""); + sb.append(",\"joinTableField\":") + .append("\"").append(joinTableField).append("\""); + sb.append(",\"joinTableFormShow\":") + .append("\"").append(joinTableFormShow).append("\""); sb.append('}'); return sb.toString(); } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java index 3cb9be9..d42d4e3 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/dynamic/impl/DynamicFormServiceImpl.java @@ -113,16 +113,11 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF public List listFormShowFieldOfPage(String tableName) throws SearchException { List dynamicFormDTOs = listDynamicForm(tableName); List dynamicFormFormShowFieldDTOList = new ArrayList<>(); - int joinIndex = 0; for (DynamicFormDTO dynamicFormDTO : dynamicFormDTOs) { // 显示字段 if (dynamicFormDTO.getFormShow() == 1) { dynamicFormFormShowFieldDTOList.add(getDynamicFormFormShowFieldDTOByDynamicFormDTO(dynamicFormDTO)); } - // 联表字段 - if (isJoinDynamicField(dynamicFormDTO)) { - dynamicFormFormShowFieldDTOList.addAll(listJoinDynamicFormFormShowField(dynamicFormDTO, ++joinIndex)); - } } return dynamicFormFormShowFieldDTOList; } @@ -137,38 +132,18 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF private List listJoinDynamicFormListShowField(DynamicFormDTO dynamicFormDTO, int index) { List dynamicFormListShowFieldDTOList = new ArrayList<>(); Map params = getHashMap(2); - params.put("tableName", WStringUtil.firstToLower(dynamicFormDTO.getJoinTable().replaceFirst("dynamic", ""))); + params.put("tableName", dynamicFormDTO.getJoinTable()); params.put("fieldNameList", Arrays.asList(dynamicFormDTO.getJoinTableListShow().split(","))); List joinDynamicFormDTOs = dynamicFormDao.listDynamicForm(params); for (DynamicFormDTO joinDynamicFormDTO : joinDynamicFormDTOs) { DynamicFormListShowFieldDTO dynamicFormListShowFieldDTO = getDynamicFormListShowFieldDTOByDynamicFormDTO(joinDynamicFormDTO); dynamicFormListShowFieldDTO.setFieldName(String.format("%sJt%d", dynamicFormListShowFieldDTO.getFieldName(), index)); + dynamicFormListShowFieldDTO.setFieldExplain(String.format("%s%d", dynamicFormListShowFieldDTO.getFieldExplain(), index)); dynamicFormListShowFieldDTOList.add(dynamicFormListShowFieldDTO); } return dynamicFormListShowFieldDTOList; } - /** - * 设置动态表单列表 联表 表单显示字段 - * - * @param dynamicFormDTO - * @param index 下标 - * @return - */ - private List listJoinDynamicFormFormShowField(DynamicFormDTO dynamicFormDTO, int index) { - List dynamicFormFormShowFieldDTOList = new ArrayList<>(); - Map params = getHashMap(2); - params.put("tableName", WStringUtil.firstToLower(dynamicFormDTO.getJoinTable().replaceFirst("dynamic", ""))); - params.put("fieldNameList", Arrays.asList(dynamicFormDTO.getJoinTableListShow().split(","))); - List joinDynamicFormDTOs = dynamicFormDao.listDynamicForm(params); - for (DynamicFormDTO joinDynamicFormDTO : joinDynamicFormDTOs) { - DynamicFormFormShowFieldDTO dynamicFormFormShowFieldDTO = getDynamicFormFormShowFieldDTOByDynamicFormDTO(joinDynamicFormDTO); - dynamicFormFormShowFieldDTO.setFieldName(String.format("%sJt%d", dynamicFormFormShowFieldDTO.getFieldName(), index)); - dynamicFormFormShowFieldDTOList.add(dynamicFormFormShowFieldDTO); - } - return dynamicFormFormShowFieldDTOList; - } - /** * 设置动态表单的列表字段 * @@ -198,6 +173,9 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF dynamicFormFormShowFieldDTO.setFieldType(dynamicFormDTO.getFieldType()); dynamicFormFormShowFieldDTO.setVerifyType(dynamicFormDTO.getVerifyType()); dynamicFormFormShowFieldDTO.setVerifyRegular(dynamicFormDTO.getVerifyRegular()); + dynamicFormFormShowFieldDTO.setJoinTable(dynamicFormDTO.getJoinTable()); + dynamicFormFormShowFieldDTO.setJoinTableField(dynamicFormDTO.getJoinTableField()); + dynamicFormFormShowFieldDTO.setJoinTableFormShow(dynamicFormDTO.getJoinTableFormShow()); return dynamicFormFormShowFieldDTO; } @@ -210,7 +188,7 @@ public class DynamicFormServiceImpl extends AbstractService implements IDynamicF Map listShow = new HashMap<>(2); listShow.put("fieldType", dynamicFormDTO.getFieldType()); listShow.put("fieldName", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getFieldName())); - listShow.put("joinTable", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTable())); + listShow.put("joinTable", String.format("%s%s", IDynamicTableService.DYNAMIC_TABLE_PREFIX, WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTable()))); listShow.put("joinTableField", WStringUtil.lowerUpper2UnderLine(dynamicFormDTO.getJoinTableField())); listShow.put("joinTableSort", dynamicFormDTO.getJoinTableSort()); // 构建连表显示字段 diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicdata-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicdata-mapper.xml index 61f5f03..16da410 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicdata-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/dynamic/dynamicdata-mapper.xml @@ -77,26 +77,27 @@ + -
- -
- + -
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
@@ -141,19 +143,19 @@
-
- -
- - -
+
+
+ +
+ +
-
- -
- - -
+
+
+ +
+ +
@@ -187,7 +189,9 @@ parent.layer.close(parent.layer.getFrameIndex(window.name)); } // 初始化 - function initData() {} + function initData() { + + } initData(); // 提交表单 @@ -269,6 +273,125 @@ } }); }); + // 选择联表 + $(document.body).on('click', '#joinTable', function() { + var joinTable = $('#joinTable').val(); + top.dialog.tree({ + title: '选择关联表', + apiUri: top.restAjax.path('api/dynamicconfigtable/listtable', []), + width: '250px', + height: '400px', + dataFilter: function(treeId, parentNode, childNodes) { + for(var i = 0, item = childNodes[i]; item = childNodes[i++];) { + item.name = item.tableName; + item.id = item.tableName; + item.title = item.tableName; + } + return childNodes; + }, + selectedNodes: [{ + id: joinTable, + name: joinTable, + title: joinTable + }], + onClose: function() { + var selectNodes = top.dialog.dialogTreeData.selectedNodes; + if(typeof(selectNodes) != 'undefined' && selectNodes != null) { + if(selectNodes.length > 0) { + $('#joinTable').val(selectNodes[0].id); + $('#joinTableField').val(selectNodes[0].id +'Id'); + $('#joinFieldDetailBox').show(); + } else { + $('#joinTable').val(''); + $('#joinTableField').val(''); + $('#joinFieldDetailBox').hide(); + } + } + } + }); + }); + /** + * 选择字段 + * @param isList 是否列表 + */ + function selectJoinField(isList) { + var check = null; + var selectedNodes = []; + if(isList) { + check = { + enable: true, + selectType: 'checkbox', + checkboxType: {Y: 'ps', N: 'ps'}, + radioType: 'level', + } + var joinTableListShow = $('#joinTableListShow').val(); + if(joinTableListShow) { + var joinTableListShowArray = joinTableListShow.split(','); + for(var i = 0, item; item = joinTableListShowArray[i++];) { + selectedNodes.push({ + id: item, + name: item, + title: item + }) + } + } + + } else { + var joinTableFormShow = $('#joinTableFormShow').val(); + selectedNodes.push({ + id: joinTableFormShow, + name: joinTableFormShow, + title: joinTableFormShow + }); + } + top.dialog.tree({ + title: '选择联表显示字段', + apiUri: top.restAjax.path('api/dynamicconfigtable/dynamicconfigform/listform/{tableName}', [$('#joinTable').val()]), + width: '250px', + height: '400px', + dataFilter: function(treeId, parentNode, childNodes) { + for(var i = 0, item = childNodes[i]; item = childNodes[i++];) { + item.name = item.fieldName; + item.id = item.fieldName; + item.title = item.fieldName; + } + return childNodes; + }, + check: check, + selectedNodes: selectedNodes, + onClose: function() { + var selectNodes = top.dialog.dialogTreeData.selectedNodes; + if(typeof(selectNodes) != 'undefined' && selectNodes != null) { + if(selectNodes.length > 0) { + var selectNodeValue = ''; + for(var j = 0, selectNode = selectNodes[j]; selectNode = selectNodes[j++];) { + if(selectNodeValue.length > 0) { + selectNodeValue += ','; + } + selectNodeValue += selectNode.id; + } + if(isList) { + $('#joinTableListShow').val(selectNodeValue); + } else { + $('#joinTableFormShow').val(selectNodeValue); + } + } else { + if(isList) { + $('#joinTableListShow').val(''); + } else { + $('#joinTableFormShow').val(''); + } + } + } + } + }); + } + $(document.body).on('click', '#joinTableListShow', function() { + selectJoinField(true); + }); + $(document.body).on('click', '#joinTableFormShow', function() { + selectJoinField(false); + }); $('.close').on('click', function() { closeBox(); }); diff --git a/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/update.html b/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/update.html index c5b81c6..b0de938 100644 --- a/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/update.html +++ b/cloud-common-plugin/src/main/resources/templates/dynamic/config/form/update.html @@ -77,31 +77,33 @@
- +
-
- -
- + -
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
-
-
- -
- +
+ +
+ +
@@ -141,19 +143,19 @@
-
- -
- - -
+
+
+ +
+ +
-
- -
- - -
+
+
+ +
+ +
@@ -203,8 +205,8 @@ verifyType: data.verifyType, verifyRegular: data.verifyRegular, fieldSort: data.fieldSort, - listShow: data.listShow, - formShow: data.formShow, + listShow: data.listShow.toString(), + formShow: data.formShow.toString(), joinTable: data.joinTable, joinTableField: data.joinTableField, joinTableSort: data.joinTableSort, @@ -215,6 +217,9 @@ if(data.fieldType === 'leftJoin' || data.fieldType === 'innerJoin' || data.fieldType === 'rightJoin') { $('#normalFieldBox').hide(); $('#joinFieldBox').show(); + if($('#joinTable').val()) { + $('#joinFieldDetailBox').show(); + } } else { $('#joinFieldBox').hide(); $('#normalFieldBox').show(); @@ -308,6 +313,125 @@ } }); }); + // 选择联表 + $(document.body).on('click', '#joinTable', function() { + var joinTable = $('#joinTable').val(); + top.dialog.tree({ + title: '选择关联表', + apiUri: top.restAjax.path('api/dynamicconfigtable/listtable', []), + width: '250px', + height: '400px', + dataFilter: function(treeId, parentNode, childNodes) { + for(var i = 0, item = childNodes[i]; item = childNodes[i++];) { + item.name = item.tableName; + item.id = item.tableName; + item.title = item.tableName; + } + return childNodes; + }, + selectedNodes: [{ + id: joinTable, + name: joinTable, + title: joinTable + }], + onClose: function() { + var selectNodes = top.dialog.dialogTreeData.selectedNodes; + if(typeof(selectNodes) != 'undefined' && selectNodes != null) { + if(selectNodes.length > 0) { + $('#joinTable').val(selectNodes[0].id); + $('#joinTableField').val(selectNodes[0].id +'Id'); + $('#joinFieldDetailBox').show(); + } else { + $('#joinTable').val(''); + $('#joinTableField').val(''); + $('#joinFieldDetailBox').hide(); + } + } + } + }); + }); + /** + * 选择字段 + * @param isList 是否列表 + */ + function selectJoinField(isList) { + var check = null; + var selectedNodes = []; + if(isList) { + check = { + enable: true, + selectType: 'checkbox', + checkboxType: {Y: 'ps', N: 'ps'}, + radioType: 'level', + } + var joinTableListShow = $('#joinTableListShow').val(); + if(joinTableListShow) { + var joinTableListShowArray = joinTableListShow.split(','); + for(var i = 0, item; item = joinTableListShowArray[i++];) { + selectedNodes.push({ + id: item, + name: item, + title: item + }) + } + } + + } else { + var joinTableFormShow = $('#joinTableFormShow').val(); + selectedNodes.push({ + id: joinTableFormShow, + name: joinTableFormShow, + title: joinTableFormShow + }); + } + top.dialog.tree({ + title: '选择联表显示字段', + apiUri: top.restAjax.path('api/dynamicconfigtable/dynamicconfigform/listform/{tableName}', [$('#joinTable').val()]), + width: '250px', + height: '400px', + dataFilter: function(treeId, parentNode, childNodes) { + for(var i = 0, item = childNodes[i]; item = childNodes[i++];) { + item.name = item.fieldName; + item.id = item.fieldName; + item.title = item.fieldName; + } + return childNodes; + }, + check: check, + selectedNodes: selectedNodes, + onClose: function() { + var selectNodes = top.dialog.dialogTreeData.selectedNodes; + if(typeof(selectNodes) != 'undefined' && selectNodes != null) { + if(selectNodes.length > 0) { + var selectNodeValue = ''; + for(var j = 0, selectNode = selectNodes[j]; selectNode = selectNodes[j++];) { + if(selectNodeValue.length > 0) { + selectNodeValue += ','; + } + selectNodeValue += selectNode.id; + } + if(isList) { + $('#joinTableListShow').val(selectNodeValue); + } else { + $('#joinTableFormShow').val(selectNodeValue); + } + } else { + if(isList) { + $('#joinTableListShow').val(''); + } else { + $('#joinTableFormShow').val(''); + } + } + } + } + }); + } + $(document.body).on('click', '#joinTableListShow', function() { + selectJoinField(true); + }); + $(document.body).on('click', '#joinTableFormShow', function() { + selectJoinField(false); + }); $('.close').on('click', function() { closeBox(); }); diff --git a/cloud-common-plugin/src/main/resources/templates/dynamic/form/savedynamicform.html b/cloud-common-plugin/src/main/resources/templates/dynamic/form/savedynamicform.html index fefcab0..121e74e 100644 --- a/cloud-common-plugin/src/main/resources/templates/dynamic/form/savedynamicform.html +++ b/cloud-common-plugin/src/main/resources/templates/dynamic/form/savedynamicform.html @@ -106,6 +106,7 @@
+
@@ -113,6 +114,7 @@
+
@@ -120,6 +122,19 @@
+ +
+ +
+ +
@@ -343,6 +358,15 @@ } }); }); + } else if(item.fieldType === 'leftJoin' || item.fieldType === 'innerJoin' || item.fieldType === 'rightJoin') { + top.restAjax.get(top.restAjax.path('api/dynamicdata/listdynamicdata/{tableName}', [item.joinTable]), {}, {fieldName: item.fieldName}, function(code, data, args) { + laytpl(document.getElementById(args.fieldName +'Template').innerHTML).render(data, function(html) { + document.getElementById(args.fieldName +'TemplateBox').innerHTML = html; + }); + form.render('select', args.fieldName +'TemplateBox'); + }, function(code, data) { + top.dialog.msg(data.msg); + }); } } } diff --git a/cloud-common-plugin/src/main/resources/templates/dynamic/form/updatedynamicform.html b/cloud-common-plugin/src/main/resources/templates/dynamic/form/updatedynamicform.html index b2b37e6..d4ca10a 100644 --- a/cloud-common-plugin/src/main/resources/templates/dynamic/form/updatedynamicform.html +++ b/cloud-common-plugin/src/main/resources/templates/dynamic/form/updatedynamicform.html @@ -106,6 +106,7 @@
+
@@ -113,6 +114,7 @@
+
@@ -120,6 +122,19 @@
+ +
+ +
+ +
@@ -398,6 +413,20 @@ } }); }); + } else if(item.fieldType === 'leftJoin' || item.fieldType === 'innerJoin' || item.fieldType === 'rightJoin') { + top.restAjax.get(top.restAjax.path('api/dynamicdata/listdynamicdata/{tableName}', [item.joinTable]), {}, {fieldName: item.fieldName}, function(code, data, args) { + laytpl(document.getElementById(args.fieldName +'Template').innerHTML).render(data, function(html) { + document.getElementById(args.fieldName +'TemplateBox').innerHTML = html; + }); + // 初始化选择 + var formSelectData = {}; + formSelectData[args.fieldName] = dataFormData[args.fieldName]; + form.val('dataForm', formSelectData); + // 刷新 + form.render('select', args.fieldName +'TemplateBox'); + }, function(code, data) { + top.dialog.msg(data.msg); + }); } } }, function(code, data) { diff --git a/cloud-common-plugin/src/main/resources/templates/dynamic/form/updatedynamicjoinform.html b/cloud-common-plugin/src/main/resources/templates/dynamic/form/updatedynamicjoinform.html index 8ba88dd..5341271 100644 --- a/cloud-common-plugin/src/main/resources/templates/dynamic/form/updatedynamicjoinform.html +++ b/cloud-common-plugin/src/main/resources/templates/dynamic/form/updatedynamicjoinform.html @@ -100,6 +100,7 @@
+
@@ -107,6 +108,7 @@
+
@@ -114,6 +116,19 @@
+ +
+ +
+ +
@@ -397,6 +412,20 @@ } }); }); + } else if(item.fieldType === 'leftJoin' || item.fieldType === 'innerJoin' || item.fieldType === 'rightJoin') { + top.restAjax.get(top.restAjax.path('api/dynamicdata/listdynamicdata/{tableName}', [item.joinTable]), {}, {fieldName: item.fieldName}, function(code, data, args) { + laytpl(document.getElementById(args.fieldName +'Template').innerHTML).render(data, function(html) { + document.getElementById(args.fieldName +'TemplateBox').innerHTML = html; + }); + // 初始化选择 + var formSelectData = {}; + formSelectData[args.fieldName] = dataFormData[args.fieldName]; + form.val('dataForm', formSelectData); + // 刷新 + form.render('select', args.fieldName +'TemplateBox'); + }, function(code, data) { + top.dialog.msg(data.msg); + }); } } }, function(code, data) {