From 43cb0b854e94ba7fafd3d7e2ba5763d91bc140a7 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Thu, 21 Jul 2022 17:34:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=95=B0=E6=8D=AE=E6=BA=90):=20API=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=BA=90=E6=94=AF=E6=8C=81=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=8F=8A=E7=BB=84=E5=90=88=E5=A4=9A=E5=B1=82=E7=BA=A7=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../provider/datasource/ApiProvider.java | 28 ++--- .../system/datasource/DsConfiguration.vue | 103 ++++++++++-------- 2 files changed, 74 insertions(+), 57 deletions(-) diff --git a/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java b/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java index 6c26d8b357..1afd3adc47 100644 --- a/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java +++ b/backend/src/main/java/io/dataease/provider/datasource/ApiProvider.java @@ -209,30 +209,28 @@ public class ApiProvider extends Provider { for (String s : jsonObject.keySet()) { String value = jsonObject.getString(s); if (StringUtils.isNotEmpty(value) && value.startsWith("[")) { - rootPath = rootPath + "." + s; JSONArray jsonArray = JSONObject.parseArray(jsonObject.getString(s)); List children = new ArrayList<>(); for (Object o : jsonArray) { - handleStr(apiDefinition, o.toString(), children, rootPath + "[*]"); + handleStr(apiDefinition, o.toString(), children, rootPath + "." + s + "[*]"); } JSONObject o = new JSONObject(); o.put("children", children); o.put("childrenDataType", "LIST"); - o.put("jsonPath", rootPath); + o.put("jsonPath", rootPath + "." + s); setProperty(apiDefinition, o, s); - if (!hasItem(objects, o, null)) { + if (!hasItem(apiDefinition, objects, o, null)) { objects.add(o); } } else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) { List children = new ArrayList<>(); - rootPath = rootPath + "." + s; - handleStr(apiDefinition, jsonObject.getString(s), children, rootPath); + handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + s); JSONObject o = new JSONObject(); o.put("children", children); o.put("childrenDataType", "OBJECT"); - o.put("jsonPath", rootPath); + o.put("jsonPath", rootPath + "." + s); setProperty(apiDefinition, o, s); - if (!hasItem(objects, o, null)) { + if (!hasItem(apiDefinition, objects, o, null)) { objects.add(o); } } else { @@ -240,7 +238,7 @@ public class ApiProvider extends Provider { o.put("children", null); o.put("jsonPath", rootPath + "." + s); setProperty(apiDefinition, o, s); - if (!hasItem(objects, o, StringUtils.isNotEmpty(jsonObject.getString(s))? jsonObject.getString(s) : "")) { + if (!hasItem(apiDefinition, objects, o, StringUtils.isNotEmpty(jsonObject.getString(s))? jsonObject.getString(s) : "")) { JSONArray array = new JSONArray(); array.add(StringUtils.isNotEmpty(jsonObject.getString(s))? jsonObject.getString(s) : ""); o.put("value", array); @@ -272,17 +270,19 @@ public class ApiProvider extends Provider { } - static private boolean hasItem(List objects, JSONObject o, String value) { + static private boolean hasItem(ApiDefinition apiDefinition, List objects, JSONObject item, String value) { boolean has = false; for (JSONObject object : objects) { - JSONObject jsonObject = JSONObject.parseObject(object.toJSONString()); jsonObject.remove("value"); jsonObject.remove("id"); - if (Md5Utils.md5(jsonObject.toString()).equals(Md5Utils.md5(o.toString()))) { + jsonObject.remove("children"); + JSONObject o = JSONObject.parseObject(item.toJSONString()); + o.remove("children"); + if (object.getString("jsonPath").equals(item.getString("jsonPath")) ) { has = true; - if(value != null){ - JSONArray array = object.getJSONArray("value"); + JSONArray array = object.getJSONArray("value"); + if(value != null && array.size() < apiDefinition.getPreviewNum()){ array.add(value); object.put("value", array); } diff --git a/frontend/src/views/system/datasource/DsConfiguration.vue b/frontend/src/views/system/datasource/DsConfiguration.vue index c92aaac26c..a63f32b8a6 100644 --- a/frontend/src/views/system/datasource/DsConfiguration.vue +++ b/frontend/src/views/system/datasource/DsConfiguration.vue @@ -13,14 +13,14 @@ > - + + show-overflow-tooltip /> + show-overflow-tooltip /> + show-overflow-tooltip />