全局参数化加入请求参数中,参数支持多行编辑,展示值转换,细节优化

This commit is contained in:
暮光:城中城
2021-11-09 22:54:37 +08:00
parent 265ad08d3e
commit cabc693119
10 changed files with 218 additions and 67 deletions

View File

@@ -62,6 +62,7 @@
zyplayerApi.docSwaggerGlobalParamList().then(res => {
setTimeout(() => docListLoading.value = false, 500);
docList.value = res.data || [];
store.commit('setGlobalParam', docList.value);
});
};
let docEdit = ref({});

View File

@@ -21,7 +21,7 @@
<a-radio value="row">row</a-radio>
<a-radio value="binary">binary</a-radio>
</a-radio-group>
<a-select v-if="bodyParamType === 'row'" v-model:value="consumesParamType" size="small" style="margin-left: 10px;vertical-align: top;width: 90px;">
<a-select v-if="bodyParamType === 'row'" v-model:value="consumesParamType" size="small" style="margin-left: 10px;vertical-align: top;width: 100px;">
<a-select-option value="json">JSON</a-select-option>
<a-select-option value="html">HTML</a-select-option>
<a-select-option value="xml">XML</a-select-option>
@@ -94,6 +94,7 @@
setup(props) {
const store = useStore();
let swaggerResource = store.state.swaggerResource || {};
let globalParam = store.state.globalParam || [];
let swaggerDoc = store.state.swaggerDoc || {};
let urlDomain = swaggerResource.rewriteDomain || swaggerDoc.host;
let docUrl = ref(urlDomain + props.docInfoShow.url);
@@ -104,15 +105,28 @@
let urlParamList = ref([]);
// Header参数处理
const headerParamRef = ref();
let headerParamListGlobal = globalParam.filter(item => item.paramType === 2);
let headerParamListProp = props.requestParamList.filter(item => item.in === 'header');
let nextIndex = 1;
headerParamListGlobal.forEach(item => {
headerParamListProp.push({name: item.paramKey, value: item.paramValue, type: 'string', key: 'g' + (nextIndex++)});
});
let headerParamList = ref(JSON.parse(JSON.stringify(headerParamListProp)));
// cookie参数处理
const cookieParamRef = ref();
let cookieParamListGlobal = globalParam.filter(item => item.paramType === 3);
let cookieParamListProp = props.requestParamList.filter(item => item.in === 'cookie');
cookieParamListGlobal.forEach(item => {
cookieParamListProp.push({name: item.paramKey, value: item.paramValue, type: 'string', key: 'g' + (nextIndex++)});
});
let cookieParamList = ref(JSON.parse(JSON.stringify(cookieParamListProp)));
// form参数处理
const formParamRef= ref();
let formParamListGlobal = globalParam.filter(item => item.paramType === 1);
let formParamListProp = props.requestParamList.filter(item => item.in === 'formData');
formParamListGlobal.forEach(item => {
formParamListProp.push({name: item.paramKey, value: item.paramValue, type: 'string', key: 'g' + (nextIndex++)});
});
let formParamList = ref([]);
if (props.docInfoShow.method === 'post') {
// post的时候参数否放到form里面

View File

@@ -8,7 +8,7 @@
<a-radio-button value="row">原始值</a-radio-button>
<a-radio-button value="preview">预览</a-radio-button>
</a-radio-group>
<a-select v-if="bodyShowType === 'format'" v-model:value="bodyShowFormatType" size="small" style="margin-left: 10px;">
<a-select v-if="bodyShowType === 'format'" v-model:value="bodyShowFormatType" size="small" style="margin-left: 10px;width: 100px;">
<a-select-option value="json">JSON</a-select-option>
<a-select-option value="html">HTML</a-select-option>
<a-select-option value="xml">XML</a-select-option>
@@ -40,7 +40,11 @@
</a-table>
</a-tab-pane>
<template #rightExtra>
<span class="status-info-box">状态码<span>{{resultData.status||'200'}}</span>耗时<span>{{resultData.useTime||0}} ms</span>大小<span>{{resultData.bodyLength||0}} B</span></span>
<span class="status-info-box">
状态码<span>{{resultData.status||'200'}}</span>
耗时<span>{{unitConvert.formatSeconds(resultData.useTime||0)}}</span>
大小<span>{{unitConvert.formatFileSize(resultData.bodyLength||0)}}</span>
</span>
</template>
</a-tabs>
</div>
@@ -60,6 +64,7 @@
import 'mavon-editor/dist/css/index.css'
import {zyplayerApi} from "../../../api";
import aceEditor from "../../../assets/ace-editor";
import unitConvert from "../../../assets/utils/unitConvert.js";
export default {
props: {
@@ -132,8 +137,9 @@
resultDataContentFormat.value = props.result.data.data;
}
} else {
resultDataContentOrigin.value = JSON.stringify(props.result.data);
resultDataContentFormat.value = JSON.stringify(props.result.data, null, 4);
let errorSuffix = '\n// 请求失败,以下为封装的返回值对象,仅供参考\n\n';
resultDataContentOrigin.value = errorSuffix + JSON.stringify(props.result.data);
resultDataContentFormat.value = errorSuffix + JSON.stringify(props.result.data, null, 4);
}
bodyShowTypeChange();
}
@@ -148,6 +154,7 @@
activePage,
bodyShowType,
bodyShowTypeChange,
unitConvert,
bodyShowFormatType,
bodyShowFormatPreview,
previewHtmlRef,