Эх сурвалжийг харах

feat:http数据集代码优化

liu.shiyi 1 жил өмнө
parent
commit
93bc278f92

+ 13 - 3
data-room-ui/packages/DataSetManagement/src/HttpEditForm.vue

@@ -432,7 +432,7 @@
                     v-else
                     class="bs-codemirror-bottom-text"
                   >
-                    <strong>响应脚本设置规则: 接口返回数据已经内置到参数responseString(已转为字符串)中,,如果需要处理成JSON格式推荐使用JsoonSlurper类。
+                    <strong>响应脚本设置规则: 接口返回数据已经内置到参数responseString(已转为字符串)中,,如果需要处理成JSON格式推荐使用JsonSlurper类。
                       <br> 例如:<span style="color: red;" />
                     </strong>
                   </div>
@@ -505,7 +505,10 @@
                   配置
                 </el-button>
               </div>
-              <div class="field-wrap bs-field-wrap bs-scrollbar">
+              <div
+                v-if="outputFieldList && outputFieldList.length"
+                class="field-wrap bs-field-wrap bs-scrollbar"
+              >
                 <div
                   v-for="(field, key) in outputFieldList"
                   :key="key"
@@ -528,6 +531,12 @@
                   </el-button>
                 </div>
               </div>
+              <div
+                v-else
+                style="color: red;padding: 16px"
+              >
+                数据为空或数据类型不符合规范,建议返回的数据res结构为{data:[],...},输出字段类型将从res.data中解析
+              </div>
             </div>
           </div>
         </el-col>
@@ -1097,7 +1106,8 @@ export default {
             this.dataPreviewList[0][item] = res[item]
           }
           // 获取数据后更新输出字段
-          this.updateOoutputFieldList(this.dataPreviewList)
+          console.log(res)
+          this.updateOoutputFieldList(res?.data)
           this.$message.success('解析并执行成功')
         })
       } else {

+ 1 - 2
data-room-ui/packages/DataSetManagement/src/HttpParamsSettingDialog.vue

@@ -190,10 +190,9 @@ export default {
           if (!this.isUpdate) {
             this.$emit('saveParams', cloneDeep(this.form.params))
           } else {
-            console.log(this.form.params)
             this.$emit('saveNewParams', cloneDeep(this.form.params))
+            this.$emit('getData')
           }
-          this.$emit('getData')
           this.dialogVisible = false
         }
       })

+ 17 - 2
data-room-ui/packages/js/utils/httpParamsFormatting.js

@@ -45,11 +45,10 @@ export default function axiosFormatting (customConfig) {
       return Promise.resolve(response.data)
     }
   })
-  const body = {}
   const pattern = /(body\.\w+)=(\w+)/g
   const replacement = "$1='$2'"
   newCustomConfig.body = newCustomConfig.body.replace(pattern, replacement)
-  eval(newCustomConfig.body)
+  const body = stringToObject(newCustomConfig.body)
   return new Promise((resolve, reject) => {
     instance({
       method: newCustomConfig.method,
@@ -63,6 +62,22 @@ export default function axiosFormatting (customConfig) {
     })
   })
 }
+function stringToObject(inputString) {
+  const lines = inputString.split('\n');
+  const result = {};
+
+  lines.forEach(line => {
+    // Use regular expressions to extract property name and value
+    const propertyMatch = line.match(/^(.*?)=(.*)$/);
+    if (propertyMatch) {
+      const propertyName = propertyMatch[1].trim();
+      const propertyValue = propertyMatch[2].trim().replace(/'/g, ""); // Remove single quotes from the value
+      result[propertyName] = propertyValue;
+    }
+  });
+
+  return { body: result };
+}
 // 动态替换url后面参数的值
 function replaceUrlParam (url, paramName, paramValue) {
   const regex = new RegExp(`([?&])${paramName}=.*?(&|$)`, 'i')