mirror of https://github.com/veops/cmdb.git
feat:webhook body 支持非json (#203)
This commit is contained in:
parent
f8fee771c4
commit
413c0dfdfe
|
@ -16,7 +16,7 @@
|
||||||
</a-space> -->
|
</a-space> -->
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-top:10px">
|
<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
|
<!-- <a-empty
|
||||||
v-else
|
v-else
|
||||||
:image-style="{
|
:image-style="{
|
||||||
|
@ -31,11 +31,14 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<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 {
|
export default {
|
||||||
name: 'Body',
|
name: 'Body',
|
||||||
components: { vueJsonEditor },
|
components: { codemirror },
|
||||||
data() {
|
data() {
|
||||||
const segmentedContentTypes = [
|
const segmentedContentTypes = [
|
||||||
{
|
{
|
||||||
|
@ -60,7 +63,15 @@ export default {
|
||||||
return {
|
return {
|
||||||
segmentedContentTypes,
|
segmentedContentTypes,
|
||||||
// contentType: 'none',
|
// contentType: 'none',
|
||||||
jsonData: {},
|
jsonData: '',
|
||||||
|
cmOptions: {
|
||||||
|
lineNumbers: true,
|
||||||
|
mode: 'python',
|
||||||
|
height: '200px',
|
||||||
|
smartIndent: true,
|
||||||
|
tabSize: 4,
|
||||||
|
lineWrapping: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,11 @@ export default {
|
||||||
this.$refs.Parameters.parameters.forEach((item) => {
|
this.$refs.Parameters.parameters.forEach((item) => {
|
||||||
parameters[item.key] = item.value
|
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 = {}
|
const headers = {}
|
||||||
this.$refs.Header.headers.forEach((item) => {
|
this.$refs.Header.headers.forEach((item) => {
|
||||||
headers[item.key] = item.value
|
headers[item.key] = item.value
|
||||||
|
@ -99,7 +103,6 @@ export default {
|
||||||
return { method, url, parameters, body, headers, authorization }
|
return { method, url, parameters, body, headers, authorization }
|
||||||
},
|
},
|
||||||
setParams(params) {
|
setParams(params) {
|
||||||
console.log(2222, params)
|
|
||||||
const { method, url, parameters, body, headers, authorization = {} } = params ?? {}
|
const { method, url, parameters, body, headers, authorization = {} } = params ?? {}
|
||||||
this.method = method
|
this.method = method
|
||||||
this.url = url
|
this.url = url
|
||||||
|
@ -111,7 +114,11 @@ export default {
|
||||||
value: parameters[key],
|
value: parameters[key],
|
||||||
}
|
}
|
||||||
}) || []
|
}) || []
|
||||||
this.$refs.Body.jsonData = body
|
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 =
|
this.$refs.Header.headers =
|
||||||
Object.keys(headers).map((key) => {
|
Object.keys(headers).map((key) => {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue