Commit 2e2ae7e2 authored by 邢磊's avatar 邢磊

*)增加图片附件

parent e140c8c2
......@@ -93,16 +93,22 @@ public class DPSubServiceImpl {
this.processShowHideRules(children, showHideRules, apiResult);
List<Object> noHiddenChildren = children.stream().filter(x -> !"hidden".equals(JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.behavior"))).collect(Collectors.toList());
// 设置一个图片附件分组
JSONObject matinfo = new JSONObject();
matinfo.put("displayName", "图片附件");
matinfo.put("renderType", "matui");
matinfo.put("datas", new JSONArray());
for (int i = 0; i < noHiddenChildren.size(); i++) {
JSONObject yObj = (JSONObject) noHiddenChildren.get(i);
if ("pageSection".equals(yObj.get("componentKey")) || "columnsLayout".equals(yObj.get("componentKey"))) { // 分组或者布局容器
List<Object> mergedArray = mergedList(yObj.getJSONArray("children"));
// 第一组去除标题
if (i == 0 || ValidationUtil.isEmpty(map.get("datas"))) {
this.buildContentData(map, mergedArray, apiResult);
this.buildContentData(map, mergedArray, apiResult, matinfo);
} else {
this.buildSubContentData(map, i, yObj, mergedArray, apiResult);
this.buildSubContentData(map, i, yObj, mergedArray, apiResult, matinfo);
}
} else if ("subForm".equals(yObj.get("componentKey"))) { // 子表单
this.buildSubFormData(map, i, yObj, apiResult);
......@@ -124,6 +130,11 @@ public class DPSubServiceImpl {
content.put(tab.getString("key"), map);
}
}
if (!ValidationUtil.isEmpty(matinfo.getJSONArray("datas"))){
matinfo.put("columns", map.getJSONObject("basic").getString("columns"));
map.getJSONArray("subs").add(matinfo);
}
} else {
if (ValidationUtil.isEmpty(map)) {
content.put(tab.getString("key"), apiResult);
......@@ -275,7 +286,7 @@ public class DPSubServiceImpl {
return mergedArray;
}
public JSONObject buildContentData(JSONObject map, List<Object> mergedArray, JSONObject apiResult) {
public JSONObject buildContentData(JSONObject map, List<Object> mergedArray, JSONObject apiResult, JSONObject matinfo) {
JSONArray datas = new JSONArray();
// 处理二维码
mergedArray.stream().filter(x -> "QRCode".equals(JsonValueUtils.getValueByKey(x, "componentKey", null))).findFirst().ifPresent(x -> {
......@@ -302,17 +313,18 @@ public class DPSubServiceImpl {
});
mergedArray = mergedArray.stream().filter(x -> !"QRCode".equals(JsonValueUtils.getValueByKey(x, "componentKey", null))).collect(Collectors.toList());
mergedArray.stream().forEach(x -> {
Object fieldKey = JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.fieldKey");
if (!ValidationUtil.isEmpty(fieldKey)) {
this.processWidgets(datas, x, fieldKey.toString(), apiResult);
this.processWidgets(datas, x, fieldKey.toString(), apiResult, matinfo);
}
});
map.put("datas", datas);
return map;
}
public JSONObject buildSubContentData(JSONObject map, int i, JSONObject yObj, List<Object> mergedArray, JSONObject apiResult) {
public JSONObject buildSubContentData(JSONObject map, int i, JSONObject yObj, List<Object> mergedArray, JSONObject apiResult, JSONObject matinfo) {
JSONArray subs = map.getJSONArray("subs");
JSONArray children = yObj.getJSONArray("children");
List<Object> columnsArray = children.stream().filter(x -> {
......@@ -330,7 +342,7 @@ public class DPSubServiceImpl {
mergedArray.stream().forEach(x -> {
Object fieldKey = JsonValueUtils.getValueByKey(x, "visualParams", "visualParams.fieldKey");
if (!ValidationUtil.isEmpty(fieldKey)) {
this.processWidgets(datas, x, fieldKey.toString(), apiResult);
this.processWidgets(datas, x, fieldKey.toString(), apiResult, matinfo);
subObj.put("datas", datas);
}
});
......@@ -347,18 +359,26 @@ public class DPSubServiceImpl {
* @param apiResult
* @return
*/
public JSONArray processWidgets(JSONArray datas, Object x, String fieldKey, JSONObject apiResult) {
public JSONArray processWidgets(JSONArray datas, Object x, String fieldKey, JSONObject apiResult, JSONObject matinfo) {
JSONObject jsonObject = new JSONObject();
JSONObject xObj = (JSONObject) x;
JSONObject visualParams = xObj.getJSONObject("visualParams");
jsonObject.put("label", visualParams.getString("label"));
Object value = apiResult.get(fieldKey);
if ("upload".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "img");
if (!ValidationUtil.isEmpty(value)) {
jsonObject.put("value", ((JSONArray) value).getJSONObject(0).getString("url"));
}
} else if ("attachmentUpload".equals(xObj.getString("componentKey"))) {
JSONArray attachmentUploadDatas = matinfo.getJSONArray("datas");
if (!ValidationUtil.isEmpty(value)) {
JSONObject attachmentUploadDatasObj = new JSONObject();
attachmentUploadDatasObj.put("value", value);
attachmentUploadDatas.add(attachmentUploadDatasObj);
}
} else if ("checkbox".equals(xObj.getString("componentKey"))) {
jsonObject.put("type", "text");
ResponseModel checkboxResult = this.getApiResult(visualParams.getJSONObject("api"), null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment