Merge pull request #4405 from dataease/pr@dev@pages

feat: API数据源支持输入jsonpath
This commit is contained in:
taojinlong 2023-01-19 15:41:52 +08:00 committed by GitHub
commit a8d72e9076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 42 deletions

View File

@ -164,6 +164,9 @@ public class DatasourceController {
public ApiDefinition checkApiDatasource(@RequestBody Map<String, String> data) throws Exception {
ApiDefinition apiDefinition = new Gson().fromJson(new String(java.util.Base64.getDecoder().decode(data.get("data"))), new TypeToken<ApiDefinition>() {
}.getType());
if(data.keySet().contains("type") && data.get("type").equals("apiStructure")){
apiDefinition.setShowApiStructure(true);
}
return datasourceService.checkApiDatasource(apiDefinition);
}

View File

@ -25,5 +25,6 @@ public class ApiDefinition {
private int serialNumber;
private boolean useJsonPath;
private String jsonPath;
private boolean showApiStructure;
}

View File

@ -186,7 +186,7 @@ public class ApiProvider extends Provider {
throw new Exception("该请求返回数据为空");
}
List<JSONObject> fields = new ArrayList<>();
if (apiDefinition.isUseJsonPath()) {
if (apiDefinition.isUseJsonPath() && !apiDefinition.isShowApiStructure()) {
List<LinkedHashMap> currentData = new ArrayList<>();
Object object = JsonPath.read(response, apiDefinition.getJsonPath());
if (object instanceof List) {

View File

@ -587,51 +587,12 @@
width="255"
>
<template slot-scope="scope">
<el-checkbox
:key="scope.row.jsonPath"
v-model="scope.row.checked"
:disabled="scope.row.disabled"
@change="handleCheckAllChange(originFieldItem, scope.row, 'originPlxTable')"
>
{{ scope.row.originName }}
</el-checkbox>
{{ scope.row.originName }}
</template>
</el-table-column>
</el-table>
</div>
<div class="row-rules" v-show="apiItem.useJsonPath">
<span>{{ $t('dataset.data_preview') }}</span>
</div>
<el-empty
v-if="showEmpty && apiItem.useJsonPath"
size="125"
:image="noneImg"
style="margin-top: 24px"
:description="$t('暂无数据,请在数据结构勾选字段')"
/>
<ux-grid
v-if="!showEmpty && apiItem.useJsonPath"
ref="originPlxTable"
size="mini"
style="width: 100%"
:height="height"
:checkbox-config="{ highlight: true }"
:width-resize="true"
>
<ux-table-column
v-for="field in originFieldItem.fields"
:key="field.name + field.deExtractType"
min-width="200px"
:field="field.name"
:resizable="true"
>
<template slot="header">
<span>{{ field.name }}</span>
</template>
</ux-table-column>
</ux-grid>
</el-form>
</el-row>
<el-row v-show="active === 2">
@ -1221,7 +1182,7 @@ export default {
if (valid) {
const data = Base64.encode(JSON.stringify(this.apiItem))
this.loading = true
checkApiDatasource({'data': data})
checkApiDatasource({'data': data, 'type': 'apiStructure'})
.then((res) => {
res.data.jsonFields.forEach(((item) => {
item.checked = false