mirror of
				https://github.com/veops/cmdb.git
				synced 2025-11-04 13:46:17 +08:00 
			
		
		
		
	feat:webhook body 支持非json (#203)
This commit is contained in:
		@@ -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,
 | 
			
		||||
      },
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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],
 | 
			
		||||
          }
 | 
			
		||||
        }) || []
 | 
			
		||||
      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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user