vue2server7 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/test/2.js +80 -0
- package/test/1.js +0 -24
package/package.json
CHANGED
package/test/2.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
|
|
3
|
+
const content = fs.readFileSync("input.txt", "utf8");
|
|
4
|
+
|
|
5
|
+
// Java → TS 类型映射
|
|
6
|
+
function javaToTsType(javaType) {
|
|
7
|
+
const map = {
|
|
8
|
+
String: "string",
|
|
9
|
+
Integer: "number",
|
|
10
|
+
Long: "number",
|
|
11
|
+
Double: "number",
|
|
12
|
+
Float: "number",
|
|
13
|
+
BigDecimal: "number",
|
|
14
|
+
Boolean: "boolean",
|
|
15
|
+
Date: "string",
|
|
16
|
+
LocalDate: "string",
|
|
17
|
+
LocalDateTime: "string"
|
|
18
|
+
};
|
|
19
|
+
return map[javaType] || "any";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 根据 TS 类型生成默认值
|
|
23
|
+
function defaultValue(tsType) {
|
|
24
|
+
switch (tsType) {
|
|
25
|
+
case "string":
|
|
26
|
+
return `""`;
|
|
27
|
+
case "number":
|
|
28
|
+
return `0`;
|
|
29
|
+
case "boolean":
|
|
30
|
+
return `false`;
|
|
31
|
+
default:
|
|
32
|
+
return `null`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 匹配注解 + 字段
|
|
37
|
+
const regex =
|
|
38
|
+
/@ApiModelProperty\s*\(\s*value\s*=\s*"([^"]+)"[^)]*\)\s*[\r\n]+\s*private\s+(\w+)\s+(\w+)\s*;/g;
|
|
39
|
+
|
|
40
|
+
let match;
|
|
41
|
+
|
|
42
|
+
const jsonResult = [];
|
|
43
|
+
const tsFields = [];
|
|
44
|
+
const formFields = [];
|
|
45
|
+
|
|
46
|
+
while ((match = regex.exec(content)) !== null) {
|
|
47
|
+
const label = match[1];
|
|
48
|
+
const javaType = match[2];
|
|
49
|
+
const field = match[3];
|
|
50
|
+
|
|
51
|
+
const tsType = javaToTsType(javaType);
|
|
52
|
+
|
|
53
|
+
// JSON
|
|
54
|
+
jsonResult.push({
|
|
55
|
+
field,
|
|
56
|
+
label
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// TS
|
|
60
|
+
tsFields.push(` /** ${label} */\n ${field}: ${tsType};`);
|
|
61
|
+
|
|
62
|
+
// JS 表单对象
|
|
63
|
+
formFields.push(` ${field}: ${defaultValue(tsType)}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 写 JSON
|
|
67
|
+
fs.writeFileSync("output.json", JSON.stringify(jsonResult, null, 2));
|
|
68
|
+
|
|
69
|
+
// 写 TS
|
|
70
|
+
const tsContent = `export interface Model {\n${tsFields.join("\n\n")}\n}\n`;
|
|
71
|
+
fs.writeFileSync("model.ts", tsContent);
|
|
72
|
+
|
|
73
|
+
// 写 JS 表单对象
|
|
74
|
+
const formContent = `export const formModel = {\n${formFields.join(",\n")}\n};\n`;
|
|
75
|
+
fs.writeFileSync("form.js", formContent);
|
|
76
|
+
|
|
77
|
+
console.log("✅ 已生成:");
|
|
78
|
+
console.log(" - output.json");
|
|
79
|
+
console.log(" - model.ts");
|
|
80
|
+
console.log(" - form.js");
|
package/test/1.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
|
|
3
|
-
// 读取 text 文件
|
|
4
|
-
const content = fs.readFileSync("input.txt", "utf8");
|
|
5
|
-
|
|
6
|
-
// 正则:匹配 注解 + 字段
|
|
7
|
-
const regex =
|
|
8
|
-
/@ApiModelProperty\s*\(\s*value\s*=\s*"([^"]+)"\s*\)\s*[\r\n]+\s*private\s+\w+\s+(\w+)\s*;/g;
|
|
9
|
-
|
|
10
|
-
let match;
|
|
11
|
-
const result = [];
|
|
12
|
-
|
|
13
|
-
while ((match = regex.exec(content)) !== null) {
|
|
14
|
-
const label = match[1]; // 中文
|
|
15
|
-
const field = match[2]; // 字段名
|
|
16
|
-
|
|
17
|
-
result.push({
|
|
18
|
-
field,
|
|
19
|
-
label
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 输出 JSON
|
|
24
|
-
console.log(JSON.stringify(result, null, 2));
|