Browse Source

feat:优化http数据集响应拦截处理

liu.shiyi 1 năm trước cách đây
mục cha
commit
9c9f3297e9
1 tập tin đã thay đổi với 5 bổ sung3 xóa
  1. 5 3
      data-room-ui/packages/js/utils/httpParamsFormatting.js

+ 5 - 3
data-room-ui/packages/js/utils/httpParamsFormatting.js

@@ -35,8 +35,10 @@ export default function axiosFormatting (customConfig) {
   instance.interceptors.response.use(response => {
     if (response.data.code === 200) {
       // 执行响应脚本
-      const resp = _.cloneDeep(response.data)
-      eval(newCustomConfig.responseScript)
+      // eslint-disable-next-line no-new-func
+      const getResp = new Function('response', newCustomConfig.responseScript)
+      const resp = getResp(response)
+      console.log(resp)
       return Promise.resolve(resp)
     } else {
       Message({
@@ -76,7 +78,7 @@ function replaceUrlParam (url, paramName, paramValue) {
 }
 // 将参数的值替换掉其他配置中对应属性的值
 function replaceParams (customConfig) {
-  let newConfig = _.cloneDeep(customConfig)
+  const newConfig = _.cloneDeep(customConfig)
   newConfig.url = evalStrFunc(newConfig.paramsList, newConfig.url)
   newConfig.headers = evalArrFunc(newConfig.paramsList, newConfig.headers)
   newConfig.params = evalArrFunc(newConfig.paramsList, newConfig.params)