Skip to content

Commit 2513466

Browse files
committed
兼容2.4.2
1 parent d807ce9 commit 2513466

File tree

13 files changed

+110
-130
lines changed

13 files changed

+110
-130
lines changed

apidoc/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line no-unused-vars
2+
var config = {
3+
// 路由前缀
4+
routePrefix: ""
5+
};

apidoc/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>apidoc</title><link href=static/css/app.d65fcd89.css rel=preload as=style><link href=static/css/chunk-vendors.39c71c89.css rel=preload as=style><link href=static/js/app.9ecb1b87.js rel=preload as=script><link href=static/js/chunk-vendors.52db4364.js rel=preload as=script><link href=static/css/chunk-vendors.39c71c89.css rel=stylesheet><link href=static/css/app.d65fcd89.css rel=stylesheet></head><body><noscript><strong>We're sorry but apidoc doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=static/js/chunk-vendors.52db4364.js></script><script src=static/js/app.9ecb1b87.js></script></body></html>
1+
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>apidoc</title><script src=./config.js></script><link href=static/css/app.1f081d72.css rel=preload as=style><link href=static/css/chunk-vendors.f22bfe75.css rel=preload as=style><link href=static/js/app.b1a8082f.js rel=preload as=script><link href=static/js/chunk-vendors.52db4364.js rel=preload as=script><link href=static/css/chunk-vendors.f22bfe75.css rel=stylesheet><link href=static/css/app.1f081d72.css rel=stylesheet></head><body><noscript><strong>We're sorry but apidoc doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=static/js/chunk-vendors.52db4364.js></script><script src=static/js/app.b1a8082f.js></script></body></html>

apidoc/static/css/app.d65fcd89.css renamed to apidoc/static/css/app.1f081d72.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apidoc/static/css/chunk-vendors.39c71c89.css renamed to apidoc/static/css/chunk-vendors.f22bfe75.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apidoc/static/js/app.9ecb1b87.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

apidoc/static/js/app.b1a8082f.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line no-unused-vars
2+
var config = {
3+
// 路由前缀
4+
routePrefix: ""
5+
};

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="viewport" content="width=device-width,initial-scale=1.0">
77
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
88
<title>apidoc</title>
9+
<script src="./config.js"></script>
910
</head>
1011
<body>
1112
<noscript>

src/components/Index.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<div>{{ error.status }}</div>
2020
</div>
2121
<div class="error-message">{{ error.message }}</div>
22+
<div>
23+
<Button icon="reload" size="large" @click="reloadPage">刷新</Button>
24+
</div>
2225
</div>
2326
<div v-else>
2427
<splitpanes style="height: calc(100vh - 50px)">
@@ -85,7 +88,7 @@
8588
import Vue from "vue";
8689
import { Splitpanes, Pane } from "splitpanes";
8790
import "splitpanes/dist/splitpanes.css";
88-
import { Card, Spin, Drawer, Icon } from "ant-design-vue";
91+
import { Card, Spin, Drawer, Icon, Button } from "ant-design-vue";
8992
import DocMenu from "./Menu";
9093
import DocApiContent from "./content";
9194
import DocHome from "./DocHome";
@@ -113,7 +116,8 @@ export default {
113116
Header,
114117
Drawer,
115118
DocMdContent,
116-
Icon
119+
Icon,
120+
Button
117121
},
118122
mixins: [responsiveMixin],
119123
data() {
@@ -287,6 +291,9 @@ export default {
287291
that.getApiList();
288292
}
289293
});
294+
},
295+
reloadPage() {
296+
window.location.href = "/apidoc/";
290297
}
291298
}
292299
};
@@ -312,6 +319,7 @@ export default {
312319
background: #282c34;
313320
border-radius: 6px;
314321
color: #ddd;
322+
margin-bottom: 20px;
315323
}
316324
}
317325
</style>

src/components/content/DocDebug.vue

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ import "highlight.js/styles/atom-one-dark.css";
120120
import javascript from "highlight.js/lib/languages/javascript";
121121
import json from "highlight.js/lib/languages/json";
122122
import { sendRequest } from "@/utils/request";
123-
import { trim, getIndent } from "@/utils/utils";
123+
import { trim, getIndent, renderParamsCode } from "@/utils/utils";
124124
import TableInput from "@/utils/Input";
125125
import cloneDeep from "lodash/cloneDeep";
126126
import { ls } from "@/utils/cache";
@@ -257,59 +257,7 @@ export default {
257257
}
258258
}
259259
260-
this.parameters = this.renderParamsCode(params);
261-
},
262-
renderParamsCode(params, indent = 0) {
263-
const indentContent = getIndent(indent);
264-
const valueIndentContent = getIndent(indent + 2);
265-
266-
let code = indentContent + "{\n";
267-
if (indent > 0) {
268-
code = "";
269-
}
270-
if (params && params.length) {
271-
params.forEach(item => {
272-
let stringValue = item.default ? item.default : item.type;
273-
let value = `"${trim(stringValue)}"`;
274-
let type = "string";
275-
if (item.type == "object" && item.params && item.params.length) {
276-
let arrayCode = indentContent + "{\n";
277-
arrayCode += this.renderParamsCode(item.params, indent + 2);
278-
arrayCode += valueIndentContent + "},\n";
279-
value = arrayCode;
280-
type = "object";
281-
} else if (
282-
item.type == "array" &&
283-
item.params &&
284-
item.params.length
285-
) {
286-
let arrayCode = indentContent + "[\n";
287-
arrayCode += valueIndentContent + "{\n";
288-
arrayCode += this.renderParamsCode(item.params, indent + 2);
289-
arrayCode += valueIndentContent + "}\n";
290-
arrayCode += valueIndentContent + "],\n";
291-
value = arrayCode;
292-
type = "array";
293-
} else if (item.type == "tree" && item.params && item.params.length) {
294-
let arrayCode = indentContent + "[\n";
295-
arrayCode += valueIndentContent + "{\n";
296-
arrayCode += this.renderParamsCode(item.params, indent + 4);
297-
arrayCode += valueIndentContent + "}\n";
298-
arrayCode += valueIndentContent + "],\n";
299-
value = arrayCode;
300-
type = "tree";
301-
}
302-
let desc = `,\n`;
303-
if (type === "array" || type == "object" || type == "tree") {
304-
desc = "";
305-
}
306-
code += `${valueIndentContent}"${item.name}": ${value}${desc}`;
307-
});
308-
}
309-
if (indent == 0) {
310-
code += indentContent + "}\n";
311-
}
312-
return code;
260+
this.parameters = renderParamsCode(params);
313261
},
314262
315263
excute() {

src/components/content/DocJson.vue

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import VueHighlightJS from "vue-highlight.js";
5858
import "highlight.js/styles/atom-one-dark.css";
5959
import javascript from "highlight.js/lib/languages/javascript";
6060
import json from "highlight.js/lib/languages/json";
61-
import { trim, getIndent } from "@/utils/utils";
61+
import { trim, getIndent, renderParamsCode } from "@/utils/utils";
6262
import { Popover, Icon } from "ant-design-vue";
6363
6464
Vue.use(VueHighlightJS, {
@@ -85,11 +85,11 @@ export default {
8585
},
8686
computed: {
8787
paramCode() {
88-
const code = this.renderParamsCode(this.apiData.param, 0, true);
88+
const code = renderParamsCode(this.apiData.param, 0, true);
8989
return code;
9090
},
9191
returnCode() {
92-
const code = this.renderParamsCode(this.apiData.return, 0, true);
92+
const code = renderParamsCode(this.apiData.return, 0, true);
9393
return code;
9494
}
9595
},
@@ -98,62 +98,7 @@ export default {
9898
},
9999
100100
created() {},
101-
methods: {
102-
renderParamsCode(params, indent = 0) {
103-
const indentContent = getIndent(indent);
104-
const valueIndentContent = getIndent(indent + 2);
105-
106-
let code = indentContent + "{\n";
107-
if (indent > 0) {
108-
code = "";
109-
}
110-
if (params && params.length) {
111-
params.forEach(item => {
112-
let stringValue = item.default ? item.default : item.type;
113-
let value = `"${trim(stringValue)}"`;
114-
let type = "string";
115-
116-
if (item.type == "object" && item.params && item.params.length) {
117-
let arrayCode = indentContent + "{ //" + item.desc + "\n";
118-
arrayCode += this.renderParamsCode(item.params, indent + 2);
119-
arrayCode += valueIndentContent + "},\n";
120-
value = arrayCode;
121-
122-
type = "object";
123-
} else if (
124-
item.type == "array" &&
125-
item.params &&
126-
item.params.length
127-
) {
128-
let arrayCode = indentContent + "[ //" + item.desc + "\n";
129-
arrayCode += valueIndentContent + "{\n";
130-
arrayCode += this.renderParamsCode(item.params, indent + 2);
131-
arrayCode += valueIndentContent + "}\n";
132-
arrayCode += valueIndentContent + "],\n";
133-
value = arrayCode;
134-
type = "array";
135-
} else if (item.type == "tree" && item.params && item.params.length) {
136-
let arrayCode = indentContent + "[ //" + item.desc + "\n";
137-
arrayCode += valueIndentContent + "{\n";
138-
arrayCode += this.renderParamsCode(item.params, indent + 4);
139-
arrayCode += valueIndentContent + "}\n";
140-
arrayCode += valueIndentContent + "],\n";
141-
value = arrayCode;
142-
type = "tree";
143-
}
144-
let desc = `, // ${item.desc}\n`;
145-
if (type === "array" || type == "object" || type === "tree") {
146-
desc = "";
147-
}
148-
code += `${valueIndentContent}${item.name}: ${value}${desc}`;
149-
});
150-
}
151-
if (indent == 0) {
152-
code += indentContent + "}\n";
153-
}
154-
return code;
155-
}
156-
}
101+
methods: {}
157102
};
158103
</script>
159104

src/utils/request.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const handleError = error => {
2525
// 创建实例
2626
const service = axios.create({
2727
baseURL:
28-
process.env.NODE_ENV === "development" ? "http://test1.apidoc.com" : "",
28+
process.env.NODE_ENV === "development" ? "http://demo.apidoc.com" : "",
2929
timeout: 1 * 60 * 1000
3030
});
3131
// 请求拦截器
@@ -65,7 +65,8 @@ service.interceptors.response.use(
6565

6666
export const sendRequest = (apiUrl, params, type, headers = {}) => {
6767
const arr = {
68-
url: apiUrl,
68+
// eslint-disable-next-line no-undef
69+
url: config.routePrefix + apiUrl,
6970
method: type,
7071
headers: headers
7172
};

src/utils/utils.js

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,71 @@ export const renderParamsCode = (params, indent = 0, notes) => {
4040

4141
if (params && params.length) {
4242
params.forEach(item => {
43-
let stringValue = item.default ? item.default : item.type;
44-
let value = `"${trim(stringValue)}"`;
43+
let fieldValue = item.default;
44+
if (!fieldValue) {
45+
switch (item.type) {
46+
case "int":
47+
fieldValue = 0;
48+
break;
49+
case "boolean":
50+
fieldValue = false;
51+
break;
52+
case "date":
53+
fieldValue = getNowTime();
54+
break;
55+
56+
case "datetime":
57+
fieldValue = getNowTime("yyyy-MM-dd HH:mm:ss");
58+
break;
59+
case "time":
60+
fieldValue = getNowTime("HH:mm:ss");
61+
break;
62+
63+
default:
64+
fieldValue = item.type;
65+
break;
66+
}
67+
}
68+
let value = ["int", "float", "boolean"].includes(item.type)
69+
? fieldValue
70+
: `"${trim(fieldValue)}"`;
4571
let type = "string";
4672
let noteText = "";
4773
if (notes) {
4874
noteText = "//" + item.desc + "";
4975
}
5076

5177
if (item.type == "object" && item.params && item.params.length) {
52-
let arrayCode = indentContent + "{ " + noteText + "\n";
78+
let arrayCode = "{ " + noteText + "\n";
5379
arrayCode += renderParamsCode(item.params, indent + 2, notes);
5480
arrayCode += valueIndentContent + "},\n";
5581
value = arrayCode;
5682

5783
type = "object";
5884
} else if (item.type == "array" && item.params && item.params.length) {
59-
let arrayCode = indentContent + "[ " + noteText + "\n";
60-
arrayCode += valueIndentContent + "{\n";
61-
arrayCode += renderParamsCode(item.params, indent + 2, notes);
62-
arrayCode += valueIndentContent + "}\n";
85+
let arrayCode = "[ " + noteText + "\n";
86+
arrayCode += valueIndentContent + getIndent(2) + "{\n";
87+
arrayCode += renderParamsCode(item.params, indent + 4, notes);
88+
arrayCode += valueIndentContent + getIndent(2) + "}\n";
6389
arrayCode += valueIndentContent + "],\n";
6490
value = arrayCode;
6591
type = "array";
92+
} else if (item.type == "tree" && item.params && item.params.length) {
93+
let arrayCode = "[ " + noteText + "\n";
94+
arrayCode += valueIndentContent + getIndent(2) + "{\n";
95+
arrayCode += renderParamsCode(item.params, indent + 4);
96+
arrayCode += valueIndentContent + getIndent(2) + "}\n";
97+
arrayCode += valueIndentContent + "],\n";
98+
value = arrayCode;
99+
type = "tree";
66100
}
67101
let desc = "";
68-
if (!(type === "array" || type == "object") && notes) {
69-
desc = `, // ${item.desc}\n`;
102+
if (!(type === "array" || type == "object" || type === "tree")) {
103+
if (notes) {
104+
desc = `, // ${item.desc}\n`;
105+
} else {
106+
desc = `,\n`;
107+
}
70108
}
71109
code += `${valueIndentContent}${item.name}: ${value}${desc}`;
72110
});
@@ -162,3 +200,32 @@ export const getTreeFirstNode = (tree, childrenField = "children") => {
162200
export const textToHtml = text => {
163201
return text ? text.replace(/ /g, "&nbsp;").replace(/\r\n/g, "<br>") : "";
164202
};
203+
204+
export const getNowTime = (fmt = "yyyy-MM-dd") => {
205+
const date = new Date();
206+
var o = {
207+
"M+": date.getMonth() + 1, //月份
208+
"d+": date.getDate(), //日
209+
"H+": date.getHours(), //小时
210+
"h+": date.getHours(), //小时
211+
"m+": date.getMinutes(), //分
212+
"s+": date.getSeconds(), //秒
213+
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
214+
S: date.getMilliseconds() //毫秒
215+
};
216+
if (/(y+)/.test(fmt)) {
217+
fmt = fmt.replace(
218+
RegExp.$1,
219+
(date.getFullYear() + "").substr(4 - RegExp.$1.length)
220+
);
221+
}
222+
for (var k in o) {
223+
if (new RegExp("(" + k + ")").test(fmt)) {
224+
fmt = fmt.replace(
225+
RegExp.$1,
226+
RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
227+
);
228+
}
229+
}
230+
return fmt;
231+
};

0 commit comments

Comments
 (0)