Blame view

src/views/jkfw/ptjk/components/retrieveDialog.vue 4.61 KB
蔡俊立 committed
1 2 3
<template>
  <dialogBox title="调用接口" @submitForm="submitForm" saveButton="调用" width="50%" :isFullscreen="false"
    @closeDialog="closeDialog" v-model="value">
蔡俊立 committed
4
    <el-descriptions class="margin-top" :column="1" size="16" border style="height:700px">
蔡俊立 committed
5 6 7 8 9 10 11 12 13 14 15 16 17
      <el-descriptions-item>
        <template slot="label" style="width:200px">接口代码</template>{{ruleForm.interfaceCode}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">接口名称</template>{{ruleForm.interfaceService}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">接口地址</template>{{ruleForm.interfaceApi}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">接口方式</template>{{ruleForm.interfaceMethod}}
      </el-descriptions-item>
      <el-descriptions-item>
蔡俊立 committed
18
        <template slot="label">接口类型</template>{{getInterfaceType(ruleForm.interfaceType)}}
蔡俊立 committed
19 20
      </el-descriptions-item>
      <el-descriptions-item>
蔡俊立 committed
21 22 23 24 25 26 27 28
        <template slot="label">接口参数</template>
        <vue-json-editor
          v-model="interfaceParams"
          :showBtns="false"
          :mode="'code'"
          @json-change="onJsonChange"
          @json-save="onJsonSave"
          @has-error="onError"/>
蔡俊立 committed
29 30
      </el-descriptions-item>
      <el-descriptions-item>
蔡俊立 committed
31 32 33
        <template slot="label">调用状态</template>
        <div style="color:green" v-if="returnMessage">{{returnMessage.statusCode}}</div>
        <div style="color:red" v-else>ERROR</div>
蔡俊立 committed
34 35
      </el-descriptions-item>
      <el-descriptions-item>
蔡俊立 committed
36 37 38 39
        <div slot="label" style="height:150px">返回结果
        </div>
        <div v-if="returnMessage">{{returnMessage.body}}</div>
        <div v-else>无效的接口CODE,请检查接口配置</div>
蔡俊立 committed
40 41 42 43 44 45
      </el-descriptions-item>
    </el-descriptions>
  </dialogBox>
</template>

<script>
蔡俊立 committed
46
import vueJsonEditor from 'vue-json-editor'
47
import {interfaceRetrieve } from "@/api/ptjk.js"
蔡俊立 committed
48 49
export default {
  components: {
50
    vueJsonEditor
蔡俊立 committed
51 52 53 54 55 56 57 58 59 60 61 62
  },
  computed: {
  },
  props: {
    value: { type: Boolean, default: false },
  },
  data () {
    return {
      //表单提交数据
      interfaceMethods: ['webapi','webservice'],
      interfaceTypes: [
          {'label': '工作流服务平台','value':'1'},
蔡俊立 committed
63
          {'label': '权限平台','value':'2'},
蔡俊立 committed
64 65 66 67
          {'label': '定时器服务','value':'3'},
          {'label': '其他第三方平台','value':'4'},
      ],
      ruleForm: {},
蔡俊立 committed
68
      interfaceParams: {} ,
蔡俊立 committed
69
      returnMessage: {},
蔡俊立 committed
70
      hasJsonFlag: true
蔡俊立 committed
71 72 73 74
    }
  },
  methods: {
    //表单提交
yuanbo committed
75 76 77 78
    /**
     * @description: 表单提交
     * @author: renchao
     */
蔡俊立 committed
79
    submitForm () {
蔡俊立 committed
80 81 82 83 84
      console.log(this.interfaceParams);
      console.log(this.hasJsonFlag);
      if(!this.hasJsonFlag){
        return;
      }
蔡俊立 committed
85 86
      var formdata = new FormData();
      formdata.append("interfaceCode", this.ruleForm.interfaceCode);
蔡俊立 committed
87
      formdata.append("interfaceType", this.ruleForm.interfaceType);
蔡俊立 committed
88
      formdata.append("params",JSON.stringify(this.interfaceParams));
蔡俊立 committed
89 90 91 92 93 94 95
      interfaceRetrieve(formdata).then(res => {
        if(res.code == 200){
          this.returnMessage = res.result
        }
      })
    },
    //获取详情
yuanbo committed
96 97 98 99 100
    /**
     * @description: 获取详情
     * @param {*} item
     * @author: renchao
     */
蔡俊立 committed
101 102 103 104
    getDetailInfo(item){
      this.ruleForm = item
    },
    //关闭弹窗
yuanbo committed
105 106 107 108
    /**
     * @description: 关闭弹窗
     * @author: renchao
     */
蔡俊立 committed
109 110
    closeDialog () {
      this.$emit("input", false);
111
      this.interfaceParams = {}
蔡俊立 committed
112
      this.returnMessage = {}
蔡俊立 committed
113
      this.hasJsonFlag = true
蔡俊立 committed
114 115
    },
    //获取接口类型
yuanbo committed
116 117 118 119 120
    /**
     * @description: 获取接口类型
     * @param {*} code
     * @author: renchao
     */
蔡俊立 committed
121 122 123 124 125 126 127 128 129
    getInterfaceType(code){
      let name = ''
      for (let item of this.interfaceTypes) {
        if (item.value == code) {
          name = item.label;
          break;
        }
      }
      return name;
蔡俊立 committed
130
    },
yuanbo committed
131 132 133 134 135
    /**
     * @description: onJsonChange
     * @param {*} value
     * @author: renchao
     */
蔡俊立 committed
136 137 138
    onJsonChange(value){
      this.onJsonSave();
    },
yuanbo committed
139 140 141 142 143
    /**
     * @description: onJsonSave
     * @param {*} value
     * @author: renchao
     */
蔡俊立 committed
144 145 146 147
    onJsonSave (value) {
      this.interfaceParams = value
      this.hasJsonFlag = true
    },
yuanbo committed
148 149 150 151 152
    /**
     * @description: onError
     * @param {*} value
     * @author: renchao
     */
蔡俊立 committed
153 154 155
    onError(value) {
      this.hasJsonFlag = false
    },
蔡俊立 committed
156 157 158 159 160
  }
}
</script>
<style scoped lang="scss">
@import "~@/styles/mixin.scss";
蔡俊立 committed
161 162 163 164 165 166
 /deep/ .is-bordered-label{
  width:100px
}
/deep/ .el-descriptions-item__content:nth-last-child(){
  height: 100px;
}
蔡俊立 committed
167
</style>