diff --git a/core/core-backend/src/main/java/io/dataease/datasource/manage/DataSourceManage.java b/core/core-backend/src/main/java/io/dataease/datasource/manage/DataSourceManage.java index d602ce65b8..61322e95cc 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/manage/DataSourceManage.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/manage/DataSourceManage.java @@ -126,7 +126,7 @@ public class DataSourceManage { } } - @XpackInteract(value = "larkManageInteract", before = true) + @XpackInteract(value = "larkManage", replace = true) public String getTenantAccessToken() { return null; } diff --git a/core/core-backend/src/main/java/io/dataease/datasource/provider/ApiUtils.java b/core/core-backend/src/main/java/io/dataease/datasource/provider/ApiUtils.java index b3df1c0bef..aaeb4f4ecf 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/provider/ApiUtils.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/provider/ApiUtils.java @@ -35,7 +35,7 @@ public class ApiUtils { private static TypeReference>> listForMapTypeReference = new TypeReference>>() { }; - public static List getTables(DatasourceRequest datasourceRequest) throws DEException { + public static List getApiTables(DatasourceRequest datasourceRequest) throws DEException { List tableDescs = new ArrayList<>(); TypeReference> listTypeReference = new TypeReference>() { }; @@ -71,7 +71,7 @@ public class ApiUtils { } - public static Map fetchResultField(DatasourceRequest datasourceRequest) throws DEException { + public static Map fetchApiResultField(DatasourceRequest datasourceRequest) throws DEException { Map result = new HashMap<>(); List dataList = new ArrayList<>(); List fieldList = new ArrayList<>(); @@ -152,7 +152,7 @@ public class ApiUtils { return tableFields; } - public static String checkStatus(DatasourceRequest datasourceRequest) throws Exception { + public static String checkAPIStatus(DatasourceRequest datasourceRequest) throws Exception { TypeReference> listTypeReference = new TypeReference>() { }; List apiDefinitionList = JsonUtil.parseList(datasourceRequest.getDatasource().getConfiguration(), listTypeReference); diff --git a/core/core-frontend/src/views/visualized/data/datasource/form/ApiHttpRequestDraw.vue b/core/core-frontend/src/views/visualized/data/datasource/form/ApiHttpRequestDraw.vue index bd34ff60d1..76810c5346 100644 --- a/core/core-frontend/src/views/visualized/data/datasource/form/ApiHttpRequestDraw.vue +++ b/core/core-frontend/src/views/visualized/data/datasource/form/ApiHttpRequestDraw.vue @@ -15,6 +15,7 @@ import { fieldType } from '@/utils/attr' import type { ApiConfiguration } from '@/views/visualized/data/datasource/form/option' import { cancelMap } from '@/config/axios/service' import { iconFieldMap } from '@/components/icon-group/field-list' +import { PluginComponent } from '@/components/plugin' export interface Field { name: string @@ -29,6 +30,9 @@ export interface ApiItem { status: string name: string type: string + appToken: string + tableId: string + viewId: string deTableName?: string url: string copy: boolean @@ -109,6 +113,7 @@ const columns = shallowRef([]) const valueList = shallowRef([]) const tableData = shallowRef([]) const apiItemBasicInfo = ref() +const xpackApiItemBasicInfo = ref() const isSupportSetKey = ref(false) const isNumber = (rule, value, callback) => { if (!value) { @@ -166,11 +171,29 @@ const rule = reactive({ const activeName = ref('table') const editItem = ref(false) const copyItem = ref(false) +const dsType = ref('API') +const jsName = ref('') +const isPlugin = ref(false) +const pluginDs = ref([]) +const pluginIndex = ref('') const copyDs = ref(false) provide('api-active-name', activeName) -const initApiItem = (val: ApiItem, from, name, edit, supportSetKey) => { +const initApiItem = ( + val: ApiItem, + from, + name, + edit, + supportSetKey, + pluginDsList, + indexPlugin, + isPluginDs +) => { + pluginDs.value = pluginDsList + pluginIndex.value = indexPlugin + isPlugin.value = isPluginDs copyItem.value = val.copy copyDs.value = from.copy + dsType.value = from.type isSupportSetKey.value = supportSetKey activeName.value = name editItem.value = edit @@ -179,6 +202,9 @@ const initApiItem = (val: ApiItem, from, name, edit, supportSetKey) => { if (from.paramsConfiguration) { paramsList = from.paramsConfiguration } + if (isPlugin.value) { + jsName.value = getPluginStatic() + } valueList.value = [] if (val.type !== 'params' && paramsList) { for (let i = 0; i < paramsList.length; i++) { @@ -189,7 +215,14 @@ const initApiItem = (val: ApiItem, from, name, edit, supportSetKey) => { edit_api_item.value = true active.value = 0 nextTick(() => { - apiItemBasicInfo.value.clearValidate() + if (isPlugin.value) { + xpackApiItemBasicInfo?.value?.invokeMethod({ + methodName: 'clearForm', + args: [] + }) + } else { + apiItemBasicInfo.value.clearValidate() + } }) } @@ -200,7 +233,7 @@ const showApiData = () => { const params = Base64.encode(JSON.stringify(paramsList)) loading.value = true cancelMap['/datasource/checkApiDatasource']?.() - checkApiItem({ data: data, type: 'apiStructure', paramsList: params }) + checkApiItem({ dsType: dsType.value, data: data, type: 'apiStructure', paramsList: params }) .then(response => { originFieldItem.jsonFields = response.data.jsonFields }) @@ -323,80 +356,101 @@ const before = () => { active.value -= 1 } const next = () => { - apiItemBasicInfo.value.validate(val => { - if (val) { - if (apiItem.useJsonPath && !apiItem.jsonPath) { - ElMessage.error(t('datasource.please_input_dataPath')) + console.log(apiItem) + if (isPlugin.value) { + } else { + apiItemBasicInfo.value.validate(val => { + if (!val) { return } - if (apiItem.type === 'params') { - for (let i = 0; i < paramsList.length; i++) { - if ( - paramsList[i].name === apiItem.name && - apiItem.serialNumber !== paramsList[i].serialNumber - ) { - ElMessage.error(t('data_source.name_already_exists_de')) - return - } - } - } else { - for (let i = 0; i < apiItemList.length; i++) { - if ( - apiItemList[i].name === apiItem.name && - apiItem.serialNumber !== apiItemList[i].serialNumber - ) { - ElMessage.error(t('datasource.has_repeat_name')) - return - } - } + }) + } + if (apiItem.useJsonPath && !apiItem.jsonPath) { + ElMessage.error(t('datasource.please_input_dataPath')) + return + } + if (apiItem.type === 'params') { + for (let i = 0; i < paramsList.length; i++) { + if ( + paramsList[i].name === apiItem.name && + apiItem.serialNumber !== paramsList[i].serialNumber + ) { + ElMessage.error(t('data_source.name_already_exists_de')) + return } - - cancelMap['/datasource/checkApiDatasource']?.() - - const params = Base64.encode(JSON.stringify(paramsList)) - disabledNext.value = true - formLoading.value = true - checkApiItem({ data: Base64.encode(JSON.stringify(apiItem)), paramsList: params }) - .then(response => { - disabledNext.value = false - formLoading.value = false - apiItem.jsonFields = response.data.jsonFields - apiItem.fields = [] - handleFiledChange(apiItem) - previewData() - active.value += 1 - }) - .catch(error => { - disabledNext.value = false - formLoading.value = false - console.warn(error?.message) - }) } + } else { + for (let i = 0; i < apiItemList.length; i++) { + if ( + apiItemList[i].name === apiItem.name && + apiItem.serialNumber !== apiItemList[i].serialNumber + ) { + ElMessage.error(t('datasource.has_repeat_name')) + return + } + } + } + cancelMap['/datasource/checkApiDatasource']?.() + const params = Base64.encode(JSON.stringify(paramsList)) + disabledNext.value = true + formLoading.value = true + checkApiItem({ + dsType: dsType.value, + data: Base64.encode(JSON.stringify(apiItem)), + paramsList: params }) + .then(response => { + disabledNext.value = false + formLoading.value = false + apiItem.jsonFields = response.data.jsonFields + apiItem.fields = [] + apiItem.name = response.data.name + handleFiledChange(apiItem) + previewData() + active.value += 1 + }) + .catch(error => { + disabledNext.value = false + formLoading.value = false + console.warn(error?.message) + }) } const validate = () => { - apiItemBasicInfo.value.validate(val => { - if (val) { - if (apiItem.useJsonPath && !apiItem.jsonPath) { - ElMessage.error(t('datasource.please_input_dataPath')) + if (isPlugin.value) { + xpackApiItemBasicInfo?.value?.invokeMethod({ + methodName: 'submitForm', + args: [apiItem] + }) + } else { + apiItemBasicInfo.value.validate(val => { + if (!val) { return } - cancelMap['/datasource/checkApiDatasource']?.() - const params = Base64.encode(JSON.stringify(paramsList)) - checkApiItem({ data: Base64.encode(JSON.stringify(apiItem)), paramsList: params }) - .then(response => { - apiItem.jsonFields = response.data.jsonFields - apiItem.fields = [] - handleFiledChange(apiItem) - previewData() - ElMessage.success(t('datasource.validate_success')) - }) - .catch(() => { - ElMessage.error(t('data_source.verification_failed')) - }) - } + }) + } + if (apiItem.useJsonPath && !apiItem.jsonPath) { + ElMessage.error(t('datasource.please_input_dataPath')) + return + } + cancelMap['/datasource/checkApiDatasource']?.() + const params = Base64.encode(JSON.stringify(paramsList)) + checkApiItem({ + dsType: dsType.value, + data: Base64.encode(JSON.stringify(apiItem)), + paramsList: params }) + .then(response => { + apiItem.jsonFields = response.data.jsonFields + apiItem.fields = [] + apiItem.name = response.data.name + handleFiledChange(apiItem) + previewData() + ElMessage.success(t('datasource.validate_success')) + }) + .catch(() => { + ElMessage.error(t('data_source.verification_failed')) + }) } const closeEditItem = () => { cancelMap['/datasource/checkApiDatasource']?.() @@ -537,6 +591,18 @@ const changeId = (val: string) => { const activeColumnInfo = ref(true) const activeDataPreview = ref(true) + +const getPluginStatic = () => { + const arr = pluginDs.value.filter(ele => { + return ele.type === dsType.value + }) + return pluginIndex.value + ? pluginIndex.value + : arr && arr.length > 0 + ? arr[0].staticMap?.index + : null +} + const returnAPIItem = defineEmits(['returnItem']) defineExpose({ @@ -584,7 +650,7 @@ defineExpose({ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { form.value, activeName.value, editItem, - isSupportSetKey.value + isSupportSetKey.value, + pluginDs.value, + pluginIndex.value, + isPlugin.value ) }) } @@ -850,7 +853,7 @@ defineExpose({ show-word-limit /> -