2021-11-04 23:43:58 +08:00
|
|
|
|
<template>
|
2021-11-06 22:55:10 +08:00
|
|
|
|
<div style="margin-bottom: 30px;">
|
2021-11-04 23:43:58 +08:00
|
|
|
|
<a-tabs v-model:activeKey="activePage" closable @tab-click="" style="padding: 5px 10px 0;">
|
|
|
|
|
|
<a-tab-pane tab="Body" key="body" forceRender>
|
2021-11-06 22:55:10 +08:00
|
|
|
|
<div style="margin-bottom: 10px;">
|
|
|
|
|
|
<a-radio-group v-model:value="bodyShowType" @change="bodyShowTypeChange" size="small">
|
|
|
|
|
|
<a-radio-button value="format">格式化</a-radio-button>
|
|
|
|
|
|
<a-radio-button value="row">原始值</a-radio-button>
|
|
|
|
|
|
<a-radio-button value="preview">预览</a-radio-button>
|
|
|
|
|
|
</a-radio-group>
|
2021-11-09 22:54:37 +08:00
|
|
|
|
<a-select v-if="bodyShowType === 'format'" v-model:value="bodyShowFormatType" size="small" style="margin-left: 10px;width: 100px;">
|
2021-11-06 22:55:10 +08:00
|
|
|
|
<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>
|
2021-11-07 23:06:36 +08:00
|
|
|
|
<a-select-option value="javascript">JavaScript</a-select-option>
|
2021-11-06 22:55:10 +08:00
|
|
|
|
<a-select-option value="text">TEXT</a-select-option>
|
|
|
|
|
|
</a-select>
|
|
|
|
|
|
</div>
|
2021-11-07 23:06:36 +08:00
|
|
|
|
<ace-editor v-if="bodyShowType === 'format'" v-model:value="resultDataContentFormat" @init="resultDataInit" :lang="bodyShowFormatType" theme="monokai" width="100%" height="100" :options="resultDataConfig"></ace-editor>
|
|
|
|
|
|
<ace-editor v-else-if="bodyShowType === 'row'" v-model:value="resultDataContentOrigin" @init="resultDataInit" lang="text" theme="chrome" width="100%" height="100" :options="resultDataConfig"></ace-editor>
|
2021-11-06 22:55:10 +08:00
|
|
|
|
<div v-else-if="bodyShowType === 'preview'">
|
|
|
|
|
|
<template v-if="bodyShowFormatPreview === 'html'">
|
|
|
|
|
|
<iframe ref="previewHtmlRef" width="100%" height="570px" style="border: 0;"></iframe>
|
|
|
|
|
|
</template>
|
2021-11-07 23:06:36 +08:00
|
|
|
|
<template v-else>{{resultDataContentOrigin}}</template>
|
2021-11-06 22:55:10 +08:00
|
|
|
|
</div>
|
2021-11-04 23:43:58 +08:00
|
|
|
|
</a-tab-pane>
|
|
|
|
|
|
<a-tab-pane tab="Headers" key="headers" forceRender>
|
|
|
|
|
|
<a-table :dataSource="resultHeaders"
|
|
|
|
|
|
:columns="resultHeadersColumns" size="small"
|
|
|
|
|
|
:pagination="false"
|
|
|
|
|
|
:scroll="{ y: '300px' }">
|
|
|
|
|
|
</a-table>
|
|
|
|
|
|
</a-tab-pane>
|
|
|
|
|
|
<a-tab-pane tab="Cookies" key="cookies" forceRender>
|
|
|
|
|
|
<a-table :dataSource="resultCookies"
|
|
|
|
|
|
:columns="resultCookiesColumns" size="small"
|
|
|
|
|
|
:pagination="false"
|
|
|
|
|
|
:scroll="{ y: '300px' }">
|
|
|
|
|
|
</a-table>
|
|
|
|
|
|
</a-tab-pane>
|
2021-11-06 22:55:10 +08:00
|
|
|
|
<template #rightExtra>
|
2021-11-09 22:54:37 +08:00
|
|
|
|
<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>
|
2021-11-06 22:55:10 +08:00
|
|
|
|
</template>
|
2021-11-04 23:43:58 +08:00
|
|
|
|
</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-07 23:06:36 +08:00
|
|
|
|
import xmlFormatter from 'xml-formatter'
|
2021-11-04 23:43:58 +08:00
|
|
|
|
import ParamTable from '../../../components/params/ParamTable.vue'
|
|
|
|
|
|
import ParamBody from '../../../components/params/ParamBody.vue'
|
|
|
|
|
|
import {CloseOutlined} from '@ant-design/icons-vue';
|
|
|
|
|
|
import 'mavon-editor/dist/markdown/github-markdown.min.css'
|
|
|
|
|
|
import 'mavon-editor/dist/css/index.css'
|
|
|
|
|
|
import {zyplayerApi} from "../../../api";
|
2021-11-06 22:55:10 +08:00
|
|
|
|
import aceEditor from "../../../assets/ace-editor";
|
2021-11-09 22:54:37 +08:00
|
|
|
|
import unitConvert from "../../../assets/utils/unitConvert.js";
|
2021-11-04 23:43:58 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
props: {
|
|
|
|
|
|
result: {
|
|
|
|
|
|
type: Object,
|
|
|
|
|
|
required: true
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
components: {
|
2021-11-06 22:55:10 +08:00
|
|
|
|
CloseOutlined, ParamTable, ParamBody, aceEditor
|
2021-11-04 23:43:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
setup(props) {
|
|
|
|
|
|
const { result } = toRefs(props);
|
|
|
|
|
|
let activePage = ref('body');
|
2021-11-06 22:55:10 +08:00
|
|
|
|
let bodyShowType = ref('format');
|
2021-11-07 23:06:36 +08:00
|
|
|
|
// 格式化展示的类型,用户可以修改
|
2021-11-06 22:55:10 +08:00
|
|
|
|
let bodyShowFormatType = ref('json');
|
2021-11-07 23:06:36 +08:00
|
|
|
|
// 预览格式,依据返回值的content-type得出,不可修改
|
2021-11-06 22:55:10 +08:00
|
|
|
|
let bodyShowFormatPreview = ref('');
|
2021-11-04 23:43:58 +08:00
|
|
|
|
let resultHeaders = ref([]);
|
|
|
|
|
|
let resultCookies = ref([]);
|
2021-11-07 23:06:36 +08:00
|
|
|
|
let resultDataContentOrigin = ref('');
|
|
|
|
|
|
let resultDataContentFormat = ref('');
|
2021-11-06 22:55:10 +08:00
|
|
|
|
let resultData = ref({});
|
|
|
|
|
|
let previewHtmlRef = ref();
|
2021-11-07 23:06:36 +08:00
|
|
|
|
const bodyShowTypeChange = () => {
|
|
|
|
|
|
if (bodyShowType.value === 'preview') {
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
if (previewHtmlRef.value) {
|
|
|
|
|
|
previewHtmlRef.value.contentDocument.write(resultDataContentOrigin.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-04 23:43:58 +08:00
|
|
|
|
const initData = () => {
|
|
|
|
|
|
if (props.result.data) {
|
2021-11-06 22:55:10 +08:00
|
|
|
|
resultData.value = props.result.data;
|
2021-11-04 23:43:58 +08:00
|
|
|
|
if (props.result.data.headers) {
|
|
|
|
|
|
resultHeaders.value = props.result.data.headers;
|
2021-11-06 22:55:10 +08:00
|
|
|
|
// 依据返回值header判断类型
|
|
|
|
|
|
let contentType = resultHeaders.value.find(item => item.name === 'Content-Type');
|
|
|
|
|
|
if (contentType && contentType.value) {
|
|
|
|
|
|
if (contentType.value.indexOf('text/html') >= 0) {
|
|
|
|
|
|
bodyShowFormatType.value = 'html';
|
2021-11-07 23:06:36 +08:00
|
|
|
|
} else if (contentType.value.indexOf('application/json') >= 0) {
|
2021-11-06 22:55:10 +08:00
|
|
|
|
bodyShowFormatType.value = 'json';
|
2021-11-07 23:06:36 +08:00
|
|
|
|
} else if (contentType.value.indexOf('application/xml') >= 0 || contentType.value.indexOf('text/xml') >= 0) {
|
|
|
|
|
|
bodyShowFormatType.value = 'xml';
|
|
|
|
|
|
} else if (contentType.value.indexOf('application/javascript') >= 0) {
|
|
|
|
|
|
bodyShowFormatType.value = 'javascript';
|
2021-11-06 22:55:10 +08:00
|
|
|
|
}
|
2021-11-07 23:06:36 +08:00
|
|
|
|
bodyShowFormatPreview.value = bodyShowFormatType.value;
|
2021-11-06 22:55:10 +08:00
|
|
|
|
}
|
2021-11-04 23:43:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (props.result.data.cookies) {
|
|
|
|
|
|
resultCookies.value = props.result.data.cookies;
|
|
|
|
|
|
}
|
2021-11-07 23:06:36 +08:00
|
|
|
|
if (props.result.data.data) {
|
|
|
|
|
|
resultDataContentOrigin.value = props.result.data.data;
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (bodyShowFormatType.value === 'xml') {
|
|
|
|
|
|
resultDataContentFormat.value = xmlFormatter(resultDataContentOrigin.value);
|
|
|
|
|
|
} else if (bodyShowFormatType.value === 'json') {
|
|
|
|
|
|
resultDataContentFormat.value = JSON.stringify(JSON.parse(resultDataContentOrigin.value), null, 4);
|
|
|
|
|
|
} else if (bodyShowFormatType.value === 'javascript') {
|
|
|
|
|
|
// TODO 暂未测试
|
|
|
|
|
|
resultDataContentFormat.value = JSON.stringify(resultDataContentOrigin.value, null, 4);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
resultDataContentFormat.value = props.result.data.data;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2021-11-09 22:54:37 +08:00
|
|
|
|
let errorSuffix = '\n// 请求失败,以下为封装的返回值对象,仅供参考\n\n';
|
|
|
|
|
|
resultDataContentOrigin.value = errorSuffix + JSON.stringify(props.result.data);
|
|
|
|
|
|
resultDataContentFormat.value = errorSuffix + JSON.stringify(props.result.data, null, 4);
|
2021-11-07 23:06:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
bodyShowTypeChange();
|
2021-11-04 23:43:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
initData();
|
|
|
|
|
|
watch(result, () => initData());
|
2021-11-06 22:55:10 +08:00
|
|
|
|
// 编辑器
|
|
|
|
|
|
const resultDataInit = editor => {
|
|
|
|
|
|
editor.setFontSize(16);
|
|
|
|
|
|
}
|
2021-11-04 23:43:58 +08:00
|
|
|
|
return {
|
|
|
|
|
|
activePage,
|
2021-11-06 22:55:10 +08:00
|
|
|
|
bodyShowType,
|
|
|
|
|
|
bodyShowTypeChange,
|
2021-11-09 22:54:37 +08:00
|
|
|
|
unitConvert,
|
2021-11-06 22:55:10 +08:00
|
|
|
|
bodyShowFormatType,
|
|
|
|
|
|
bodyShowFormatPreview,
|
|
|
|
|
|
previewHtmlRef,
|
|
|
|
|
|
resultData,
|
2021-11-04 23:43:58 +08:00
|
|
|
|
resultHeaders,
|
|
|
|
|
|
resultCookies,
|
|
|
|
|
|
resultHeadersColumns: [
|
|
|
|
|
|
{title: 'KEY', dataIndex: 'name'},
|
|
|
|
|
|
{title: 'VALUE', dataIndex: 'value'},
|
|
|
|
|
|
],
|
|
|
|
|
|
resultCookiesColumns: [
|
|
|
|
|
|
{title: 'KEY', dataIndex: 'name'},
|
|
|
|
|
|
{title: 'VALUE', dataIndex: 'value'},
|
|
|
|
|
|
],
|
2021-11-06 22:55:10 +08:00
|
|
|
|
// 编辑器
|
|
|
|
|
|
resultDataInit,
|
2021-11-07 23:06:36 +08:00
|
|
|
|
resultDataContentOrigin,
|
|
|
|
|
|
resultDataContentFormat,
|
2021-11-06 22:55:10 +08:00
|
|
|
|
resultDataConfig: {
|
|
|
|
|
|
wrap: true,
|
|
|
|
|
|
readOnly: true,
|
|
|
|
|
|
autoScrollEditorIntoView: true,
|
|
|
|
|
|
enableBasicAutocompletion: true,
|
|
|
|
|
|
enableSnippets: true,
|
|
|
|
|
|
enableLiveAutocompletion: true,
|
|
|
|
|
|
minLines: 30,
|
|
|
|
|
|
maxLines: 30,
|
|
|
|
|
|
},
|
2021-11-04 23:43:58 +08:00
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
</script>
|
2021-11-06 22:55:10 +08:00
|
|
|
|
<style>
|
|
|
|
|
|
.status-info-box{color: #888;}
|
|
|
|
|
|
.status-info-box span{color: #00aa00; margin-right: 15px;}
|
|
|
|
|
|
.status-info-box span:last-child{margin-right: 0;}
|
|
|
|
|
|
</style>
|