update: api配置组件替换、逻辑优化
This commit is contained in:
parent
ae3f1a96ff
commit
68720f668c
|
@ -12,3 +12,4 @@ declare module '*.js';
|
||||||
declare module '*.ts';
|
declare module '*.ts';
|
||||||
declare module 'js-cookie';
|
declare module 'js-cookie';
|
||||||
declare module 'jetlinks-ui-components';
|
declare module 'jetlinks-ui-components';
|
||||||
|
declare module 'vue3-json-viewer';
|
|
@ -67,10 +67,10 @@ export default [
|
||||||
path: '/form',
|
path: '/form',
|
||||||
component: () => import('@/views/demo/Form.vue')
|
component: () => import('@/views/demo/Form.vue')
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
path: '/system/Api',
|
// path: '/system/Api',
|
||||||
component: () => import('@/views/system/Platforms/index.vue')
|
// component: () => import('@/views/system/Platforms/index.vue')
|
||||||
},
|
// },
|
||||||
// end: 测试用, 可删除
|
// end: 测试用, 可删除
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<h5>{{ selectApi.summary }}</h5>
|
<h5>{{ selectApi.summary }}</h5>
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<InputCard :value="selectApi.method" />
|
<InputCard :value="selectApi.method" />
|
||||||
<a-input :value="selectApi?.url" disabled />
|
<j-input :value="selectApi?.url" disabled />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -18,6 +18,14 @@
|
||||||
<span>{{ `["/"]` }}</span>
|
<span>{{ `["/"]` }}</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<div class="api-card" v-if="props.selectApi.description">
|
||||||
|
<h5>接口描述</h5>
|
||||||
|
<div>{{ props.selectApi.description }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="api-card" v-if="requestCard.codeText">
|
||||||
|
<h5>请求示例</h5>
|
||||||
|
<JsonViewer :value="requestCard.codeText" copyable />
|
||||||
|
</div>
|
||||||
<div class="api-card">
|
<div class="api-card">
|
||||||
<h5>请求参数</h5>
|
<h5>请求参数</h5>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
@ -26,12 +34,13 @@
|
||||||
:dataSource="requestCard.tableData"
|
:dataSource="requestCard.tableData"
|
||||||
noPagination
|
noPagination
|
||||||
model="TABLE"
|
model="TABLE"
|
||||||
|
size="small"
|
||||||
>
|
>
|
||||||
<template #required="slotProps">
|
<template #required="slotProps">
|
||||||
<span>{{ Boolean(slotProps.required) + '' }}</span>
|
<span>{{ Boolean(slotProps.required) + '' }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template #type="slotProps">
|
<template #type="slotProps">
|
||||||
<span>{{ slotProps.schema.type }}</span>
|
<span>{{ slotProps?.schema.type }}</span>
|
||||||
</template>
|
</template>
|
||||||
</j-pro-table>
|
</j-pro-table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,16 +53,17 @@
|
||||||
:dataSource="responseStatusCard.tableData"
|
:dataSource="responseStatusCard.tableData"
|
||||||
noPagination
|
noPagination
|
||||||
model="TABLE"
|
model="TABLE"
|
||||||
|
size="small"
|
||||||
>
|
>
|
||||||
</j-pro-table>
|
</j-pro-table>
|
||||||
|
|
||||||
<a-tabs v-model:activeKey="responseStatusCard.activeKey">
|
<j-tabs v-model:activeKey="responseStatusCard.activeKey">
|
||||||
<a-tab-pane
|
<j-tab-pane
|
||||||
:key="key"
|
:key="key"
|
||||||
:tab="key"
|
:tab="key"
|
||||||
v-for="key in tabs"
|
v-for="key in tabs"
|
||||||
></a-tab-pane>
|
></j-tab-pane>
|
||||||
</a-tabs>
|
</j-tabs>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -65,21 +75,19 @@
|
||||||
:dataSource="respParamsCard.tableData"
|
:dataSource="respParamsCard.tableData"
|
||||||
noPagination
|
noPagination
|
||||||
model="TABLE"
|
model="TABLE"
|
||||||
|
size="small"
|
||||||
>
|
>
|
||||||
</j-pro-table>
|
</j-pro-table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<MonacoEditor
|
<JsonViewer :value="respParamsCard.codeText" copyable />
|
||||||
v-model:modelValue="codeText"
|
|
||||||
style="height: 300px; width: 100%"
|
|
||||||
theme="vs"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import MonacoEditor from '@/components/MonacoEditor/index.vue';
|
import { JsonViewer } from 'vue3-json-viewer';
|
||||||
|
import 'vue3-json-viewer/dist/index.css';
|
||||||
import type { apiDetailsType } from '../typing';
|
import type { apiDetailsType } from '../typing';
|
||||||
import InputCard from './InputCard.vue';
|
import InputCard from './InputCard.vue';
|
||||||
import { PropType } from 'vue';
|
import { PropType } from 'vue';
|
||||||
|
@ -98,7 +106,7 @@ const { selectApi } = toRefs(props);
|
||||||
|
|
||||||
type tableCardType = {
|
type tableCardType = {
|
||||||
columns: object[];
|
columns: object[];
|
||||||
tableData: object[];
|
tableData: any[];
|
||||||
codeText?: any;
|
codeText?: any;
|
||||||
activeKey?: any;
|
activeKey?: any;
|
||||||
getData?: any;
|
getData?: any;
|
||||||
|
@ -134,8 +142,36 @@ const requestCard = reactive<tableCardType>({
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
tableData: [],
|
tableData: [],
|
||||||
|
codeText: undefined,
|
||||||
getData: () => {
|
getData: () => {
|
||||||
requestCard.tableData = props.selectApi.parameters;
|
if (!props.selectApi.requestBody)
|
||||||
|
return (requestCard.tableData = props.selectApi.parameters);
|
||||||
|
const schema =
|
||||||
|
props.selectApi.requestBody.content['application/json'].schema;
|
||||||
|
const schemaName = (schema.$ref || schema.items.$ref)?.split('/').pop();
|
||||||
|
const type = schema.type || '';
|
||||||
|
const tableData = findData(schemaName);
|
||||||
|
if (type === 'array') {
|
||||||
|
requestCard.codeText = [getCodeText(tableData, 3)];
|
||||||
|
} else requestCard.codeText = getCodeText(tableData, 3);
|
||||||
|
// console.clear();
|
||||||
|
// console.log(schemaName, tableData);
|
||||||
|
|
||||||
|
requestCard.tableData = [
|
||||||
|
{
|
||||||
|
name: schemaName[0].toLowerCase() + schemaName.substring(1),
|
||||||
|
description: schemaName,
|
||||||
|
in: 'body',
|
||||||
|
required: true,
|
||||||
|
schema: { type: type || schemaName },
|
||||||
|
children: tableData.map((item) => ({
|
||||||
|
name: item.paramsName,
|
||||||
|
description: item.desc,
|
||||||
|
required: false,
|
||||||
|
schema: { type: item.paramsType },
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const responseStatusCard = reactive<tableCardType>({
|
const responseStatusCard = reactive<tableCardType>({
|
||||||
|
@ -200,26 +236,43 @@ const respParamsCard = reactive<tableCardType>({
|
||||||
tableData: [],
|
tableData: [],
|
||||||
codeText: '',
|
codeText: '',
|
||||||
getData: (code: string) => {
|
getData: (code: string) => {
|
||||||
type schemaObjType = {
|
|
||||||
paramsName: string;
|
|
||||||
paramsType: string;
|
|
||||||
desc?: string;
|
|
||||||
children?: schemaObjType[];
|
|
||||||
};
|
|
||||||
|
|
||||||
const schemaName = responseStatusCard.tableData.find(
|
const schemaName = responseStatusCard.tableData.find(
|
||||||
(item: any) => item.code === code,
|
(item: any) => item.code === code,
|
||||||
)?.schema;
|
)?.schema;
|
||||||
|
|
||||||
|
const tableData = findData(schemaName);
|
||||||
|
respParamsCard.codeText = getCodeText(tableData, 3);
|
||||||
|
|
||||||
|
respParamsCard.tableData = tableData;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const getContent = (data: any) => {
|
||||||
|
if (data && data.content) {
|
||||||
|
return Object.keys(data.content || {})[0];
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
onMounted(() => {
|
||||||
|
requestCard.getData();
|
||||||
|
responseStatusCard.getData();
|
||||||
|
});
|
||||||
|
watch(
|
||||||
|
() => props.selectApi,
|
||||||
|
() => {
|
||||||
|
requestCard.getData();
|
||||||
|
responseStatusCard.getData();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
watch([() => responseStatusCard.activeKey, () => props.selectApi], (n) => {
|
||||||
|
n[0] && respParamsCard.getData(n[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
function findData(schemaName: string) {
|
||||||
const schemas = toRaw(props.schemas);
|
const schemas = toRaw(props.schemas);
|
||||||
const basicType = ['string', 'integer', 'boolean'];
|
const basicType = ['string', 'integer', 'boolean'];
|
||||||
|
|
||||||
const tableData = findData(schemaName);
|
|
||||||
const codeText = getCodeText(tableData, 3);
|
|
||||||
|
|
||||||
respParamsCard.tableData = tableData;
|
|
||||||
respParamsCard.codeText = JSON.stringify(codeText);
|
|
||||||
|
|
||||||
function findData(schemaName: string) {
|
|
||||||
if (!schemaName || !schemas[schemaName]) {
|
if (!schemaName || !schemas[schemaName]) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -245,7 +298,7 @@ const respParamsCard = reactive<tableCardType>({
|
||||||
}
|
}
|
||||||
function getCodeText(arr: schemaObjType[], level: number): object {
|
function getCodeText(arr: schemaObjType[], level: number): object {
|
||||||
const result = {};
|
const result = {};
|
||||||
|
const schemas = toRaw(props.schemas);
|
||||||
arr.forEach((item) => {
|
arr.forEach((item) => {
|
||||||
switch (item.paramsType) {
|
switch (item.paramsType) {
|
||||||
case 'string':
|
case 'string':
|
||||||
|
@ -261,7 +314,7 @@ const respParamsCard = reactive<tableCardType>({
|
||||||
result[item.paramsName] = [];
|
result[item.paramsName] = [];
|
||||||
break;
|
break;
|
||||||
case 'object':
|
case 'object':
|
||||||
result[item.paramsName] = {};
|
result[item.paramsName] = '';
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
const properties = schemas[item.paramsType]
|
const properties = schemas[item.paramsType]
|
||||||
|
@ -270,53 +323,28 @@ const respParamsCard = reactive<tableCardType>({
|
||||||
(item: [string, any]) => ({
|
(item: [string, any]) => ({
|
||||||
paramsName: item[0],
|
paramsName: item[0],
|
||||||
paramsType: level
|
paramsType: level
|
||||||
? (item[1].$ref &&
|
? (item[1].$ref && item[1].$ref.split('/').pop()) ||
|
||||||
item[1].$ref.split('/').pop()) ||
|
|
||||||
(item[1].items &&
|
(item[1].items &&
|
||||||
item[1].items.$ref
|
item[1].items.$ref.split('/').pop()) ||
|
||||||
.split('/')
|
|
||||||
.pop()) ||
|
|
||||||
item[1].type ||
|
item[1].type ||
|
||||||
''
|
''
|
||||||
: item[1].type,
|
: item[1].type,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
result[item.paramsName] = getCodeText(
|
result[item.paramsName] = getCodeText(newArr, level - 1);
|
||||||
newArr,
|
|
||||||
level - 1,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { codeText } = toRefs(requestCard);
|
type schemaObjType = {
|
||||||
|
paramsName: string;
|
||||||
const getContent = (data: any) => {
|
paramsType: string;
|
||||||
if (data && data.content) {
|
desc?: string;
|
||||||
return Object.keys(data.content || {})[0];
|
children?: schemaObjType[];
|
||||||
}
|
|
||||||
return '';
|
|
||||||
};
|
};
|
||||||
onMounted(() => {
|
|
||||||
requestCard.getData();
|
|
||||||
responseStatusCard.getData();
|
|
||||||
});
|
|
||||||
watch(
|
|
||||||
() => props.selectApi,
|
|
||||||
() => {
|
|
||||||
requestCard.getData();
|
|
||||||
responseStatusCard.getData();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
watch([() => responseStatusCard.activeKey, () => props.selectApi], (n) => {
|
|
||||||
n[0] && respParamsCard.getData(n[0]);
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<h5>{{ props.selectApi.summary }}</h5>
|
<h5>{{ props.selectApi.summary }}</h5>
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<InputCard :value="props.selectApi.method" />
|
<InputCard :value="props.selectApi.method" />
|
||||||
<a-input :value="props.selectApi?.url" disabled />
|
<j-input :value="props.selectApi?.url" disabled />
|
||||||
<span class="send" @click="send">发送</span>
|
<span class="send" @click="send">发送</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,14 +12,9 @@
|
||||||
<div class="api-card">
|
<div class="api-card">
|
||||||
<h5>请求参数</h5>
|
<h5>请求参数</h5>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<!-- <VueJsoneditor
|
|
||||||
height="400"
|
|
||||||
mode="tree"
|
|
||||||
v-model:text="requestBody.paramsText"
|
|
||||||
/> -->
|
|
||||||
<div class="table" v-if="paramsTable.length">
|
<div class="table" v-if="paramsTable.length">
|
||||||
<a-form :model="requestBody.params" ref="formRef" >
|
<j-form :model="requestBody.params" ref="formRef">
|
||||||
<a-table
|
<j-table
|
||||||
:columns="requestBody.tableColumns"
|
:columns="requestBody.tableColumns"
|
||||||
:dataSource="paramsTable"
|
:dataSource="paramsTable"
|
||||||
:pagination="false"
|
:pagination="false"
|
||||||
|
@ -27,7 +22,7 @@
|
||||||
>
|
>
|
||||||
<template #bodyCell="{ column, record, index }">
|
<template #bodyCell="{ column, record, index }">
|
||||||
<template v-if="column.key === 'name'">
|
<template v-if="column.key === 'name'">
|
||||||
<a-form-item
|
<j-form-item
|
||||||
:name="[
|
:name="[
|
||||||
'paramsTable',
|
'paramsTable',
|
||||||
index +
|
index +
|
||||||
|
@ -42,13 +37,13 @@
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<a-input
|
<j-input
|
||||||
v-model:value="record.name"
|
v-model:value="record.name"
|
||||||
></a-input>
|
></j-input>
|
||||||
</a-form-item>
|
</j-form-item>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="column.key === 'value'">
|
<template v-else-if="column.key === 'value'">
|
||||||
<a-form-item
|
<j-form-item
|
||||||
:name="[
|
:name="[
|
||||||
'paramsTable',
|
'paramsTable',
|
||||||
index +
|
index +
|
||||||
|
@ -63,10 +58,10 @@
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<a-input
|
<j-input
|
||||||
v-model:value="record.value"
|
v-model:value="record.value"
|
||||||
></a-input>
|
></j-input>
|
||||||
</a-form-item>
|
</j-form-item>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="column.key === 'action'">
|
<template v-else-if="column.key === 'action'">
|
||||||
<PermissionButton
|
<PermissionButton
|
||||||
|
@ -82,60 +77,53 @@
|
||||||
</PermissionButton>
|
</PermissionButton>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</j-table>
|
||||||
</a-form>
|
</j-form>
|
||||||
|
|
||||||
<a-pagination
|
<j-pagination
|
||||||
:pageSize="requestBody.pageSize"
|
:pageSize="requestBody.pageSize"
|
||||||
v-model:current="requestBody.pageNum"
|
v-model:current="requestBody.pageNum"
|
||||||
:total="requestBody.params.paramsTable.length"
|
:total="requestBody.params.paramsTable.length"
|
||||||
hideOnSinglePage
|
hideOnSinglePage
|
||||||
style="text-align: center"
|
style="text-align: center"
|
||||||
/>
|
/>
|
||||||
<a-button
|
<j-button
|
||||||
@click="requestBody.addRow"
|
@click="requestBody.addRow"
|
||||||
style="width: 100%; text-align: center"
|
style="width: 100%; text-align: center"
|
||||||
>
|
>
|
||||||
<AIcon type="PlusOutlined" />新增
|
<AIcon type="PlusOutlined" />新增
|
||||||
</a-button>
|
</j-button>
|
||||||
</div>
|
</div>
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
v-model:modelValue="requestBody.paramsText"
|
v-model:modelValue="requestBody.code"
|
||||||
style="height: 300px; width: 100%"
|
style="height: 300px; width: 100%"
|
||||||
theme="vs"
|
theme="vs"
|
||||||
|
ref="editorRef"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="api-card">
|
<div class="api-card">
|
||||||
<h5>响应参数</h5>
|
<h5>响应参数</h5>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<VueJsoneditor
|
<JsonViewer :value="responsesContent" copyable />
|
||||||
height="400"
|
|
||||||
mode="tree"
|
|
||||||
v-model:text="responsesContent"
|
|
||||||
:disabled="true"
|
|
||||||
/>
|
|
||||||
<!-- <MonacoEditor
|
|
||||||
v-model:modelValue="responsesContent"
|
|
||||||
style="height: 300px; width: 100%"
|
|
||||||
theme="vs"
|
|
||||||
/> -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import VueJsoneditor from 'vue3-ts-jsoneditor';
|
import { JsonViewer } from 'vue3-json-viewer';
|
||||||
|
import 'vue3-json-viewer/dist/index.css';
|
||||||
import MonacoEditor from '@/components/MonacoEditor/index.vue';
|
import MonacoEditor from '@/components/MonacoEditor/index.vue';
|
||||||
import type { apiDetailsType } from '../typing';
|
import type { apiDetailsType } from '../typing';
|
||||||
import InputCard from './InputCard.vue';
|
import InputCard from './InputCard.vue';
|
||||||
import { cloneDeep, toLower } from 'lodash';
|
import { cloneDeep, toLower } from 'lodash';
|
||||||
import { FormInstance } from 'ant-design-vue';
|
import { FormInstance } from 'ant-design-vue';
|
||||||
import server from '@/utils/request'
|
import server from '@/utils/request';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
selectApi: apiDetailsType;
|
selectApi: apiDetailsType;
|
||||||
|
schemas: any;
|
||||||
}>();
|
}>();
|
||||||
const formRef = ref<FormInstance>();
|
const formRef = ref<FormInstance>();
|
||||||
const requestBody = reactive({
|
const requestBody = reactive({
|
||||||
|
@ -163,10 +151,12 @@ const requestBody = reactive({
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
params: {
|
params: {
|
||||||
paramsTable: cloneDeep(props.selectApi.parameters || []) as requestObj[],
|
paramsTable: cloneDeep(
|
||||||
|
props.selectApi.parameters || [],
|
||||||
|
) as requestObj[],
|
||||||
},
|
},
|
||||||
|
|
||||||
paramsText: '',
|
code: '',
|
||||||
|
|
||||||
addRow: () => {
|
addRow: () => {
|
||||||
if (paramsTable.value.length === 10)
|
if (paramsTable.value.length === 10)
|
||||||
|
@ -188,49 +178,142 @@ const paramsTable = computed(() => {
|
||||||
return requestBody.params.paramsTable.slice(startIndex, endIndex);
|
return requestBody.params.paramsTable.slice(startIndex, endIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
const responsesContent = ref('{"a":123}');
|
const responsesContent = ref({});
|
||||||
|
const editorRef = ref()
|
||||||
const send = () => {
|
const send = () => {
|
||||||
|
if (paramsTable.value.length)
|
||||||
formRef.value &&
|
formRef.value &&
|
||||||
formRef.value.validate().then(() => {
|
formRef.value.validate().then(() => {
|
||||||
const methodName = toLower(props.selectApi.method)
|
_send();
|
||||||
|
});
|
||||||
|
else _send();
|
||||||
|
};
|
||||||
|
const _send = () => {
|
||||||
|
const methodName = toLower(props.selectApi.method);
|
||||||
const methodObj = {
|
const methodObj = {
|
||||||
get: 'get',
|
get: 'get',
|
||||||
post: 'post',
|
post: 'post',
|
||||||
patch: 'patch',
|
patch: 'patch',
|
||||||
put: 'put',
|
put: 'put',
|
||||||
delete: 'remove'
|
delete: 'remove',
|
||||||
}
|
};
|
||||||
|
|
||||||
let url = props.selectApi?.url;
|
let url = props.selectApi?.url;
|
||||||
const urlParams = {}
|
const urlParams = {};
|
||||||
requestBody.params.paramsTable.forEach(item=>{
|
requestBody.params.paramsTable.forEach((item) => {
|
||||||
if(methodName === 'get')
|
if (methodName === 'get') urlParams[item.name] = item.value;
|
||||||
urlParams[item.name] = item.value
|
|
||||||
if (url.includes(`{${item.name}}`))
|
if (url.includes(`{${item.name}}`))
|
||||||
url = url.replace(`{${item.name}}`, item.value)
|
url = url.replace(`{${item.name}}`, item.value);
|
||||||
})
|
});
|
||||||
const params = {
|
const params = {
|
||||||
...JSON.parse(requestBody.paramsText || '{}'),
|
...JSON.parse(requestBody.code || '{}'),
|
||||||
...urlParams
|
...urlParams,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
server[methodObj[methodName]](url, params).then((resp: any) => {
|
server[methodObj[methodName]](url, params).then((resp: any) => {
|
||||||
responsesContent.value = JSON.stringify(resp)
|
if (Object.keys(params).length === 0){
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
requestBody.code = JSON.stringify(getDefaultParams());
|
||||||
|
editorRef.value?.editorFormat()
|
||||||
|
}
|
||||||
|
responsesContent.value = resp;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取默认参数
|
||||||
|
*/
|
||||||
|
function getDefaultParams() {
|
||||||
|
if (!props.selectApi.requestBody) return {};
|
||||||
|
const schema =
|
||||||
|
props.selectApi.requestBody.content['application/json'].schema;
|
||||||
|
const schemaName = (schema.$ref || schema.items.$ref)?.split('/').pop();
|
||||||
|
const type = schema.type || '';
|
||||||
|
const tableData = findData(schemaName);
|
||||||
|
if (type === 'array') {
|
||||||
|
return [getCodeText(tableData, 3)];
|
||||||
|
} else return getCodeText(tableData, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findData(schemaName: string) {
|
||||||
|
const schemas = toRaw(props.schemas);
|
||||||
|
const basicType = ['string', 'integer', 'boolean'];
|
||||||
|
|
||||||
|
if (!schemaName || !schemas[schemaName]) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const result: schemaObjType[] = [];
|
||||||
|
const schema = schemas[schemaName];
|
||||||
|
Object.entries(schema.properties).forEach((item: [string, any]) => {
|
||||||
|
const paramsType =
|
||||||
|
item[1].type ||
|
||||||
|
(item[1].$ref && item[1].$ref.split('/').pop()) ||
|
||||||
|
(item[1].items && item[1].items.$ref.split('/').pop()) ||
|
||||||
|
'';
|
||||||
|
const schemaObj: schemaObjType = {
|
||||||
|
paramsName: item[0],
|
||||||
|
paramsType,
|
||||||
|
desc: item[1].description || '',
|
||||||
|
};
|
||||||
|
if (!basicType.includes(paramsType))
|
||||||
|
schemaObj.children = findData(paramsType);
|
||||||
|
result.push(schemaObj);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function getCodeText(arr: schemaObjType[], level: number): object {
|
||||||
|
const result = {};
|
||||||
|
const schemas = toRaw(props.schemas);
|
||||||
|
arr.forEach((item) => {
|
||||||
|
switch (item.paramsType) {
|
||||||
|
case 'string':
|
||||||
|
result[item.paramsName] = '';
|
||||||
|
break;
|
||||||
|
case 'integer':
|
||||||
|
result[item.paramsName] = 0;
|
||||||
|
break;
|
||||||
|
case 'boolean':
|
||||||
|
result[item.paramsName] = true;
|
||||||
|
break;
|
||||||
|
case 'array':
|
||||||
|
result[item.paramsName] = [];
|
||||||
|
break;
|
||||||
|
case 'object':
|
||||||
|
result[item.paramsName] = '';
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
const properties = schemas[item.paramsType]
|
||||||
|
.properties as object;
|
||||||
|
const newArr = Object.entries(properties).map(
|
||||||
|
(item: [string, any]) => ({
|
||||||
|
paramsName: item[0],
|
||||||
|
paramsType: level
|
||||||
|
? (item[1].$ref && item[1].$ref.split('/').pop()) ||
|
||||||
|
(item[1].items &&
|
||||||
|
item[1].items.$ref.split('/').pop()) ||
|
||||||
|
item[1].type ||
|
||||||
|
''
|
||||||
|
: item[1].type,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
result[item.paramsName] = getCodeText(newArr, level - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
type requestObj = {
|
type requestObj = {
|
||||||
name: string;
|
name: string;
|
||||||
value: string;
|
value: string;
|
||||||
};
|
};
|
||||||
|
type schemaObjType = {
|
||||||
|
paramsName: string;
|
||||||
|
paramsType: string;
|
||||||
|
desc?: string;
|
||||||
|
children?: schemaObjType[];
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
@ -284,8 +367,6 @@ type requestObj = {
|
||||||
.jtable-body-header {
|
.jtable-body-header {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
.table {
|
.table {
|
||||||
:deep(.ant-table-cell) {
|
:deep(.ant-table-cell) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="choose-api-container">
|
<div class="choose-api-container">
|
||||||
|
<div class="table">
|
||||||
<j-pro-table
|
<j-pro-table
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:dataSource="props.tableData"
|
:dataSource="props.tableData"
|
||||||
|
@ -15,9 +16,10 @@
|
||||||
>
|
>
|
||||||
</template>
|
</template>
|
||||||
</j-pro-table>
|
</j-pro-table>
|
||||||
|
</div>
|
||||||
|
|
||||||
<a-button type="primary" @click="save" v-if="props.mode !== 'home'"
|
<j-button type="primary" @click="save" v-if="props.mode !== 'home'"
|
||||||
>保存</a-button
|
>保存</j-button
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -88,8 +90,10 @@ watch(
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
.choose-api-container {
|
.choose-api-container {
|
||||||
height: 100%;
|
.table {
|
||||||
|
max-height: calc(100vh - 260px);
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
:deep(.jtable-body-header) {
|
:deep(.jtable-body-header) {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<a-tree
|
<j-tree
|
||||||
:tree-data="treeData"
|
:tree-data="treeData"
|
||||||
@select="clickSelectItem"
|
@select="clickSelectItem"
|
||||||
v-model:selected-keys="selectedKeys"
|
v-model:selected-keys="selectedKeys"
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
<template #title="{ name }">
|
<template #title="{ name }">
|
||||||
{{ name }}
|
{{ name }}
|
||||||
</template>
|
</template>
|
||||||
</a-tree>
|
</j-tree>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
@ -141,9 +141,6 @@ const filterPath = (path: object, filterArr: string[]) => {
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
.left-tree-container {
|
.left-tree-container {
|
||||||
border-right: 1px solid #e9e9e9;
|
|
||||||
height: calc(100vh - 150px);
|
|
||||||
overflow-y: auto;
|
|
||||||
.ant-tree-list {
|
.ant-tree-list {
|
||||||
.ant-tree-list-holder-inner {
|
.ant-tree-list-holder-inner {
|
||||||
.ant-tree-switcher-noop {
|
.ant-tree-switcher-noop {
|
||||||
|
|
|
@ -3,14 +3,15 @@
|
||||||
<div class="top">
|
<div class="top">
|
||||||
<slot name="top" />
|
<slot name="top" />
|
||||||
</div>
|
</div>
|
||||||
<a-row :gutter="24" style="background-color: #fff; padding: 20px;margin: 0;">
|
<j-row :gutter="24">
|
||||||
<a-col
|
<j-col
|
||||||
:span="24"
|
:span="24"
|
||||||
v-if="props.showTitle"
|
v-if="props.showTitle"
|
||||||
style="font-size: 16px; margin-bottom: 48px"
|
style="font-size: 16px; margin-bottom: 48px"
|
||||||
>API文档</a-col
|
|
||||||
>
|
>
|
||||||
<a-col :span="5">
|
API文档
|
||||||
|
</j-col>
|
||||||
|
<j-col :span="5" class="tree-content">
|
||||||
<LeftTree
|
<LeftTree
|
||||||
@select="treeSelect"
|
@select="treeSelect"
|
||||||
:mode="props.mode"
|
:mode="props.mode"
|
||||||
|
@ -18,8 +19,8 @@
|
||||||
:filter-array="treeFilter"
|
:filter-array="treeFilter"
|
||||||
:code="props.code"
|
:code="props.code"
|
||||||
/>
|
/>
|
||||||
</a-col>
|
</j-col>
|
||||||
<a-col :span="19">
|
<j-col :span="19">
|
||||||
<HomePage v-show="showHome" />
|
<HomePage v-show="showHome" />
|
||||||
<div class="url-page" v-show="!showHome">
|
<div class="url-page" v-show="!showHome">
|
||||||
<ChooseApi
|
<ChooseApi
|
||||||
|
@ -35,26 +36,29 @@
|
||||||
class="api-details"
|
class="api-details"
|
||||||
v-if="selectedApi.url && tableData.length > 0"
|
v-if="selectedApi.url && tableData.length > 0"
|
||||||
>
|
>
|
||||||
<a-button
|
<j-button
|
||||||
@click="selectedApi = initSelectedApi"
|
@click="selectedApi = initSelectedApi"
|
||||||
style="margin-bottom: 24px"
|
style="margin-bottom: 24px"
|
||||||
>返回</a-button
|
>返回</j-button
|
||||||
>
|
>
|
||||||
<a-tabs v-model:activeKey="activeKey" type="card">
|
<j-tabs v-model:activeKey="activeKey" type="card">
|
||||||
<a-tab-pane key="does" tab="文档">
|
<j-tab-pane key="does" tab="文档">
|
||||||
<ApiDoes
|
<ApiDoes
|
||||||
:select-api="selectedApi"
|
:select-api="selectedApi"
|
||||||
:schemas="schemas"
|
:schemas="schemas"
|
||||||
/>
|
/>
|
||||||
</a-tab-pane>
|
</j-tab-pane>
|
||||||
<a-tab-pane key="test" tab="调试">
|
<j-tab-pane key="test" tab="调试">
|
||||||
<ApiTest :select-api="selectedApi" />
|
<ApiTest
|
||||||
</a-tab-pane>
|
:select-api="selectedApi"
|
||||||
</a-tabs>
|
:schemas="schemas"
|
||||||
|
/>
|
||||||
|
</j-tab-pane>
|
||||||
|
</j-tabs>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a-col>
|
</j-col>
|
||||||
</a-row>
|
</j-row>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -76,7 +80,7 @@ const props = defineProps<{
|
||||||
mode: modeType;
|
mode: modeType;
|
||||||
showTitle?: boolean;
|
showTitle?: boolean;
|
||||||
hasHome?: boolean;
|
hasHome?: boolean;
|
||||||
code?: string
|
code?: string;
|
||||||
}>();
|
}>();
|
||||||
const showHome = ref<boolean>(Boolean(props.hasHome));
|
const showHome = ref<boolean>(Boolean(props.hasHome));
|
||||||
const tableData = ref([]);
|
const tableData = ref([]);
|
||||||
|
@ -127,7 +131,7 @@ function init() {
|
||||||
getApiGranted_api(props.code as string).then((resp) => {
|
getApiGranted_api(props.code as string).then((resp) => {
|
||||||
selectedKeys.value = resp.result as string[];
|
selectedKeys.value = resp.result as string[];
|
||||||
selectSourceKeys.value = [...(resp.result as string[])];
|
selectSourceKeys.value = [...(resp.result as string[])];
|
||||||
})
|
});
|
||||||
} else if (props.mode === 'api') {
|
} else if (props.mode === 'api') {
|
||||||
apiOperations_api().then((resp) => {
|
apiOperations_api().then((resp) => {
|
||||||
selectedKeys.value = resp.result as string[];
|
selectedKeys.value = resp.result as string[];
|
||||||
|
@ -138,12 +142,20 @@ function init() {
|
||||||
activeKey.value = 'does';
|
activeKey.value = 'does';
|
||||||
selectedApi.value = initSelectedApi;
|
selectedApi.value = initSelectedApi;
|
||||||
});
|
});
|
||||||
|
watch(
|
||||||
|
() => selectedApi.value.url,
|
||||||
|
() => (activeKey.value = 'does'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style lang="less" scoped>
|
||||||
.api-page-container {
|
.api-page-container {
|
||||||
height: 100%;
|
.tree-content {
|
||||||
background-color: transparent;
|
padding-bottom: 30px;
|
||||||
|
height: calc(100vh - 230px);
|
||||||
|
overflow-y: auto;
|
||||||
|
border-right: 1px solid #e9e9e9;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -22,6 +22,7 @@ export type apiDetailsType = {
|
||||||
parameters: any[];
|
parameters: any[];
|
||||||
requestBody?: any;
|
requestBody?: any;
|
||||||
responses:object;
|
responses:object;
|
||||||
|
description?:string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type modeType = 'api'| 'appManger' | 'home'
|
export type modeType = 'api'| 'appManger' | 'home'
|
|
@ -0,0 +1,28 @@
|
||||||
|
<template>
|
||||||
|
<page-container>
|
||||||
|
<div class="api-container">
|
||||||
|
<Api mode="api">
|
||||||
|
<template #top>
|
||||||
|
<p>
|
||||||
|
<AIcon
|
||||||
|
type="ExclamationCircleOutlined"
|
||||||
|
style="margin-right: 12px; font-size: 14px"
|
||||||
|
/>配置系统支持API赋权的范围
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
</Api>
|
||||||
|
</div>
|
||||||
|
</page-container>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts" name="Api">
|
||||||
|
import Api from '../Api/index.vue';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.api-container {
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
|
@ -16,5 +16,3 @@
|
||||||
<script setup lang="ts" name="Platforms">
|
<script setup lang="ts" name="Platforms">
|
||||||
import Api from './Api/index.vue';
|
import Api from './Api/index.vue';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
|
|
Loading…
Reference in New Issue