Skip to content

Commit e916f42

Browse files
committed
升级v2.1.2
- 支持使用ref引入model时,仅指定到模型名,及使用@指定引用的方法。 - 接口调试时增加 更新mock数据并执行的操作。 - 修正ParamType类型为route、formdata时mock数据无法正常生成问题。 - 修正参数类型为int是为空的默认值为空的问题。
1 parent f11b808 commit e916f42

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
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.1.0",
3+
"version": "2.1.2",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",

public/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const config = {
1313
TIMEOUT: 30000,
1414
// 多个可切换的host
1515
HOSTS: [],
16+
// 请求头 encodeURIComponent 转码
17+
HEADERS_ENCODEURICOMPONENT: false,
1618
},
1719
// 菜单配置
1820
MENU: {
@@ -81,6 +83,7 @@ const config = {
8183
"apiPage.mdDetail.title": "{name} 字段的说明",
8284
"apiPage.debug.mock.reload": "更新Mock",
8385
"apiPage.debug.excute": "执行 Excute",
86+
"apiPage.debug.mockAndExcute": "更新Mock 并执行",
8487
"apiPage.debug.selectFile": "Select File",
8588
"apiPage.debug.selectFiles": "Select Files",
8689
"layout.menu.reload": "更新菜单",

src/api/interface/apiData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface ParamItem {
4646
require?: boolean;
4747
source?: string;
4848
type?: string;
49+
mock?: string;
4950
}
5051

5152
export interface ApiEventItem {

src/utils/helper/codeHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function renderCodeJsonByParams<T>(params: T[], isMock?: boolean): object
1010
if (isMock && item.mock) {
1111
fieldValue = Mock.mock(item.mock);
1212
}
13-
if (!fieldValue) {
13+
if (fieldValue === null) {
1414
switch (item.type) {
1515
case "int":
1616
fieldValue = 0;

src/utils/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const copyTextToClipboard = (text: string): boolean => {
4444
* @param {string} s
4545
*/
4646
export const trim = (s: string): string => {
47-
if (s) {
47+
if (s && s.replace) {
4848
return s.replace(/(^\s*)|(\s*$)/g, "");
4949
}
5050
return "";
@@ -243,7 +243,7 @@ export const getRandomNumber = (max: number, min?: number): number => {
243243
};
244244

245245
// 根据前17位生成末位
246-
export const createIdcardEndNumber = (idcard: string) => {
246+
export const createIdcardEndNumber = (idcard: string): string | number => {
247247
let arrExp = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; // 加权因子
248248
let arrValid = [1, 0, "X", 9, 8, 7, 6, 5, 4, 3, 2]; // 校验码
249249
let sum = 0;
@@ -255,7 +255,7 @@ export const createIdcardEndNumber = (idcard: string) => {
255255
};
256256

257257
// 生成身份证号
258-
export const createIdcard = () => {
258+
export const createIdcard = (): string => {
259259
let cityPrefixs = [
260260
11, 12, 13, 14, 15, 21, 22, 23, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 50, 51, 52,
261261
53, 54, 61, 62, 63, 64, 65, 71, 81, 82,

src/views/apiDetail/debug/Index.vue

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</div>
2525
<div>
2626
<Title :title="t('apiPage.title.params')">
27-
<a-button @click="onMockReload">
27+
<a-button v-if="isMock" @click="onMockReload">
2828
<ReloadOutlined />{{ t("apiPage.debug.mock.reload") }}
2929
</a-button>
3030
</Title>
@@ -83,7 +83,10 @@
8383
/>
8484
</div>
8585
</div>
86-
<div class="mb-sm">
86+
<div class="excute-buttons">
87+
<a-button v-if="isMock" type="primary" :loading="loading" block @click="mockAndExcute">{{
88+
t("apiPage.debug.mockAndExcute")
89+
}}</a-button>
8790
<a-button type="primary" :loading="loading" block @click="excute">{{
8891
t("apiPage.debug.excute")
8992
}}</a-button>
@@ -149,6 +152,8 @@ import EventPopover from "./EventPopover.vue";
149152
import { getAppsConfigItemByKey } from "@/utils";
150153
import { ConfigAppItem } from "@/api/interface/config";
151154
import { useRoute } from "vue-router";
155+
import Mock from "mockjs";
156+
import "@/utils/helper/mockExtend";
152157
153158
interface EventDataState {
154159
before: ResultState;
@@ -245,6 +250,7 @@ export default defineComponent({
245250
config: computed(() => store.state.app.config),
246251
eventData: eventData,
247252
feConfig: computed(() => store.state.app.feConfig),
253+
isMock: false,
248254
});
249255
const headersColumns = [
250256
{
@@ -310,23 +316,34 @@ export default defineComponent({
310316
311317
function handleParamData(paramData: ParamItem[]): ParamItem[] {
312318
const data = cloneDeep(paramData);
319+
let isMock = false;
320+
let res: ParamItem[] = [];
313321
if (data && data.length) {
314322
// 合并全局参数
315323
const globalParams = state.globalParams;
316324
if (globalParams && globalParams.params && globalParams.params.length) {
317-
return data.map((item) => {
325+
res = data.map((item) => {
318326
const globalParamFind = globalParams.params.find((p) => p.name === item.name);
319327
if (globalParamFind && globalParamFind.value) {
320328
item.default = globalParamFind.value;
321329
}
330+
if (item.mock) {
331+
isMock = true;
332+
}
322333
return item;
323334
});
324335
} else {
325-
return data;
336+
res = data.map((item) => {
337+
if (item.mock) {
338+
isMock = true;
339+
item.default = Mock.mock(item.mock);
340+
}
341+
return item;
342+
});
326343
}
327344
}
328-
329-
return [];
345+
state.isMock = isMock;
346+
return res;
330347
}
331348
332349
const tableScroll = {
@@ -408,6 +425,13 @@ export default defineComponent({
408425
}
409426
}
410427
428+
function mockAndExcute() {
429+
onMockReload();
430+
setTimeout(() => {
431+
excute();
432+
}, 200);
433+
}
434+
411435
async function sendRequest(url: string, data?: any) {
412436
state.loading = true;
413437
let method = props.currentMethod as string;
@@ -559,9 +583,22 @@ export default defineComponent({
559583
560584
function onMockReload() {
561585
if (props.detail.param) {
562-
const json = renderCodeJsonByParams(props.detail.param, true);
563-
state.paramCode = formatJsonCode(json);
586+
if (props.detail.paramType === "formdata" || props.detail.paramType === "route") {
587+
state.paramFormData = props.detail.param.map((p) => {
588+
if (p.mock) {
589+
p.default = Mock.mock(p.mock);
590+
}
591+
return p;
592+
});
593+
} else {
594+
const json = renderCodeJsonByParams(props.detail.param, true);
595+
state.paramCode = formatJsonCode(json);
596+
}
564597
}
598+
// if (props.detail.param) {
599+
// const json = renderCodeJsonByParams(props.detail.param, true);
600+
// state.paramCode = formatJsonCode(json);
601+
// }
565602
}
566603
567604
return {
@@ -577,6 +614,7 @@ export default defineComponent({
577614
formatJsonCode,
578615
onMockReload,
579616
t,
617+
mockAndExcute,
580618
};
581619
},
582620
});

src/views/apiDetail/debug/debug.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@
1212
border-radius: 4px;
1313
border: 1px solid var(--color-line);
1414
}
15+
.excute-buttons{
16+
margin-bottom: 10px;
17+
display: flex;
18+
button{
19+
flex:1;
20+
}
21+
button+button{
22+
margin-left: 10px;
23+
}
24+
}

0 commit comments

Comments
 (0)