Skip to content

Commit

Permalink
feat:webhook body 支持非json (veops#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-liang0615 authored Oct 17, 2023
1 parent 375f087 commit ed49b23
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
19 changes: 15 additions & 4 deletions cmdb-ui/src/modules/cmdb/components/webhook/body.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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="{
Expand All @@ -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 = [
{
Expand All @@ -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,
},
}
},
}
Expand Down
13 changes: 10 additions & 3 deletions cmdb-ui/src/modules/cmdb/components/webhook/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -111,7 +114,11 @@ export default {
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 =
Object.keys(headers).map((key) => {
return {
Expand Down

0 comments on commit ed49b23

Please sign in to comment.