Skip to content

Commit 954047b

Browse files
committed
升级2.0.9
- 支持自定义配置,请求类型颜色。 - 支持接口注解`ContentType`指定调试时请求ContentType。 - 修正全局参数调试接口为formdata类型时的异常问题。
1 parent 2a848a9 commit 954047b

File tree

13 files changed

+116
-40
lines changed

13 files changed

+116
-40
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apidoc",
3-
"version": "2.0.5",
3+
"version": "2.0.9",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",

public/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@ const config = {
1414
// 多个可切换的host
1515
HOSTS: [],
1616
},
17+
// 菜单配置
1718
MENU: {
1819
SHOWURL: false,
1920
WIDTH: 300,
2021
},
22+
// 请求类型的颜色
23+
METHODCOLOR: {
24+
GET: "#87d068",
25+
POST: "#2db7f5",
26+
PUT: "#ff9800",
27+
DELETE: "#ff4d4f",
28+
PATCH: "#802feb",
29+
},
2130
// 多语言
2231
LANG: [
2332
{

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
88
<title><%= htmlWebpackPlugin.options.title %></title>
99
<link rel="stylesheet" href="./icon/iconfont.css?t=<%= VUE_APP_VERSION %>">
10-
<script src="./config.js?t=<%= VUE_APP_VERSION %>"></script>
10+
<script src="./config.js?v=<%= VUE_APP_VERSION %>"></script>
1111
</head>
1212
<body>
1313
<noscript>

src/components/Menu/src/MenuItemContent.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
>
88
<span class="method-icon_multiple">{{ item.method.split(",").length }} </span>
99
</span>
10-
<span v-else-if="item.method" :class="['api-method-icon', `method-color_${item.method}`]">{{
11-
item.method
12-
}}</span>
10+
<span
11+
v-else-if="item.method"
12+
:class="['api-method-icon', `method-color_${item.method}`]"
13+
:style="{
14+
color:
15+
feConfig.METHODCOLOR && feConfig.METHODCOLOR[item.method]
16+
? feConfig.METHODCOLOR[item.method]
17+
: '',
18+
}"
19+
>{{ item.method }}</span
20+
>
1321
<FileMarkdownOutlined v-else-if="item.path && item.type === 'md'" />
1422
<FolderOutlined v-else />
1523

@@ -68,7 +76,7 @@ export default defineComponent({
6876
<style lang="less" scoped>
6977
.api-method-icon {
7078
display: inline-block;
71-
width: 36px;
79+
width: 40px;
7280
font-size: 12px;
7381
}
7482
.method-color_GET {

src/utils/http/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ if (localStorage.APIDOC_CONFIG) {
3737
const service = axios.create({
3838
baseURL: baseURL,
3939
timeout: timeout,
40+
withCredentials: true,
4041
});
4142

4243
// 请求拦截器
@@ -77,7 +78,6 @@ service.interceptors.request.use(
7778
}
7879
}
7980
}
80-
8181
return config;
8282
},
8383
(error) => {

src/views/apiDetail/Title.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default defineComponent({
2323
</script>
2424
<style lang="less" scoped>
2525
.title {
26-
margin-top: 24px;
26+
margin-top: 5px;
2727
.title-extra {
2828
line-height: 32px;
2929
}

src/views/apiDetail/debug/Index.vue

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div>
33
<div v-if="headerData && headerData.length">
44
<Title :title="t('apiPage.title.header')" />
5-
<div class="api-param-table mb">
5+
<div class="api-param-table mb-sm">
66
<Table
77
:columns="headersColumns"
88
size="small"
@@ -92,7 +92,7 @@
9292
:eventData="eventData.after"
9393
/>
9494
</Title>
95-
<div v-if="returnData && returnData.status" class="mb">
95+
<div v-if="returnData && returnData.status" class="mb-sm">
9696
<div class="mb-sm">
9797
<Alert
9898
:type="returnData.status >= 200 && returnData.status < 300 ? 'success' : 'error'"
@@ -292,12 +292,37 @@ export default defineComponent({
292292
293293
watchEffect(() => {
294294
if (props.detail.param) {
295-
const json = renderCodeJsonByParams(props.detail.param, true);
296-
state.paramCode = formatJsonCode(json);
297-
state.paramFormData = props.detail.param;
295+
const paramFormData = handleParamData(props.detail.param);
296+
if (props.detail.paramType === "formdata" || props.detail.paramType === "route") {
297+
state.paramFormData = paramFormData;
298+
} else {
299+
const json = renderCodeJsonByParams(paramFormData, true);
300+
state.paramCode = formatJsonCode(json);
301+
}
298302
}
299303
});
300304
305+
function handleParamData(paramData: ParamItem[]): ParamItem[] {
306+
const data = cloneDeep(paramData);
307+
if (data && data.length) {
308+
// 合并全局参数
309+
const globalParams = state.globalParams;
310+
if (globalParams && globalParams.params && globalParams.params.length) {
311+
return data.map((item) => {
312+
const globalParamFind = globalParams.params.find((p) => p.name === item.name);
313+
if (globalParamFind && globalParamFind.value) {
314+
item.default = globalParamFind.value;
315+
}
316+
return item;
317+
});
318+
} else {
319+
return data;
320+
}
321+
}
322+
323+
return [];
324+
}
325+
301326
const tableScroll = {
302327
x: "700px",
303328
y: "100%",
@@ -409,9 +434,10 @@ export default defineComponent({
409434
}
410435
411436
if (props.detail.paramType === "formdata") {
412-
headers[method] = {
413-
"Content-Type": "application/x-www-form-urlencoded",
414-
};
437+
headers["content-type"] = "application/x-www-form-urlencoded";
438+
}
439+
if (props.detail.contentType) {
440+
headers["content-type"] = props.detail.contentType;
415441
}
416442
let json: any = {
417443
method,
@@ -445,7 +471,6 @@ export default defineComponent({
445471
if (appConfig && appConfig.host) {
446472
json.baseURL = appConfig.host;
447473
}
448-
449474
Axios(url, json)
450475
.then((res) => {
451476
// 执行后置方法

src/views/apiDetail/debug/handleEvent.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,7 @@ const events = {
257257
headers: {},
258258
};
259259
if (eventItem.contentType) {
260-
ajaxOptions.headers[method] = {
261-
"Content-Type": eventItem.contentType,
262-
};
260+
ajaxOptions.headers["content-type"] = eventItem.contentType;
263261
}
264262
// 执行前置生成请求参数
265263
let params: ObjectType = {};

src/views/apiDetail/index.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
background-color: var(--color-red);
5353
color:var(--text-color-light);
5454
}
55+
&.dark{
56+
color:var(--text-color-light);
57+
}
5558
}
5659
.api-method-select {
5760
width: 105px;

src/views/apiDetail/index.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,20 @@
3838
}}</a-select-option>
3939
</a-select>
4040
</div>
41-
<div v-else :class="['api-url-method', currentMethod]">
41+
<div
42+
v-else
43+
:class="[
44+
'api-url-method',
45+
currentMethod,
46+
{ dark: feConfig.METHODCOLOR && feConfig.METHODCOLOR[detail.method] },
47+
]"
48+
:style="{
49+
backgroundColor:
50+
feConfig.METHODCOLOR && feConfig.METHODCOLOR[detail.method]
51+
? feConfig.METHODCOLOR[detail.method]
52+
: '',
53+
}"
54+
>
4255
{{ detail.method }}
4356
</div>
4457
<div :class="['api-url-input', { 'method-multiple': methodList.length > 0 }]">
@@ -116,6 +129,7 @@ export default defineComponent({
116129
config: computed(() => store.state.app.config),
117130
pageData: computed(() => store.state.app.pageData),
118131
apiObject: computed(() => store.state.apidoc.apiObject),
132+
feConfig: computed(() => store.state.app.feConfig),
119133
detail: detail,
120134
currentKey: "",
121135
methodList: methodList,

src/views/apiDetail/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ApiDetailState extends ApiItem {
1616
// param: ParamItem[];
1717
// return: ParamItem[];
1818
paramType?: string;
19+
contentType?: string;
1920
}
2021

2122
export interface UploadFileState {

src/views/home/home.less

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,35 @@
5959
padding-left: 0;
6060
list-style-type:none;
6161
&>li{
62-
display: flex;
63-
padding:5px 10px;
62+
63+
6464
margin-bottom: 5px;
6565
border-radius: 3px;
66+
position: relative;
67+
height: 36px;
68+
line-height: 36px;
69+
6670
.name{
6771
flex:1;
6872
text-align: left;
6973
}
70-
&.method-color_GET {
71-
background-color:lighten(#87d068,30%);
74+
.info{
75+
position: absolute;
76+
width: 100%;
77+
height: 100%;
78+
top:0;
79+
left: 0;
80+
z-index: 1;
81+
display: flex;
82+
padding:0 10px;
7283
}
73-
&.method-color_POST {
74-
background-color:lighten(#2db7f5,30%);
75-
}
76-
&.method-color_PUT {
77-
background-color: lighten(#ff9800,40%);
78-
}
79-
&.method-color_DELETE {
80-
background-color: lighten(#ff4d4f,30%);
84+
.bg{
85+
position: absolute;
86+
width: 100%;
87+
height: 100%;
88+
top:0;
89+
left: 0;
90+
opacity: 0.3;
8191
}
8292
}
8393
}

src/views/home/index.vue

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@
4848
<template #title> {{ t("common.type") }} </template>
4949
<div v-if="Object.keys(apiAnalysis.apiMethodTotal).length" class="method-list">
5050
<ul>
51-
<li
52-
v-for="(number, key) in apiAnalysis.apiMethodTotal"
53-
:key="key"
54-
:class="[`method-color_${key}`]"
55-
>
56-
<div class="name">{{ key }}</div>
57-
<div class="value">{{ number }}</div>
51+
<li v-for="(number, key) in apiAnalysis.apiMethodTotal" :key="key">
52+
<div class="info">
53+
<div class="name">{{ key }}</div>
54+
<div class="value">{{ number }}</div>
55+
</div>
56+
<div
57+
class="bg"
58+
:style="{
59+
backgroundColor:
60+
feConfig.METHODCOLOR && feConfig.METHODCOLOR[key]
61+
? feConfig.METHODCOLOR[key]
62+
: '',
63+
}"
64+
></div>
5865
</li>
5966
</ul>
6067
</div>
@@ -146,6 +153,7 @@ export default defineComponent({
146153
apiAnalysis: computed(() => store.state.apidoc.apiAnalysis),
147154
currentApp: computed(() => store.state.apidoc.currentApp),
148155
config: computed(() => store.state.app.config),
156+
feConfig: computed(() => store.state.app.feConfig),
149157
groupColumns: [
150158
{
151159
title: "名称",

0 commit comments

Comments
 (0)