vue2server7 2.3.11 → 2.3.12
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/9.text +100 -0
- package/test/8.text +0 -14
package/package.json
CHANGED
package/test/9.text
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
|
|
3
|
+
const content = fs.readFileSync("input.txt", "utf8");
|
|
4
|
+
const lines = content.split(/\r?\n/);
|
|
5
|
+
|
|
6
|
+
// Java → TS 类型
|
|
7
|
+
function javaToTsType(javaType) {
|
|
8
|
+
const map = {
|
|
9
|
+
String: "string",
|
|
10
|
+
Integer: "number",
|
|
11
|
+
Long: "number",
|
|
12
|
+
Double: "number",
|
|
13
|
+
Float: "number",
|
|
14
|
+
BigDecimal: "number",
|
|
15
|
+
Boolean: "boolean",
|
|
16
|
+
Date: "string",
|
|
17
|
+
LocalDate: "string",
|
|
18
|
+
LocalDateTime: "string",
|
|
19
|
+
};
|
|
20
|
+
return map[javaType] || "any";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// TS 默认值
|
|
24
|
+
function defaultValue(tsType) {
|
|
25
|
+
switch (tsType) {
|
|
26
|
+
case "string":
|
|
27
|
+
return `""`;
|
|
28
|
+
case "number":
|
|
29
|
+
return `0`;
|
|
30
|
+
case "boolean":
|
|
31
|
+
return `false`;
|
|
32
|
+
default:
|
|
33
|
+
return `null`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 支持:@ApiModelProperty(value="xx") / @ApiModelProperty(value = "xx", required=true)
|
|
38
|
+
// 也顺手兼容:@ApiModelProperty("xx") 这种写法(有些项目会这样写)
|
|
39
|
+
function parseApiModelProperty(line) {
|
|
40
|
+
let m = /@ApiModelProperty\s*\(\s*value\s*=\s*"([^"]+)"/.exec(line);
|
|
41
|
+
if (m?.[1]) return m[1];
|
|
42
|
+
m = /@ApiModelProperty\s*\(\s*"([^"]+)"\s*\)/.exec(line);
|
|
43
|
+
if (m?.[1]) return m[1];
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 支持:@CheckV(desc="xx") / @CheckV(desc = "xx", ...)
|
|
48
|
+
function parseCheckV(line) {
|
|
49
|
+
const m = /@CheckV\s*\(\s*desc\s*=\s*"([^"]+)"/.exec(line);
|
|
50
|
+
return m?.[1] || null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 字段:private String queryDate;
|
|
54
|
+
function parseField(line) {
|
|
55
|
+
const m = /^\s*private\s+(\w+)\s+(\w+)\s*;\s*$/.exec(line);
|
|
56
|
+
if (!m) return null;
|
|
57
|
+
return { javaType: m[1], field: m[2] };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let apiLabel = null;
|
|
61
|
+
let checkLabel = null;
|
|
62
|
+
|
|
63
|
+
const jsonResult = [];
|
|
64
|
+
const tsFields = [];
|
|
65
|
+
const formFields = [];
|
|
66
|
+
|
|
67
|
+
for (const line of lines) {
|
|
68
|
+
const a = parseApiModelProperty(line);
|
|
69
|
+
if (a) {
|
|
70
|
+
apiLabel = a;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const c = parseCheckV(line);
|
|
75
|
+
if (c) {
|
|
76
|
+
checkLabel = c;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const f = parseField(line);
|
|
81
|
+
if (f) {
|
|
82
|
+
const label = apiLabel || checkLabel || f.field;
|
|
83
|
+
const tsType = javaToTsType(f.javaType);
|
|
84
|
+
|
|
85
|
+
jsonResult.push({ field: f.field, label });
|
|
86
|
+
tsFields.push(` /** ${label} */\n ${f.field}: ${tsType};`);
|
|
87
|
+
formFields.push(` /** ${label} */\n ${f.field}: ${defaultValue(tsType)}`);
|
|
88
|
+
|
|
89
|
+
// ✅ 关键:输出后立刻清空,避免串到下一个字段
|
|
90
|
+
apiLabel = null;
|
|
91
|
+
checkLabel = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 写文件
|
|
96
|
+
fs.writeFileSync("output.json", JSON.stringify(jsonResult, null, 2), "utf8");
|
|
97
|
+
fs.writeFileSync("model.ts", `export interface Model {\n${tsFields.join("\n\n")}\n}\n`, "utf8");
|
|
98
|
+
fs.writeFileSync("form.js", `export const formModel = {\n${formFields.join(",\n\n")}\n};\n`, "utf8");
|
|
99
|
+
|
|
100
|
+
console.log("✅ 已生成 output.json / model.ts / form.js");
|
package/test/8.text
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<el-input
|
|
2
|
-
v-model="value"
|
|
3
|
-
@input="value = format(value)"
|
|
4
|
-
/>
|
|
5
|
-
|
|
6
|
-
<script setup>
|
|
7
|
-
const format = (v) => {
|
|
8
|
-
v = v.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.')
|
|
9
|
-
if (v.startsWith('.')) v = '0' + v
|
|
10
|
-
const arr = v.split('.')
|
|
11
|
-
if (arr.length > 2) v = arr[0] + '.' + arr.slice(1).join('')
|
|
12
|
-
return v
|
|
13
|
-
}
|
|
14
|
-
</script>
|