ol-base-components 2.8.12 → 2.8.13
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 +6 -39
- package/readme1.md +164 -0
- package/src/assets/Snipaste_2025-09-03_14-30-49.png +0 -0
- package/src/assets/generator0.png +0 -0
- package/src/assets/generator1.png +0 -0
- package/src/assets/generator2.png +0 -0
- package/src/bin/initTemplate.js +1 -3
- package/src/bin/news.js +171 -0
- package/src/bin/openCloseloop.js +154 -0
- package/src/bin/openLoop.js +154 -0
- package/src/package/formSearch/src/index.js +29 -0
- package/src/package/formSearch/src/index.vue +115 -7
- package/src/package/table/src/index.vue +913 -914
- package/scripts/auto-install.js +0 -193
- package/scripts/build-vscode.js +0 -30
- package/scripts/install-vscode.js +0 -192
- package/src/component/countCom.vue +0 -105
- package/src/vscode/extension.js +0 -35
- package/src/vscode/webview/panel.js +0 -756
|
@@ -1,756 +0,0 @@
|
|
|
1
|
-
const vscode = require("vscode");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
|
|
5
|
-
// 复用现有的模板生成逻辑
|
|
6
|
-
function generateKeyName(url, method) {
|
|
7
|
-
// 移除前缀 "/api/app"
|
|
8
|
-
const cleanedUrl = url.replace(/\/api\/app/, "");
|
|
9
|
-
const arr = cleanedUrl.split("/");
|
|
10
|
-
|
|
11
|
-
// 处理 {xxx} 转换为 ByXxx
|
|
12
|
-
const processedArr = arr.map(
|
|
13
|
-
item =>
|
|
14
|
-
item
|
|
15
|
-
.replace(/{(.*?)}/, (_, param) => `By${param.charAt(0).toUpperCase() + param.slice(1)}`) // 处理 {xxx}
|
|
16
|
-
.replace(/[-_]/g, "") // 去除 - 和 _
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
// 删除第一个空项
|
|
20
|
-
if (processedArr[0] === "") {
|
|
21
|
-
processedArr.shift();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// 去重和拼接相邻相同的项
|
|
25
|
-
const resultArr = [];
|
|
26
|
-
for (let i = 0; i < processedArr.length; i++) {
|
|
27
|
-
if (i === 0 || processedArr[i] !== processedArr[i - 1]) {
|
|
28
|
-
// 将每项首字母大写
|
|
29
|
-
const capitalizedItem = processedArr[i].charAt(0).toUpperCase() + processedArr[i].slice(1);
|
|
30
|
-
resultArr.push(capitalizedItem);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const key = resultArr.join("");
|
|
34
|
-
return `${method.toLowerCase()}${key}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const vue2Template = (moduleName, config = {}) => {
|
|
38
|
-
// 生成各种接口的key名称
|
|
39
|
-
let pageUrlKey = "",
|
|
40
|
-
exportUrlKey = "",
|
|
41
|
-
addUrlKey = "",
|
|
42
|
-
editUrlKey = "",
|
|
43
|
-
deleteUrlKey = "",
|
|
44
|
-
detailUrlKey = "",
|
|
45
|
-
baseUrlKey = ""; //接口选择优先级:新增 > 编辑 > 详情
|
|
46
|
-
|
|
47
|
-
if (config.pageUrl) pageUrlKey = generateKeyName(config.pageUrl, "get");
|
|
48
|
-
if (config.exportUrl) exportUrlKey = generateKeyName(config.exportUrl, "post");
|
|
49
|
-
if (config.detailUrl) {
|
|
50
|
-
detailUrlKey = generateKeyName(config.detailUrl, "get");
|
|
51
|
-
baseUrlKey = `${detailUrlKey}CompleteUrl`; //补充后缀
|
|
52
|
-
}
|
|
53
|
-
if (config.editUrl) {
|
|
54
|
-
editUrlKey = generateKeyName(config.editUrl, "put");
|
|
55
|
-
baseUrlKey = `${editUrlKey}CompleteUrl`; //补充后缀
|
|
56
|
-
}
|
|
57
|
-
if (config.addUrl) baseUrlKey = addUrlKey = generateKeyName(config.addUrl, "post");
|
|
58
|
-
if (config.deleteUrl) deleteUrlKey = generateKeyName(config.deleteUrl, "delete");
|
|
59
|
-
|
|
60
|
-
// 生成导入语句
|
|
61
|
-
const generateImports = () => {
|
|
62
|
-
const imports = [];
|
|
63
|
-
if (config.pageUrl) imports.push(`${pageUrlKey}`);
|
|
64
|
-
if (config.addUrl) imports.push(`${addUrlKey}`);
|
|
65
|
-
if (config.editUrl) imports.push(`${editUrlKey}`);
|
|
66
|
-
if (config.detailUrl) imports.push(`${detailUrlKey}`);
|
|
67
|
-
if (config.deleteUrl) imports.push(`${deleteUrlKey}`);
|
|
68
|
-
return imports.join(", ");
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// 生成方法
|
|
72
|
-
const generateMethods = () => {
|
|
73
|
-
const methods = [];
|
|
74
|
-
|
|
75
|
-
// onCancel
|
|
76
|
-
if (config.hasAdd || config.hasEdit || config.hasDetail) {
|
|
77
|
-
methods.push(`
|
|
78
|
-
onCancel() {
|
|
79
|
-
this.formConfig.dialogVisible = false;
|
|
80
|
-
}`);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// onSubmit
|
|
84
|
-
if (config.hasAdd || config.hasEdit) {
|
|
85
|
-
methods.push(`
|
|
86
|
-
async onSubmit({ form, data }) {
|
|
87
|
-
if(form.type === 1){
|
|
88
|
-
//新建
|
|
89
|
-
const res = await ${addUrlKey}(data);
|
|
90
|
-
if(res.code !== 200) return;
|
|
91
|
-
this.$message("新建成功");
|
|
92
|
-
}else if (form.type === 2) {
|
|
93
|
-
//编辑
|
|
94
|
-
const res = await ${editUrlKey}(data['${config.rowId}'], data);
|
|
95
|
-
if(res.code !== 200) return;
|
|
96
|
-
this.$message("编辑成功");
|
|
97
|
-
this.init();
|
|
98
|
-
};
|
|
99
|
-
this.init();
|
|
100
|
-
this.onCancel()
|
|
101
|
-
}`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (config.hasAdd) {
|
|
105
|
-
methods.push(`
|
|
106
|
-
addBtnHandler() {
|
|
107
|
-
this.formConfig.title = "新增";
|
|
108
|
-
this.formConfig.type = 1;
|
|
109
|
-
this.formConfig.formData = {};
|
|
110
|
-
this.formConfig.dialogVisible = true;
|
|
111
|
-
}`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (config.hasEdit) {
|
|
115
|
-
methods.push(`
|
|
116
|
-
${config.hasDetail ? `async ` : ``}editBtnHandler() {
|
|
117
|
-
const data = this.multipleSelection;
|
|
118
|
-
if(data.length !== 1) return this.$message.info("请选择一条数据");
|
|
119
|
-
const row = data[0];
|
|
120
|
-
${
|
|
121
|
-
config.hasDetail
|
|
122
|
-
? `const { result = {} } = await ${detailUrlKey}(row.${config.rowId});
|
|
123
|
-
this.formConfig.formData = result || {};`
|
|
124
|
-
: `this.formConfig.formData = { ...row };`
|
|
125
|
-
}
|
|
126
|
-
this.formConfig.title = "编辑";
|
|
127
|
-
this.formConfig.type = 2;
|
|
128
|
-
this.formConfig.dialogVisible = true;
|
|
129
|
-
}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// 有详情
|
|
133
|
-
if (config.hasDetail) {
|
|
134
|
-
methods.push(`
|
|
135
|
-
async detailBtnHandler() {
|
|
136
|
-
const data = this.multipleSelection;
|
|
137
|
-
if(data.length !== 1) return this.$message.info("请选择一条数据");
|
|
138
|
-
const row = data[0];
|
|
139
|
-
const { result = {} } = await ${detailUrlKey}(row.${config.rowId});
|
|
140
|
-
this.formConfig.formData = result || {};
|
|
141
|
-
this.formConfig.title = "详情";
|
|
142
|
-
this.formConfig.type = 0;
|
|
143
|
-
this.formConfig.dialogVisible = true;
|
|
144
|
-
}`);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (config.hasDelete) {
|
|
148
|
-
methods.push(`
|
|
149
|
-
deleteBtnHandler() {
|
|
150
|
-
const data = this.multipleSelection;
|
|
151
|
-
if(data.length !== 1) return this.$message.info("请选择一条数据");
|
|
152
|
-
const row = data[0];
|
|
153
|
-
this.$confirm('确认删除当前数据吗?', '提示', {
|
|
154
|
-
confirmButtonText: '确定',
|
|
155
|
-
cancelButtonText: '取消',
|
|
156
|
-
type: 'warning'
|
|
157
|
-
}).then(() => {
|
|
158
|
-
${deleteUrlKey}(row.${config.rowId}).then(() => {
|
|
159
|
-
this.$message.success('删除成功');
|
|
160
|
-
this.init();
|
|
161
|
-
}).catch(() => {
|
|
162
|
-
this.$message.error('删除失败');
|
|
163
|
-
});
|
|
164
|
-
}).catch(() => {});
|
|
165
|
-
}`);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (config.hasExport) {
|
|
169
|
-
methods.push(`
|
|
170
|
-
export() {
|
|
171
|
-
const timer = this.formSearchData.value.createdTime;
|
|
172
|
-
this.formSearchData.value.BeginTime = timer ? timer[0] : "";
|
|
173
|
-
this.formSearchData.value.EndTime = timer ? timer[1] : "";
|
|
174
|
-
this.post({
|
|
175
|
-
url: ${config.swaggerModule}.${exportUrlKey},
|
|
176
|
-
isLoading: true,
|
|
177
|
-
responseType: "blob",
|
|
178
|
-
data: Object.assign(this.formSearchData.value, {
|
|
179
|
-
Page: this.paginations.page,
|
|
180
|
-
MaxResultCount: this.paginations.limit
|
|
181
|
-
})
|
|
182
|
-
}).then(res => {
|
|
183
|
-
this.fnexsl(res);
|
|
184
|
-
});
|
|
185
|
-
}`);
|
|
186
|
-
}
|
|
187
|
-
return methods.join(",");
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
return `<!--
|
|
191
|
-
Filename: ${moduleName}.vue
|
|
192
|
-
name: ${moduleName}
|
|
193
|
-
Created Date: ${new Date().toLocaleString()}
|
|
194
|
-
Author:
|
|
195
|
-
-->
|
|
196
|
-
<template>
|
|
197
|
-
<div>
|
|
198
|
-
<ol-search
|
|
199
|
-
:url="swaggerUrl.${pageUrlKey}"
|
|
200
|
-
:form-search-data="formSearchData"
|
|
201
|
-
@handleSearch="handleSearch"
|
|
202
|
-
@handleReset="handleReset"
|
|
203
|
-
/>
|
|
204
|
-
<ol-table
|
|
205
|
-
:url="swaggerUrl.${pageUrlKey}"
|
|
206
|
-
:paginations="paginations"
|
|
207
|
-
:btnlist="this.hasBtn(this)"
|
|
208
|
-
:empty-img="tableData.emptyImg"
|
|
209
|
-
:table-data="tableData"
|
|
210
|
-
:multiple-selection="multipleSelection"
|
|
211
|
-
@SelectionChange="SelectionChange"
|
|
212
|
-
@handleSizeChange="handleSizeChange"
|
|
213
|
-
@handleindexChange="handleindexChange"
|
|
214
|
-
/>
|
|
215
|
-
${
|
|
216
|
-
config.hasDialog
|
|
217
|
-
? `<el-dialog :title="formConfig.title" :visible.sync="formConfig.dialogVisible" width="80%">
|
|
218
|
-
<FormModule
|
|
219
|
-
v-if="formConfig.dialogVisible"
|
|
220
|
-
:formData="formConfig.formData"
|
|
221
|
-
:type="formConfig.type"
|
|
222
|
-
@onCancel="onCancel"
|
|
223
|
-
@onSubmit="onSubmit"
|
|
224
|
-
/>
|
|
225
|
-
</el-dialog>`
|
|
226
|
-
: ""
|
|
227
|
-
}
|
|
228
|
-
</div>
|
|
229
|
-
</template>
|
|
230
|
-
<script>
|
|
231
|
-
import { ${generateImports()} } from "@/api/modules";
|
|
232
|
-
import { ${config.swaggerModule} } from '@/api/swagger';
|
|
233
|
-
${config.hasDialog ? `import FormModule from "./components/formModule.vue"` : ""}
|
|
234
|
-
export default {
|
|
235
|
-
name: "${moduleName}",
|
|
236
|
-
${
|
|
237
|
-
config.hasDialog
|
|
238
|
-
? `components: {
|
|
239
|
-
FormModule
|
|
240
|
-
},`
|
|
241
|
-
: ""
|
|
242
|
-
}
|
|
243
|
-
data() {
|
|
244
|
-
return {
|
|
245
|
-
swaggerUrl: ${config.swaggerModule},
|
|
246
|
-
multipleSelection: [],
|
|
247
|
-
// 查询表单
|
|
248
|
-
formSearchData: {
|
|
249
|
-
reset: true, // 重置
|
|
250
|
-
expendShow: true, // 展开
|
|
251
|
-
value: {},
|
|
252
|
-
tableSearch: []
|
|
253
|
-
},
|
|
254
|
-
// 表格数据
|
|
255
|
-
tableData: {
|
|
256
|
-
loading: false,
|
|
257
|
-
emptyImg: true,
|
|
258
|
-
options: {
|
|
259
|
-
selection: true, // 多选框
|
|
260
|
-
index: null, // 序号
|
|
261
|
-
headTool: true, // 开启头部工具栏
|
|
262
|
-
refreshBtn: true, // 开启表格头部刷新按钮
|
|
263
|
-
downloadBtn: true // 开启表格头部下载按钮
|
|
264
|
-
}, // 序号和复选框
|
|
265
|
-
rows: [], // 表数据
|
|
266
|
-
columns: [],
|
|
267
|
-
operatesAttrs: {},
|
|
268
|
-
operates: [], // 表格里面的操作按钮
|
|
269
|
-
tableHeightDiff: 330
|
|
270
|
-
},
|
|
271
|
-
paginations: {
|
|
272
|
-
page: 1, // 当前位于那页面
|
|
273
|
-
total: 10, // 总数
|
|
274
|
-
limit: 30, // 一页显示多少条
|
|
275
|
-
pagetionShow: true
|
|
276
|
-
},
|
|
277
|
-
${
|
|
278
|
-
config.hasDialog
|
|
279
|
-
? `formConfig: {
|
|
280
|
-
type: 1,
|
|
281
|
-
formData: {},
|
|
282
|
-
title:"",
|
|
283
|
-
dialogVisible: false
|
|
284
|
-
}`
|
|
285
|
-
: ""
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
created() {
|
|
290
|
-
this.init()
|
|
291
|
-
},
|
|
292
|
-
methods: {
|
|
293
|
-
async init() {
|
|
294
|
-
const params = {
|
|
295
|
-
...this.formSearchData.value,
|
|
296
|
-
Page: this.paginations.page,
|
|
297
|
-
MaxResultCount: this.paginations.limit
|
|
298
|
-
};
|
|
299
|
-
const { result: { items = [], totalCount = 0 } = {} } = await ${pageUrlKey}(params, {
|
|
300
|
-
isLoading: true
|
|
301
|
-
});
|
|
302
|
-
this.tableData.rows = items;
|
|
303
|
-
this.paginations.total = totalCount;
|
|
304
|
-
this.tableData.emptyImg = true;
|
|
305
|
-
},
|
|
306
|
-
handleSearch(from) {
|
|
307
|
-
this.formSearchData.value = { ...from };
|
|
308
|
-
this.paginations.page = 1;
|
|
309
|
-
this.init();
|
|
310
|
-
},
|
|
311
|
-
handleReset() {
|
|
312
|
-
for (let key in this.formSearchData.value) {
|
|
313
|
-
this.formSearchData.value[key] = null;
|
|
314
|
-
}
|
|
315
|
-
this.paginations.page = 1;
|
|
316
|
-
},
|
|
317
|
-
SelectionChange(row) {
|
|
318
|
-
this.multipleSelection = row;
|
|
319
|
-
},
|
|
320
|
-
handleSizeChange(val) {
|
|
321
|
-
this.paginations.page = 1;
|
|
322
|
-
this.paginations.limit = val;
|
|
323
|
-
this.init();
|
|
324
|
-
},
|
|
325
|
-
handleindexChange(val) {
|
|
326
|
-
this.paginations.page = val;
|
|
327
|
-
this.init();
|
|
328
|
-
},${generateMethods()}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
</script>
|
|
332
|
-
`;
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
const vue2Form = (moduleName, config = {}) => {
|
|
336
|
-
let editUrlKey = "",
|
|
337
|
-
detailUrlKey = "",
|
|
338
|
-
baseUrlKey = "";
|
|
339
|
-
|
|
340
|
-
if (config.detailUrl) {
|
|
341
|
-
detailUrlKey = generateKeyName(config.detailUrl, "get");
|
|
342
|
-
baseUrlKey = `${detailUrlKey}CompleteUrl`; //补充后缀
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
if (config.editUrl) {
|
|
346
|
-
editUrlKey = generateKeyName(config.editUrl, "put");
|
|
347
|
-
baseUrlKey = `${editUrlKey}CompleteUrl`; //补充后缀
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (config.addUrl) baseUrlKey = generateKeyName(config.addUrl, "post");
|
|
351
|
-
|
|
352
|
-
return `<!--
|
|
353
|
-
Filename: ${moduleName}.vue
|
|
354
|
-
name: ${moduleName}
|
|
355
|
-
Created Date: ${new Date().toLocaleString()}
|
|
356
|
-
Author:
|
|
357
|
-
-->
|
|
358
|
-
<template>
|
|
359
|
-
<ol-form
|
|
360
|
-
:url="swaggerUrl.${baseUrlKey}"
|
|
361
|
-
:form="form"
|
|
362
|
-
@onCancel="onCancel"
|
|
363
|
-
@onSubmit="onSubmit"
|
|
364
|
-
/>
|
|
365
|
-
</template>
|
|
366
|
-
<script>
|
|
367
|
-
import { ${config.swaggerModule} } from '@/api/swagger';
|
|
368
|
-
export default {
|
|
369
|
-
name: "${moduleName}Form",
|
|
370
|
-
props: {
|
|
371
|
-
formData: {
|
|
372
|
-
type: Object,
|
|
373
|
-
default: () => ({})
|
|
374
|
-
},
|
|
375
|
-
type: {
|
|
376
|
-
type: Number,
|
|
377
|
-
default: 1
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
data() {
|
|
381
|
-
return {
|
|
382
|
-
swaggerUrl: ${config.swaggerModule},
|
|
383
|
-
form: {
|
|
384
|
-
type: this.type, // 0详情,1新增, 2编辑
|
|
385
|
-
title: "",
|
|
386
|
-
defaultValue: {}, // 默认值
|
|
387
|
-
value: {},
|
|
388
|
-
model: [],
|
|
389
|
-
rules: {},
|
|
390
|
-
attrs: {},
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
watch: {
|
|
395
|
-
type: {
|
|
396
|
-
handler(val){
|
|
397
|
-
this.form.type = val;
|
|
398
|
-
},
|
|
399
|
-
immediate: true
|
|
400
|
-
}
|
|
401
|
-
},
|
|
402
|
-
created(){
|
|
403
|
-
if(this.type !== 1) this.form.value = { ...this.formData };
|
|
404
|
-
},
|
|
405
|
-
methods: {
|
|
406
|
-
onCancel() {
|
|
407
|
-
this.$emit("onCancel");
|
|
408
|
-
},
|
|
409
|
-
onSubmit({form, data}) {
|
|
410
|
-
this.$emit("onSubmit", { form, data });
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
</script>
|
|
415
|
-
`;
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
class GeneratorPanel {
|
|
419
|
-
static currentPanel = undefined;
|
|
420
|
-
|
|
421
|
-
static createOrShow(extensionUri, targetUri) {
|
|
422
|
-
const column = vscode.window.activeTextEditor
|
|
423
|
-
? vscode.window.activeTextEditor.viewColumn
|
|
424
|
-
: undefined;
|
|
425
|
-
|
|
426
|
-
if (GeneratorPanel.currentPanel) {
|
|
427
|
-
GeneratorPanel.currentPanel._panel.reveal(column);
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const panel = vscode.window.createWebviewPanel(
|
|
432
|
-
"vueGenerator",
|
|
433
|
-
"Vue 页面生成器",
|
|
434
|
-
column || vscode.ViewColumn.One,
|
|
435
|
-
{
|
|
436
|
-
enableScripts: true,
|
|
437
|
-
localResourceRoots: [extensionUri],
|
|
438
|
-
}
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
GeneratorPanel.currentPanel = new GeneratorPanel(panel, extensionUri, targetUri);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
constructor(panel, extensionUri, targetUri) {
|
|
445
|
-
this._panel = panel;
|
|
446
|
-
this._extensionUri = extensionUri;
|
|
447
|
-
this._targetUri = targetUri;
|
|
448
|
-
this._disposables = [];
|
|
449
|
-
|
|
450
|
-
this._setWebviewMessageListener();
|
|
451
|
-
this._update();
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
_setWebviewMessageListener() {
|
|
455
|
-
this._panel.webview.onDidReceiveMessage(
|
|
456
|
-
message => {
|
|
457
|
-
switch (message.command) {
|
|
458
|
-
case "generate":
|
|
459
|
-
this._generateFiles(message.config);
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
},
|
|
463
|
-
undefined,
|
|
464
|
-
this._disposables
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
async _generateFiles(config) {
|
|
469
|
-
try {
|
|
470
|
-
const moduleName = config.moduleName;
|
|
471
|
-
const targetPath = path.dirname(this._targetUri.fsPath);
|
|
472
|
-
const outputDir = path.join(targetPath, moduleName);
|
|
473
|
-
|
|
474
|
-
// 检查目录是否存在
|
|
475
|
-
if (fs.existsSync(outputDir)) {
|
|
476
|
-
vscode.window.showErrorMessage(`❌ 创建失败,文件夹 ${outputDir} 已存在`);
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// 创建目录
|
|
481
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
482
|
-
|
|
483
|
-
// 生成主页面
|
|
484
|
-
const mainContent = vue2Template(moduleName, config);
|
|
485
|
-
const mainPath = path.join(outputDir, "index.vue");
|
|
486
|
-
fs.writeFileSync(mainPath, mainContent);
|
|
487
|
-
|
|
488
|
-
// 如果有弹窗功能,生成表单组件
|
|
489
|
-
if (config.hasDialog) {
|
|
490
|
-
const componentsDir = path.join(outputDir, "components");
|
|
491
|
-
fs.mkdirSync(componentsDir, { recursive: true });
|
|
492
|
-
|
|
493
|
-
const formContent = vue2Form(moduleName, config);
|
|
494
|
-
const formPath = path.join(componentsDir, "formModule.vue");
|
|
495
|
-
fs.writeFileSync(formPath, formContent);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
vscode.window.showInformationMessage(`✅ 页面模板已成功生成并保存到 ${outputDir}`);
|
|
499
|
-
|
|
500
|
-
// 打开生成的文件
|
|
501
|
-
const document = await vscode.workspace.openTextDocument(mainPath);
|
|
502
|
-
vscode.window.showTextDocument(document);
|
|
503
|
-
} catch (error) {
|
|
504
|
-
vscode.window.showErrorMessage(`❌ 生成过程中发生错误:${error.message}`);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
_update() {
|
|
509
|
-
const webview = this._panel.webview;
|
|
510
|
-
this._panel.title = "Vue 页面生成器";
|
|
511
|
-
this._panel.webview.html = this._getHtmlForWebview(webview);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
_getHtmlForWebview(webview) {
|
|
515
|
-
return `<!DOCTYPE html>
|
|
516
|
-
<html lang="zh-CN">
|
|
517
|
-
<head>
|
|
518
|
-
<meta charset="UTF-8">
|
|
519
|
-
<title>Vue 页面生成器</title>
|
|
520
|
-
<style>
|
|
521
|
-
body {
|
|
522
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
523
|
-
padding: 20px;
|
|
524
|
-
background-color: var(--vscode-editor-background);
|
|
525
|
-
color: var(--vscode-editor-foreground);
|
|
526
|
-
}
|
|
527
|
-
.container {
|
|
528
|
-
max-width: 600px;
|
|
529
|
-
margin: 0 auto;
|
|
530
|
-
}
|
|
531
|
-
.form-group {
|
|
532
|
-
margin-bottom: 20px;
|
|
533
|
-
}
|
|
534
|
-
label {
|
|
535
|
-
display: block;
|
|
536
|
-
margin-bottom: 5px;
|
|
537
|
-
font-weight: 500;
|
|
538
|
-
}
|
|
539
|
-
input[type="text"], input[type="url"] {
|
|
540
|
-
width: 100%;
|
|
541
|
-
padding: 8px 12px;
|
|
542
|
-
border: 1px solid var(--vscode-input-border);
|
|
543
|
-
border-radius: 4px;
|
|
544
|
-
background-color: var(--vscode-input-background);
|
|
545
|
-
color: var(--vscode-input-foreground);
|
|
546
|
-
box-sizing: border-box;
|
|
547
|
-
}
|
|
548
|
-
.checkbox-group {
|
|
549
|
-
display: flex;
|
|
550
|
-
flex-wrap: wrap;
|
|
551
|
-
gap: 15px;
|
|
552
|
-
}
|
|
553
|
-
.checkbox-group label {
|
|
554
|
-
display: flex;
|
|
555
|
-
align-items: center;
|
|
556
|
-
margin-bottom: 0;
|
|
557
|
-
cursor: pointer;
|
|
558
|
-
}
|
|
559
|
-
.checkbox-group input[type="checkbox"] {
|
|
560
|
-
margin-right: 5px;
|
|
561
|
-
}
|
|
562
|
-
.btn {
|
|
563
|
-
background-color: var(--vscode-button-background);
|
|
564
|
-
color: var(--vscode-button-foreground);
|
|
565
|
-
border: none;
|
|
566
|
-
padding: 10px 20px;
|
|
567
|
-
border-radius: 4px;
|
|
568
|
-
cursor: pointer;
|
|
569
|
-
font-size: 14px;
|
|
570
|
-
}
|
|
571
|
-
.btn:hover {
|
|
572
|
-
background-color: var(--vscode-button-hoverBackground);
|
|
573
|
-
}
|
|
574
|
-
.section {
|
|
575
|
-
background-color: var(--vscode-editor-inactiveSelectionBackground);
|
|
576
|
-
padding: 15px;
|
|
577
|
-
border-radius: 6px;
|
|
578
|
-
margin-bottom: 20px;
|
|
579
|
-
}
|
|
580
|
-
.section h3 {
|
|
581
|
-
margin-top: 0;
|
|
582
|
-
margin-bottom: 15px;
|
|
583
|
-
color: var(--vscode-editor-foreground);
|
|
584
|
-
}
|
|
585
|
-
</style>
|
|
586
|
-
</head>
|
|
587
|
-
<body>
|
|
588
|
-
<div class="container">
|
|
589
|
-
<h2>🎉 Vue 页面生成器</h2>
|
|
590
|
-
|
|
591
|
-
<div class="section">
|
|
592
|
-
<h3>基础配置</h3>
|
|
593
|
-
<div class="form-group">
|
|
594
|
-
<label for="moduleName">页面名称:</label>
|
|
595
|
-
<input type="text" id="moduleName" placeholder="请输入页面名称" required>
|
|
596
|
-
</div>
|
|
597
|
-
</div>
|
|
598
|
-
|
|
599
|
-
<div class="section">
|
|
600
|
-
<h3>API 配置</h3>
|
|
601
|
-
<div class="form-group">
|
|
602
|
-
<label for="pageUrl">分页接口地址:</label>
|
|
603
|
-
<input type="url" id="pageUrl" placeholder="/api/app/xxx/paged-result" required>
|
|
604
|
-
</div>
|
|
605
|
-
|
|
606
|
-
<div class="form-group">
|
|
607
|
-
<label>
|
|
608
|
-
<input type="checkbox" id="hasExport"> 是否有导出接口
|
|
609
|
-
</label>
|
|
610
|
-
</div>
|
|
611
|
-
|
|
612
|
-
<div class="form-group" id="exportUrlGroup" style="display:none;">
|
|
613
|
-
<label for="exportUrl">导出接口地址:</label>
|
|
614
|
-
<input type="url" id="exportUrl" placeholder="/api/app/xxx/export">
|
|
615
|
-
</div>
|
|
616
|
-
</div>
|
|
617
|
-
|
|
618
|
-
<div class="section">
|
|
619
|
-
<h3>功能选择</h3>
|
|
620
|
-
<div class="form-group">
|
|
621
|
-
<div class="checkbox-group">
|
|
622
|
-
<label><input type="checkbox" id="hasAdd"> 新增功能</label>
|
|
623
|
-
<label><input type="checkbox" id="hasEdit"> 编辑功能</label>
|
|
624
|
-
<label><input type="checkbox" id="hasDelete"> 删除功能</label>
|
|
625
|
-
<label><input type="checkbox" id="hasDetail"> 详情功能</label>
|
|
626
|
-
</div>
|
|
627
|
-
</div>
|
|
628
|
-
</div>
|
|
629
|
-
|
|
630
|
-
<div class="section" id="operationConfig" style="display:none;">
|
|
631
|
-
<h3>操作接口配置</h3>
|
|
632
|
-
<div class="form-group">
|
|
633
|
-
<label for="baseUrl">操作接口基础路径:</label>
|
|
634
|
-
<input type="url" id="baseUrl" placeholder="/api/app/xxx">
|
|
635
|
-
</div>
|
|
636
|
-
|
|
637
|
-
<div class="form-group">
|
|
638
|
-
<label for="idField">URL后缀ID字段名:</label>
|
|
639
|
-
<input type="text" id="idField" placeholder="admissionInfoId">
|
|
640
|
-
</div>
|
|
641
|
-
|
|
642
|
-
<div class="form-group">
|
|
643
|
-
<label for="rowId">行数据中ID字段键名:</label>
|
|
644
|
-
<input type="text" id="rowId" placeholder="id">
|
|
645
|
-
</div>
|
|
646
|
-
</div>
|
|
647
|
-
|
|
648
|
-
<div class="section">
|
|
649
|
-
<h3>模块配置</h3>
|
|
650
|
-
<div class="form-group">
|
|
651
|
-
<label for="swaggerModule">接口模块名:</label>
|
|
652
|
-
<input type="text" id="swaggerModule" placeholder="AdmissionInfo">
|
|
653
|
-
</div>
|
|
654
|
-
</div>
|
|
655
|
-
|
|
656
|
-
<button class="btn" id="generateBtn">🚀 生成页面</button>
|
|
657
|
-
</div>
|
|
658
|
-
|
|
659
|
-
<script>
|
|
660
|
-
const vscode = acquireVsCodeApi();
|
|
661
|
-
|
|
662
|
-
// 获取DOM元素
|
|
663
|
-
const moduleNameInput = document.getElementById('moduleName');
|
|
664
|
-
const pageUrlInput = document.getElementById('pageUrl');
|
|
665
|
-
const hasExportCheckbox = document.getElementById('hasExport');
|
|
666
|
-
const exportUrlGroup = document.getElementById('exportUrlGroup');
|
|
667
|
-
const exportUrlInput = document.getElementById('exportUrl');
|
|
668
|
-
const hasAddCheckbox = document.getElementById('hasAdd');
|
|
669
|
-
const hasEditCheckbox = document.getElementById('hasEdit');
|
|
670
|
-
const hasDeleteCheckbox = document.getElementById('hasDelete');
|
|
671
|
-
const hasDetailCheckbox = document.getElementById('hasDetail');
|
|
672
|
-
const operationConfig = document.getElementById('operationConfig');
|
|
673
|
-
const baseUrlInput = document.getElementById('baseUrl');
|
|
674
|
-
const idFieldInput = document.getElementById('idField');
|
|
675
|
-
const rowIdInput = document.getElementById('rowId');
|
|
676
|
-
const swaggerModuleInput = document.getElementById('swaggerModule');
|
|
677
|
-
const generateBtn = document.getElementById('generateBtn');
|
|
678
|
-
|
|
679
|
-
// 监听导出功能选择
|
|
680
|
-
hasExportCheckbox.addEventListener('change', () => {
|
|
681
|
-
exportUrlGroup.style.display = hasExportCheckbox.checked ? 'block' : 'none';
|
|
682
|
-
});
|
|
683
|
-
|
|
684
|
-
// 监听功能选择
|
|
685
|
-
function updateOperationConfig() {
|
|
686
|
-
const hasOperations = hasAddCheckbox.checked || hasEditCheckbox.checked ||
|
|
687
|
-
hasDeleteCheckbox.checked || hasDetailCheckbox.checked;
|
|
688
|
-
operationConfig.style.display = hasOperations ? 'block' : 'none';
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
hasAddCheckbox.addEventListener('change', updateOperationConfig);
|
|
692
|
-
hasEditCheckbox.addEventListener('change', updateOperationConfig);
|
|
693
|
-
hasDeleteCheckbox.addEventListener('change', updateOperationConfig);
|
|
694
|
-
hasDetailCheckbox.addEventListener('change', updateOperationConfig);
|
|
695
|
-
|
|
696
|
-
// 生成按钮点击事件
|
|
697
|
-
generateBtn.addEventListener('click', () => {
|
|
698
|
-
// 验证必填字段
|
|
699
|
-
if (!moduleNameInput.value.trim()) {
|
|
700
|
-
alert('请输入页面名称');
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
if (!pageUrlInput.value.trim()) {
|
|
704
|
-
alert('请输入分页接口地址');
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
const config = {
|
|
709
|
-
moduleName: moduleNameInput.value.trim(),
|
|
710
|
-
pageUrl: pageUrlInput.value.trim(),
|
|
711
|
-
hasExport: hasExportCheckbox.checked,
|
|
712
|
-
exportUrl: exportUrlInput.value.trim(),
|
|
713
|
-
hasAdd: hasAddCheckbox.checked,
|
|
714
|
-
hasEdit: hasEditCheckbox.checked,
|
|
715
|
-
hasDelete: hasDeleteCheckbox.checked,
|
|
716
|
-
hasDetail: hasDetailCheckbox.checked,
|
|
717
|
-
baseUrl: baseUrlInput.value.trim(),
|
|
718
|
-
idField: idFieldInput.value.trim() || 'id',
|
|
719
|
-
rowId: rowIdInput.value.trim() || 'id',
|
|
720
|
-
swaggerModule: swaggerModuleInput.value.trim() || 'Module',
|
|
721
|
-
hasDialog: hasAddCheckbox.checked || hasEditCheckbox.checked || hasDetailCheckbox.checked
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
// 发送消息给扩展
|
|
725
|
-
vscode.postMessage({
|
|
726
|
-
command: 'generate',
|
|
727
|
-
config: config
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
|
|
731
|
-
// 设置默认值
|
|
732
|
-
pageUrlInput.value = '/api/app/admission-info/paged-result';
|
|
733
|
-
baseUrlInput.value = '/api/app/admission-info/admission-info';
|
|
734
|
-
idFieldInput.value = 'admissionInfoId';
|
|
735
|
-
rowIdInput.value = 'id';
|
|
736
|
-
swaggerModuleInput.value = 'AdmissionInfo';
|
|
737
|
-
</script>
|
|
738
|
-
</body>
|
|
739
|
-
</html>`;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
dispose() {
|
|
743
|
-
GeneratorPanel.currentPanel = undefined;
|
|
744
|
-
this._panel.dispose();
|
|
745
|
-
while (this._disposables.length) {
|
|
746
|
-
const x = this._disposables.pop();
|
|
747
|
-
if (x) {
|
|
748
|
-
x.dispose();
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
module.exports = {
|
|
755
|
-
GeneratorPanel,
|
|
756
|
-
};
|