feat:http数据集完善请求脚本配置和响应脚本配置

main
liu.shiyi 2 years ago
parent 7b9e17dc9f
commit 4da2d8b69f

@ -998,7 +998,8 @@ export default {
if (this.dataForm.config.requestType === 'front') { if (this.dataForm.config.requestType === 'front') {
this.replaceParams(this.dataForm.config.paramsList) this.replaceParams(this.dataForm.config.paramsList)
axiosFormatting({ ...this.newDataForm.config }).then((res) => { axiosFormatting({ ...this.newDataForm.config }).then((res) => {
this.dataPreviewList = res.list this.dataPreviewList = res.data.list
console.log(res)
}) })
} else { } else {
// //

@ -1,5 +1,6 @@
import axios from 'axios' import axios from 'axios'
import { Loading, Message } from 'element-ui' import { Loading, Message } from 'element-ui'
import _ from 'lodash'
export default function axiosFormatting (customConfig) { export default function axiosFormatting (customConfig) {
// 将请求头和请求参数的值转化为对象形式 // 将请求头和请求参数的值转化为对象形式
// const headers = arrToObject(customConfig.headers) // const headers = arrToObject(customConfig.headers)
@ -25,7 +26,6 @@ export default function axiosFormatting (customConfig) {
customConfig.url = replaceUrlParam(customConfig.url, key, req.urlKey[key]) customConfig.url = replaceUrlParam(customConfig.url, key, req.urlKey[key])
} }
config = { ...config, ...req, url: customConfig.url } config = { ...config, ...req, url: customConfig.url }
console.log(config.url)
return config return config
}, error => { }, error => {
// 对请求错误做些什么 // 对请求错误做些什么
@ -36,13 +36,14 @@ export default function axiosFormatting (customConfig) {
instance.interceptors.response.use(response => { instance.interceptors.response.use(response => {
if (response.data.code === 200) { if (response.data.code === 200) {
// 执行响应脚本 // 执行响应脚本
const data = response.data.data const resp = _.cloneDeep(response.data)
eval(customConfig.responseScript) eval(customConfig.responseScript)
Message({ Message({
message: '执行成功', message: '执行成功',
type: 'success' type: 'success'
}) })
return Promise.resolve(data) console.log(resp.data.list[0])
return Promise.resolve(resp)
} else { } else {
Message({ Message({
message: response.data.message, message: response.data.message,

Loading…
Cancel
Save