feat:webhook body 支持非json (#203)

This commit is contained in:
wang-liang0615 2023-10-17 10:44:38 +08:00 committed by GitHub
parent f8fee771c4
commit 413c0dfdfe
2 changed files with 25 additions and 7 deletions

View File

@ -16,7 +16,7 @@
</a-space> -->
</div>
<div style="margin-top:10px">
<vue-json-editor v-model="jsonData" :showBtns="false" :mode="'text'" />
<codemirror style="z-index: 9999" :options="cmOptions" v-model="jsonData"></codemirror>
<!-- <a-empty
v-else
:image-style="{
@ -31,11 +31,14 @@
</template>
<script>
import vueJsonEditor from 'vue-json-editor'
import { codemirror } from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
require('codemirror/mode/python/python.js')
export default {
name: 'Body',
components: { vueJsonEditor },
components: { codemirror },
data() {
const segmentedContentTypes = [
{
@ -60,7 +63,15 @@ export default {
return {
segmentedContentTypes,
// contentType: 'none',
jsonData: {},
jsonData: '',
cmOptions: {
lineNumbers: true,
mode: 'python',
height: '200px',
smartIndent: true,
tabSize: 4,
lineWrapping: true,
},
}
},
}

View File

@ -81,7 +81,11 @@ export default {
this.$refs.Parameters.parameters.forEach((item) => {
parameters[item.key] = item.value
})
const body = this.$refs.Body.jsonData
let body = this.$refs.Body.jsonData
try {
JSON.parse(body)
body = JSON.parse(body)
} catch {}
const headers = {}
this.$refs.Header.headers.forEach((item) => {
headers[item.key] = item.value
@ -99,7 +103,6 @@ export default {
return { method, url, parameters, body, headers, authorization }
},
setParams(params) {
console.log(2222, params)
const { method, url, parameters, body, headers, authorization = {} } = params ?? {}
this.method = method
this.url = url
@ -111,7 +114,11 @@ export default {
value: parameters[key],
}
}) || []
if (body && Object.prototype.toString.call(body) === '[object Object]') {
this.$refs.Body.jsonData = JSON.stringify(body)
} else {
this.$refs.Body.jsonData = body
}
this.$refs.Header.headers =
Object.keys(headers).map((key) => {
return {