5b09e0369935ce882d3b6a36698f48ca527a89bd.svn-base 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <a-card :bordered="false">
  3. <a-row style="margin-top: 20px">
  4. <a-col :md="2" :sm="4">
  5. <a-select defaultValue="POST" style="width: 90px" @change="handleChange" size="large">
  6. <a-select-option value="POST">POST</a-select-option>
  7. <a-select-option value="GET">GET</a-select-option>
  8. <a-select-option value="PUT">PUT</a-select-option>
  9. <a-select-option value="DELETE">DELETE</a-select-option>
  10. </a-select>
  11. </a-col>
  12. <a-col :md="22" :sm="20">
  13. <a-input-search
  14. placeholder="input send url"
  15. v-model="url"
  16. @search="onSearch"
  17. enterButton="Send"
  18. size="large" />
  19. </a-col>
  20. </a-row>
  21. <a-tabs defaultActiveKey="2">
  22. <a-tab-pane tab="params" key="2">
  23. <textarea style="width:100%;font-size: 16px;font-weight:500" :rows="13" @blur="changeVal">
  24. </textarea>
  25. </a-tab-pane>
  26. </a-tabs>
  27. <a-tabs defaultActiveKey="1">
  28. <a-tab-pane tab="response" key="1">
  29. <textarea style="width:100%;font-size: 16px;font-weight:500" :rows="10" v-html="resultJson" readOnly>
  30. </textarea>
  31. </a-tab-pane>
  32. </a-tabs>
  33. </a-card>
  34. </template>
  35. <script>
  36. import { axios } from '@/utils/request'
  37. import { ACCESS_TOKEN } from "@/store/mutation-types"
  38. import Vue from 'vue'
  39. export default {
  40. name: 'FlowTest',
  41. data(){
  42. return {
  43. url:"",
  44. paramJson:"",
  45. resultJson:{},
  46. requestMethod:"POST"
  47. }
  48. },
  49. methods: {
  50. onSearch (value) {
  51. let that = this
  52. if(!value){
  53. that.$message.error("请填写路径")
  54. return false
  55. }
  56. this.resultJson = {};
  57. axios({
  58. url: value,
  59. method: this.requestMethod,
  60. data: this.paramJson
  61. }).then((res) => {
  62. console.log(res)
  63. this.resultJson = res
  64. }).catch((err) => {
  65. that.$message.error("请求异常:"+err)
  66. })
  67. },
  68. changeVal(e){
  69. try {
  70. let json = e.target.value;
  71. if(json.indexOf(",}")>0){
  72. json = json.replace(",}","}");
  73. }
  74. this.paramJson = JSON.parse(json);
  75. }catch (e) {
  76. console.log(e);
  77. this.$message.error("非法的JSON字符串")
  78. }
  79. },
  80. handleChange(value) {
  81. this.requestMethod = value;
  82. },
  83. created () {
  84. const token = Vue.ls.get(ACCESS_TOKEN);
  85. this.headers = {"X-Access-Token":token}
  86. }
  87. }
  88. }
  89. </script>