Bläddra i källkod

feat:修改http数据集数据预览

liu.shiyi 1 år sedan
förälder
incheckning
f4ceeb35c1

+ 7 - 1
data-room-ui/packages/DataSetManagement/src/HttpEditForm.vue

@@ -504,6 +504,7 @@
             :data="dataPreviewList"
             max-height="400"
             :border="true"
+            height="500px"
             class="bs-el-table bs-scrollbar"
           >
             <el-table-column
@@ -987,7 +988,12 @@ export default {
         if (this.dataForm.config.requestType === 'frontend') {
           // this.replaceParams(this.dataForm.config.paramsList)
           axiosFormatting({ ...this.dataForm.config }).then((res) => {
-            this.dataPreviewList = res.data && Array.isArray(res.data) ? res.data : []
+            const { resp, response } = res
+            // this.dataPreviewList = res.data && Array.isArray(res.data) ? res.data : []
+            this.dataPreviewList = [{}]
+            for (const item in response.data) {
+              this.dataPreviewList[0][item] = response.data[item]
+            }
             // 获取数据后更新输出字段
             this.updateOoutputFieldList(this.dataPreviewList)
             this.$message.success('解析并执行成功')

+ 2 - 0
data-room-ui/packages/js/mixins/commonMixins.js

@@ -77,6 +77,7 @@ export default {
           if (res.executionByFrontend) {
             if (res.data.datasetType === 'http') {
               _res = await axiosFormatting(res.data)
+              _res = _res.resp
             }
             if (res.data.datasetType === 'js') {
               try {
@@ -123,6 +124,7 @@ export default {
           if (res.executionByFrontend) {
             if (res.data.datasetType === 'http') {
               _res = await axiosFormatting(res.data)
+              _res = _res.resp
             }
             if (res.data.datasetType === 'js') {
               try {

+ 9 - 10
data-room-ui/packages/js/utils/httpParamsFormatting.js

@@ -33,19 +33,18 @@ export default function axiosFormatting (customConfig) {
 
   /** 添加响应拦截器  **/
   instance.interceptors.response.use(response => {
-    if (response.data.code === 200) {
-      // 执行响应脚本
-      // eslint-disable-next-line no-new-func
+    console.log('response', response)
+    // 执行响应脚本
+    // eslint-disable-next-line no-new-func
+    if (newCustomConfig.responseScript) {
       const getResp = new Function('response', newCustomConfig.responseScript)
       const resp = getResp(response)
-      console.log(resp)
-      return Promise.resolve(resp)
+      console.log('resp', resp)
+      return Promise.resolve({ resp, response })
     } else {
-      Message({
-        message: response.data.message,
-        type: 'error'
-      })
-      return Promise.reject(response.data.message)
+      console.log(response.data)
+      const resp = response
+      return Promise.resolve({ resp, response })
     }
   })
   const body = {}