2021-10-31 23:48:55 +08:00
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<a-input-search
|
|
|
|
|
:addon-before="docInfoShow.method.toUpperCase()"
|
|
|
|
|
v-model:value="docUrl"
|
|
|
|
|
enter-button="发送请求"
|
|
|
|
|
@search="sendRequest"
|
|
|
|
|
/>
|
|
|
|
|
<a-tabs v-model:activeKey="activePage" closable @tab-click="" style="padding: 5px 10px 0;">
|
|
|
|
|
<a-tab-pane tab="URL参数" key="urlParam">
|
2021-11-03 23:23:29 +08:00
|
|
|
<ParamTable ref="urlParamRef" v-model:selected="urlParamChecked" :paramList="urlParamList"></ParamTable>
|
2021-10-31 23:48:55 +08:00
|
|
|
</a-tab-pane>
|
2021-11-02 23:49:48 +08:00
|
|
|
<a-tab-pane tab="请求参数" key="bodyParam" v-if="docInfoShow.method !== 'get'">
|
2021-11-01 22:51:03 +08:00
|
|
|
<a-radio-group v-model:value="bodyParamType" style="margin-bottom: 5px;">
|
2021-10-31 23:48:55 +08:00
|
|
|
<a-radio value="none">none</a-radio>
|
|
|
|
|
<a-radio value="form">form-data</a-radio>
|
|
|
|
|
<a-radio value="formUrlEncode">x-www-form-urlencoded</a-radio>
|
|
|
|
|
<a-radio value="row">row</a-radio>
|
|
|
|
|
<a-radio value="binary">binary</a-radio>
|
|
|
|
|
</a-radio-group>
|
2021-11-01 22:51:03 +08:00
|
|
|
<div v-show="bodyParamType === 'form'">
|
2021-11-03 23:23:29 +08:00
|
|
|
<ParamTable ref="formParamRef" :paramList="formParamList" showType></ParamTable>
|
2021-11-01 22:51:03 +08:00
|
|
|
</div>
|
|
|
|
|
<div v-show="bodyParamType === 'formUrlEncode'">
|
2021-11-03 23:23:29 +08:00
|
|
|
<ParamTable ref="formEncodeParamRef" :paramList="formEncodeParamList"></ParamTable>
|
2021-11-01 22:51:03 +08:00
|
|
|
</div>
|
|
|
|
|
<div v-show="bodyParamType === 'row'">
|
2021-11-03 23:23:29 +08:00
|
|
|
<ParamBody ref="bodyParamRef" :paramList="bodyRowParamList"></ParamBody>
|
2021-11-01 22:51:03 +08:00
|
|
|
</div>
|
2021-10-31 23:48:55 +08:00
|
|
|
</a-tab-pane>
|
|
|
|
|
<a-tab-pane tab="Header参数" key="headerParam">
|
2021-11-03 23:23:29 +08:00
|
|
|
<ParamTable ref="headerParamRef" :paramList="headerParamList"></ParamTable>
|
2021-10-31 23:48:55 +08:00
|
|
|
</a-tab-pane>
|
|
|
|
|
<a-tab-pane tab="Cookie参数" key="cookieParam">
|
2021-11-03 23:23:29 +08:00
|
|
|
<ParamTable ref="cookieParamRef" :paramList="cookieParamList"></ParamTable>
|
2021-10-31 23:48:55 +08:00
|
|
|
</a-tab-pane>
|
|
|
|
|
</a-tabs>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import {toRefs, ref, reactive, onMounted, watch} from 'vue';
|
|
|
|
|
import { useRouter, useRoute } from "vue-router";
|
|
|
|
|
import {useStore} from 'vuex';
|
|
|
|
|
import { message } from 'ant-design-vue';
|
|
|
|
|
import {markdownIt} from 'mavon-editor'
|
2021-11-03 23:23:29 +08:00
|
|
|
import ParamTable from '../../../components/params/ParamTable.vue'
|
|
|
|
|
import ParamBody from '../../../components/params/ParamBody.vue'
|
2021-10-31 23:48:55 +08:00
|
|
|
import {CloseOutlined} from '@ant-design/icons-vue';
|
|
|
|
|
import 'mavon-editor/dist/markdown/github-markdown.min.css'
|
|
|
|
|
import 'mavon-editor/dist/css/index.css'
|
2021-11-03 23:23:29 +08:00
|
|
|
import {zyplayerApi} from "../../../api";
|
2021-10-31 23:48:55 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
props: {
|
|
|
|
|
docInfoShow: {
|
|
|
|
|
type: Object,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
requestParamList: {
|
|
|
|
|
type: Array,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
responseParamList: {
|
|
|
|
|
type: Array,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
components: {
|
2021-11-03 23:23:29 +08:00
|
|
|
CloseOutlined, ParamTable, ParamBody
|
2021-10-31 23:48:55 +08:00
|
|
|
},
|
|
|
|
|
setup(props) {
|
2021-11-03 23:23:29 +08:00
|
|
|
const store = useStore();
|
|
|
|
|
let swaggerResource = store.state.swaggerResource || {};
|
|
|
|
|
let swaggerDoc = store.state.swaggerDoc || {};
|
|
|
|
|
let urlDomain = swaggerResource.rewriteDomain || swaggerDoc.host;
|
|
|
|
|
let docUrl = ref(urlDomain + props.docInfoShow.url);
|
2021-10-31 23:48:55 +08:00
|
|
|
let activePage = ref('urlParam');
|
|
|
|
|
// URL参数处理
|
2021-11-03 23:23:29 +08:00
|
|
|
const urlParamRef = ref();
|
2021-11-01 22:51:03 +08:00
|
|
|
const urlParamChecked = ref([]);
|
2021-10-31 23:48:55 +08:00
|
|
|
let urlParamListProp = props.requestParamList.filter(item => item.in === 'query');
|
2021-11-03 23:23:29 +08:00
|
|
|
let urlParamList = ref([]);
|
2021-10-31 23:48:55 +08:00
|
|
|
// Header参数处理
|
2021-11-03 23:23:29 +08:00
|
|
|
const headerParamRef = ref();
|
2021-11-01 22:51:03 +08:00
|
|
|
const headerParamChecked = ref([]);
|
|
|
|
|
let headerParamListProp = props.requestParamList.filter(item => item.in === 'header');
|
2021-10-31 23:48:55 +08:00
|
|
|
let headerParamList = ref(JSON.parse(JSON.stringify(headerParamListProp)));
|
|
|
|
|
// cookie参数处理
|
2021-11-03 23:23:29 +08:00
|
|
|
const cookieParamRef = ref();
|
2021-11-01 22:51:03 +08:00
|
|
|
const cookieParamChecked = ref([]);
|
|
|
|
|
let cookieParamListProp = props.requestParamList.filter(item => item.in === 'cookie');
|
2021-10-31 23:48:55 +08:00
|
|
|
let cookieParamList = ref(JSON.parse(JSON.stringify(cookieParamListProp)));
|
2021-11-01 22:51:03 +08:00
|
|
|
// form参数处理
|
2021-11-03 23:23:29 +08:00
|
|
|
const formParamRef= ref();
|
2021-11-01 22:51:03 +08:00
|
|
|
const formParamChecked = ref([]);
|
|
|
|
|
let formParamListProp = props.requestParamList.filter(item => item.in === 'formData');
|
|
|
|
|
let formParamList = ref([]);
|
2021-11-03 23:23:29 +08:00
|
|
|
if (props.docInfoShow.method === 'post') {
|
|
|
|
|
// post的时候参数否放到form里面
|
|
|
|
|
formParamListProp = formParamListProp.concat(urlParamListProp);
|
|
|
|
|
} else {
|
|
|
|
|
// 否则放到URL参数里面
|
|
|
|
|
urlParamList = ref(JSON.parse(JSON.stringify(urlParamListProp)));
|
|
|
|
|
}
|
2021-11-01 22:51:03 +08:00
|
|
|
// form参数处理
|
2021-11-03 23:23:29 +08:00
|
|
|
const formEncodeParamRef = ref();
|
2021-11-01 22:51:03 +08:00
|
|
|
const formEncodeParamChecked = ref([]);
|
|
|
|
|
let formEncodeParamList = ref([]);
|
2021-10-31 23:48:55 +08:00
|
|
|
// body 参数
|
2021-11-03 23:23:29 +08:00
|
|
|
let bodyParamRef = ref();
|
2021-10-31 23:48:55 +08:00
|
|
|
let bodyParamType = ref('form');
|
2021-11-03 23:23:29 +08:00
|
|
|
let bodyRowListProp = props.requestParamList.filter(item => item.in === 'body');
|
|
|
|
|
let bodyRowParamList = ref(JSON.parse(JSON.stringify(bodyRowListProp)));
|
2021-11-01 22:51:03 +08:00
|
|
|
// x-www-form-urlencoded
|
2021-11-03 23:23:29 +08:00
|
|
|
if (props.docInfoShow.consumes.indexOf('application/x-www-form-urlencoded') >= 0) {
|
2021-11-01 22:51:03 +08:00
|
|
|
bodyParamType.value = 'formUrlEncode';
|
|
|
|
|
formEncodeParamList = ref(JSON.parse(JSON.stringify(formParamListProp)));
|
2021-11-03 23:23:29 +08:00
|
|
|
} else if (props.docInfoShow.consumes.indexOf('multipart/form-data') >= 0) {
|
|
|
|
|
bodyParamType.value = 'form';
|
|
|
|
|
formParamList = ref(JSON.parse(JSON.stringify(formParamListProp)));
|
2021-11-01 22:51:03 +08:00
|
|
|
} else if (props.docInfoShow.consumes.indexOf('application/json') >= 0) {
|
|
|
|
|
bodyParamType.value = 'row';
|
2021-11-03 23:23:29 +08:00
|
|
|
formEncodeParamList = ref(JSON.parse(JSON.stringify(formParamListProp)));
|
|
|
|
|
if (formParamListProp.length > 0) {
|
|
|
|
|
bodyParamType.value = 'formUrlEncode';
|
|
|
|
|
}
|
2021-11-01 22:51:03 +08:00
|
|
|
} else {
|
|
|
|
|
formParamList = ref(JSON.parse(JSON.stringify(formParamListProp)));
|
|
|
|
|
}
|
2021-11-03 23:23:29 +08:00
|
|
|
if (formParamList.value.length > 0) {
|
|
|
|
|
activePage.value = 'urlParam';
|
|
|
|
|
} else if (formParamListProp.length > 0 || bodyRowListProp.length > 0) {
|
|
|
|
|
activePage.value = 'bodyParam';
|
|
|
|
|
} else if (headerParamListProp.length > 0) {
|
|
|
|
|
activePage.value = 'headerParam';
|
|
|
|
|
}
|
2021-10-31 23:48:55 +08:00
|
|
|
// 发送请求
|
|
|
|
|
const sendRequest = () => {
|
2021-11-03 23:23:29 +08:00
|
|
|
const formData = new FormData();
|
|
|
|
|
let selectedRowKeys = urlParamRef.value.getSelectedRowKeys();
|
|
|
|
|
let urlParamStr = urlParamList.value.filter(item => selectedRowKeys.indexOf(item.key) >= 0 && item.name && item.value).map(item => {
|
|
|
|
|
return item.name + '=' + encodeURIComponent(item.value);
|
|
|
|
|
}).join('&');
|
|
|
|
|
console.log('urlParamStr', urlParamStr);
|
|
|
|
|
// fileList.value.forEach(file => {
|
|
|
|
|
// formData.append('files[]', file);
|
|
|
|
|
// });
|
|
|
|
|
formData.append('url', docUrl.value + '?' + urlParamStr);
|
|
|
|
|
zyplayerApi.requestUrl(formData).then(res => {
|
|
|
|
|
debugger
|
|
|
|
|
});
|
2021-10-31 23:48:55 +08:00
|
|
|
message.info('暂未开放此功能,敬请期待');
|
|
|
|
|
};
|
|
|
|
|
return {
|
|
|
|
|
docUrl,
|
|
|
|
|
activePage,
|
|
|
|
|
sendRequest,
|
|
|
|
|
// url参数
|
2021-11-03 23:23:29 +08:00
|
|
|
urlParamRef,
|
2021-11-01 22:51:03 +08:00
|
|
|
urlParamChecked,
|
2021-10-31 23:48:55 +08:00
|
|
|
urlParamList,
|
|
|
|
|
// header参数
|
2021-11-03 23:23:29 +08:00
|
|
|
headerParamRef,
|
2021-11-01 22:51:03 +08:00
|
|
|
headerParamChecked,
|
2021-10-31 23:48:55 +08:00
|
|
|
headerParamList,
|
|
|
|
|
// cookie参数
|
2021-11-03 23:23:29 +08:00
|
|
|
cookieParamRef,
|
2021-11-01 22:51:03 +08:00
|
|
|
cookieParamChecked,
|
2021-10-31 23:48:55 +08:00
|
|
|
cookieParamList,
|
2021-11-01 22:51:03 +08:00
|
|
|
// form参数
|
2021-11-03 23:23:29 +08:00
|
|
|
formParamRef,
|
2021-11-01 22:51:03 +08:00
|
|
|
formParamChecked,
|
|
|
|
|
formParamList,
|
|
|
|
|
// form-encode参数
|
2021-11-03 23:23:29 +08:00
|
|
|
formEncodeParamRef,
|
2021-11-01 22:51:03 +08:00
|
|
|
formEncodeParamChecked,
|
|
|
|
|
formEncodeParamList,
|
2021-10-31 23:48:55 +08:00
|
|
|
// body参数
|
2021-11-03 23:23:29 +08:00
|
|
|
bodyParamRef,
|
2021-10-31 23:48:55 +08:00
|
|
|
bodyParamType,
|
2021-11-03 23:23:29 +08:00
|
|
|
bodyRowParamList,
|
2021-10-31 23:48:55 +08:00
|
|
|
responseCodeListColumns: [
|
|
|
|
|
{title: '状态码', dataIndex: 'code', width: 100},
|
|
|
|
|
{title: '类型', dataIndex: 'type', width: 250},
|
|
|
|
|
{title: '说明', dataIndex: 'desc'},
|
|
|
|
|
],
|
|
|
|
|
responseParamListColumns: [
|
|
|
|
|
{title: '参数名', dataIndex: 'name', width: 250},
|
|
|
|
|
{title: '类型', dataIndex: 'type', width: 250},
|
|
|
|
|
{title: '说明', dataIndex: 'description'},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|