ソースを参照

feat:http数据集添加g2plot前端代理处理

liu.shiyi 1 年間 前
コミット
9c3f0f38f7

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

@@ -980,7 +980,6 @@ export default {
             this.dataPreviewList = res.data
             // 获取数据后更新输出字段
             this.updateOoutputFieldList(this.dataPreviewList)
-            console.log(res)
           })
         } else {
           // 如果是后端代理,则将配置传到后端

+ 14 - 32
data-room-ui/packages/js/mixins/commonMixins.js

@@ -71,28 +71,13 @@ export default {
           pageCode: this.pageCode,
           size: size,
           type: config.type
-        }).then((res) => {
+        }).then(async (res) => {
+          let _res = _.cloneDeep(res)
           // 如果是http数据集的前端代理,则需要调封装的axios请求
-          // if (data.executionByFrontend) {
-          //   axiosFormatting(data.data).then(res => {
-          //     config = this.dataFormatting(config, res)
-          //     this.changeChartConfig(config)
-          //   })
-          // }
-          // if (data.datasetType !== 'http' && data.executionByFrontend) {
-          //   try {
-          //     const scriptAfterReplacement = data.data.replace(/\${(.*?)}/g, (match, p) => {
-          //       // 根据parmas的key获取value
-          //       return `'${this.config.dataSource?.params[p]}' || '${p}'`
-          //     })
-          //     // eslint-disable-next-line no-new-func
-          //     const scriptMethod = new Function(scriptAfterReplacement)
-          //     data.data = scriptMethod()
-          //   } catch (error) {
-          //     console.error('数据集脚本执行失败', error)
-          //   }
-          // }
           if (res.executionByFrontend) {
+            if (res.data.datasetType === 'http') {
+              _res = await axiosFormatting(res.data)
+            }
             if (res.data.datasetType === 'js') {
               try {
                 const scriptAfterReplacement = res.data.script.replace(/\${(.*?)}/g, (match, p) => {
@@ -101,13 +86,13 @@ export default {
                 })
                 // eslint-disable-next-line no-new-func
                 const scriptMethod = new Function(scriptAfterReplacement)
-                res.data = scriptMethod()
+                _res.data = scriptMethod()
               } catch (error) {
                 console.error('JS数据集脚本执行失败', error)
               }
             }
           }
-          config = this.dataFormatting(config, res)
+          config = this.dataFormatting(config, _res)
           this.changeChartConfig(config)
         }).catch((err) => {
           console.error(err)
@@ -132,15 +117,13 @@ export default {
         filterList: filterList || this.filterList
       }
       return new Promise((resolve, reject) => {
-        getUpdateChartInfo(params).then((res) => {
+        getUpdateChartInfo(params).then(async (res) => {
+          let _res = _.cloneDeep(res)
           // 如果是http数据集的前端代理,则需要调封装的axios请求
-          // if (data.executionByFrontend) {
-          //   axiosFormatting(data.data).then(res => {
-          //     config = this.dataFormatting(config, res)
-          //     this.changeChartConfig(config)
-          //   })
-          // }
           if (res.executionByFrontend) {
+            if (res.data.datasetType === 'http') {
+              _res = await axiosFormatting(res.data)
+            }
             if (res.data.datasetType === 'js') {
               try {
                 const scriptAfterReplacement = res.data.script.replace(/\${(.*?)}/g, (match, p) => {
@@ -149,14 +132,13 @@ export default {
                 })
                 // eslint-disable-next-line no-new-func
                 const scriptMethod = new Function(scriptAfterReplacement)
-                res.data = scriptMethod()
+                _res.data = scriptMethod()
               } catch (error) {
                 console.error('JS数据集脚本执行失败', error)
               }
             }
           }
-          config = this.dataFormatting(config, res)
-          this.changeChartConfig(config)
+          config = this.dataFormatting(config, _res)
           if (this.chart) {
             // 单指标组件和多指标组件的changeData传参不同
             if (['Liquid', 'Gauge', 'RingProgress'].includes(config.chartType)) {

+ 0 - 4
data-room-ui/packages/js/utils/httpParamsFormatting.js

@@ -37,10 +37,6 @@ export default function axiosFormatting (customConfig) {
       // 执行响应脚本
       const resp = _.cloneDeep(response.data)
       eval(newCustomConfig.responseScript)
-      Message({
-        message: '执行成功',
-        type: 'success'
-      })
       return Promise.resolve(resp)
     } else {
       Message({