ol-base-components 2.8.3 → 2.8.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol-base-components",
3
- "version": "2.8.3",
3
+ "version": "2.8.4",
4
4
  "private": false,
5
5
  "main": "src/package/index.js",
6
6
  "bin": {
@@ -16,7 +16,8 @@
16
16
  "lint": "vue-cli-service lint",
17
17
  "add": "node src/bin/add.js",
18
18
  "vscode:build": "node scripts/build-vscode.js",
19
- "vscode:install": "node scripts/install-vscode.js"
19
+ "vscode:install": "node scripts/install-vscode.js",
20
+ "postinstall": "node scripts/auto-install.js"
20
21
  },
21
22
  "dependencies": {
22
23
  "commander": "^14.0.0",
@@ -45,9 +46,9 @@
45
46
  "vscode": {
46
47
  "extension": {
47
48
  "name": "vue-page-generator",
48
- "displayName": "Vue Page Generator",
49
- "description": "Generate Vue CRUD pages from Swagger API",
50
- "version": "0.0.1",
49
+ "displayName": "Vue 页面生成器",
50
+ "description": "配合ol-base-components组件使用, 无需联调的CRUD页面",
51
+ "version": "0.0.2",
51
52
  "engines": {
52
53
  "vscode": "^1.60.0"
53
54
  },
@@ -59,8 +60,8 @@
59
60
  "commands": [
60
61
  {
61
62
  "command": "vue-generator.createPage",
62
- "title": "Generate Vue Page",
63
- "category": "Vue Generator"
63
+ "title": "生成 Vue 页面",
64
+ "category": "Vue 生成器"
64
65
  }
65
66
  ],
66
67
  "menus": {
@@ -116,8 +116,8 @@ function installVSCodeExtension() {
116
116
  // 创建 package.json
117
117
  const packageJson = {
118
118
  name: extensionName,
119
- displayName: "Vue Page Generator",
120
- description: "Generate Vue CRUD pages from Swagger API",
119
+ displayName: "Vue 页面生成器",
120
+ description: " Swagger API 生成 Vue CRUD 页面",
121
121
  version: "0.0.1",
122
122
  engines: {
123
123
  vscode: "^1.60.0",
@@ -128,13 +128,13 @@ function installVSCodeExtension() {
128
128
  commands: [
129
129
  {
130
130
  command: "vue-generator.createPage",
131
- title: "Generate Vue Page",
132
- category: "Vue Generator",
131
+ title: "生成 Vue 页面",
132
+ category: "Vue 生成器",
133
133
  },
134
134
  {
135
135
  command: "vue-generator.test",
136
- title: "Test Vue Generator",
137
- category: "Vue Generator",
136
+ title: "测试 Vue 生成器",
137
+ category: "Vue 生成器",
138
138
  },
139
139
  ],
140
140
  menus: {
@@ -142,7 +142,7 @@ function installVSCodeExtension() {
142
142
  {
143
143
  command: "vue-generator.createPage",
144
144
  group: "navigation",
145
- when: "resourceExtname == .vue || resourceExtname == .js || resourceExtname == .ts || resourceExtname == .jsx || resourceExtname == .tsx",
145
+ when: "resourceFolder",
146
146
  },
147
147
  ],
148
148
  },
@@ -2,15 +2,15 @@ const vscode = require("vscode");
2
2
  const { GeneratorPanel } = require("./webview/panel");
3
3
 
4
4
  function activate(context) {
5
- console.log("�� Vue Page Generator is now active!");
5
+ console.log("🎉 Vue 页面生成器扩展已激活!");
6
6
 
7
7
  // 显示通知确认扩展已激活
8
- vscode.window.showInformationMessage("Vue Page Generator 扩展已激活!");
8
+ vscode.window.showInformationMessage("Vue 页面生成器扩展已激活!");
9
9
 
10
10
  // 注册右键菜单命令
11
11
  const disposable = vscode.commands.registerCommand("vue-generator.createPage", uri => {
12
12
  console.log("命令被调用,URI:", uri);
13
- vscode.window.showInformationMessage("Generate Vue Page 命令被调用!");
13
+ vscode.window.showInformationMessage("生成 Vue 页面命令被调用!");
14
14
  GeneratorPanel.createOrShow(context.extensionUri, uri);
15
15
  });
16
16
 
@@ -18,14 +18,14 @@ function activate(context) {
18
18
 
19
19
  // 注册一个测试命令
20
20
  const testDisposable = vscode.commands.registerCommand("vue-generator.test", () => {
21
- vscode.window.showInformationMessage("Vue Page Generator 测试命令工作正常!");
21
+ vscode.window.showInformationMessage("Vue 页面生成器测试命令工作正常!");
22
22
  });
23
23
 
24
24
  context.subscriptions.push(testDisposable);
25
25
  }
26
26
 
27
27
  function deactivate() {
28
- console.log("Vue Page Generator 扩展已停用");
28
+ console.log("Vue 页面生成器扩展已停用");
29
29
  }
30
30
 
31
31
  module.exports = {
@@ -4,22 +4,28 @@ const fs = require("fs");
4
4
 
5
5
  // 复用现有的模板生成逻辑
6
6
  function generateKeyName(url, method) {
7
+ // 移除前缀 "/api/app"
7
8
  const cleanedUrl = url.replace(/\/api\/app/, "");
8
9
  const arr = cleanedUrl.split("/");
9
10
 
10
- const processedArr = arr.map(item =>
11
- item
12
- .replace(/{(.*?)}/, (_, param) => `By${param.charAt(0).toUpperCase() + param.slice(1)}`)
13
- .replace(/[-_]/g, "")
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, "") // 去除 - 和 _
14
17
  );
15
18
 
19
+ // 删除第一个空项
16
20
  if (processedArr[0] === "") {
17
21
  processedArr.shift();
18
22
  }
19
23
 
24
+ // 去重和拼接相邻相同的项
20
25
  const resultArr = [];
21
26
  for (let i = 0; i < processedArr.length; i++) {
22
27
  if (i === 0 || processedArr[i] !== processedArr[i - 1]) {
28
+ // 将每项首字母大写
23
29
  const capitalizedItem = processedArr[i].charAt(0).toUpperCase() + processedArr[i].slice(1);
24
30
  resultArr.push(capitalizedItem);
25
31
  }
@@ -28,29 +34,30 @@ function generateKeyName(url, method) {
28
34
  return `${method.toLowerCase()}${key}`;
29
35
  }
30
36
 
31
- // 复用现有的 vue2Template 函数
32
- function vue2Template(moduleName, config) {
37
+ const vue2Template = (moduleName, config = {}) => {
38
+ // 生成各种接口的key名称
33
39
  let pageUrlKey = "",
34
40
  exportUrlKey = "",
35
41
  addUrlKey = "",
36
42
  editUrlKey = "",
37
43
  deleteUrlKey = "",
38
44
  detailUrlKey = "",
39
- baseUrlKey = "";
45
+ baseUrlKey = ""; //接口选择优先级:新增 > 编辑 > 详情
40
46
 
41
47
  if (config.pageUrl) pageUrlKey = generateKeyName(config.pageUrl, "get");
42
48
  if (config.exportUrl) exportUrlKey = generateKeyName(config.exportUrl, "post");
43
49
  if (config.detailUrl) {
44
50
  detailUrlKey = generateKeyName(config.detailUrl, "get");
45
- baseUrlKey = `${detailUrlKey}CompleteUrl`;
51
+ baseUrlKey = `${detailUrlKey}CompleteUrl`; //补充后缀
46
52
  }
47
53
  if (config.editUrl) {
48
54
  editUrlKey = generateKeyName(config.editUrl, "put");
49
- baseUrlKey = `${editUrlKey}CompleteUrl`;
55
+ baseUrlKey = `${editUrlKey}CompleteUrl`; //补充后缀
50
56
  }
51
57
  if (config.addUrl) baseUrlKey = addUrlKey = generateKeyName(config.addUrl, "post");
52
58
  if (config.deleteUrl) deleteUrlKey = generateKeyName(config.deleteUrl, "delete");
53
59
 
60
+ // 生成导入语句
54
61
  const generateImports = () => {
55
62
  const imports = [];
56
63
  if (config.pageUrl) imports.push(`${pageUrlKey}`);
@@ -61,13 +68,46 @@ function vue2Template(moduleName, config) {
61
68
  return imports.join(", ");
62
69
  };
63
70
 
71
+ // 生成方法
64
72
  const generateMethods = () => {
65
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
+
66
104
  if (config.hasAdd) {
67
105
  methods.push(`
68
106
  addBtnHandler() {
69
- this.type = 1;
70
- this.dialogVisible = true;
107
+ this.formConfig.title = "新增";
108
+ this.formConfig.type = 1;
109
+ this.formConfig.formData = {};
110
+ this.formConfig.dialogVisible = true;
71
111
  }`);
72
112
  }
73
113
 
@@ -80,23 +120,27 @@ function vue2Template(moduleName, config) {
80
120
  ${
81
121
  config.hasDetail
82
122
  ? `const { result = {} } = await ${detailUrlKey}(row.${config.rowId});
83
- this.formData = result || {};`
84
- : `this.formData = { ...row };`
123
+ this.formConfig.formData = result || {};`
124
+ : `this.formConfig.formData = { ...row };`
85
125
  }
86
- this.type = 2;
87
- this.dialogVisible = true;
126
+ this.formConfig.title = "编辑";
127
+ this.formConfig.type = 2;
128
+ this.formConfig.dialogVisible = true;
88
129
  }`);
89
130
  }
90
131
 
132
+ // 有详情
91
133
  if (config.hasDetail) {
92
- methods.push(`async detailBtnHandler() {
134
+ methods.push(`
135
+ async detailBtnHandler() {
93
136
  const data = this.multipleSelection;
94
137
  if(data.length !== 1) return this.$message.info("请选择一条数据");
95
138
  const row = data[0];
96
139
  const { result = {} } = await ${detailUrlKey}(row.${config.rowId});
97
- this.formData = result || {};
98
- this.type = 0;
99
- this.dialogVisible = true;
140
+ this.formConfig.formData = result || {};
141
+ this.formConfig.title = "详情";
142
+ this.formConfig.type = 0;
143
+ this.formConfig.dialogVisible = true;
100
144
  }`);
101
145
  }
102
146
 
@@ -121,31 +165,25 @@ function vue2Template(moduleName, config) {
121
165
  }`);
122
166
  }
123
167
 
124
- if (config.hasAdd || config.hasEdit || config.hasDetail) {
125
- methods.push(`
126
- onCancel() {
127
- this.dialogVisible = false;
128
- }`);
129
- }
130
-
131
- if (config.hasAdd || config.hasEdit) {
168
+ if (config.hasExport) {
132
169
  methods.push(`
133
- async onSubmit({ form, data }) {
134
- if(form.type === 1){
135
- const res = await ${addUrlKey}(data);
136
- if(res.code !== 200) return;
137
- this.$message("新建成功");
138
- }else if (form.type === 2) {
139
- const res = await ${editUrlKey}(data['${config.rowId}'], data);
140
- if(res.code !== 200) return;
141
- this.$message("编辑成功");
142
- this.init();
143
- };
144
- this.init();
145
- this.onCancel()
146
- }`);
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
+ }`);
147
186
  }
148
-
149
187
  return methods.join(",");
150
188
  };
151
189
 
@@ -176,10 +214,11 @@ function vue2Template(moduleName, config) {
176
214
  />
177
215
  ${
178
216
  config.hasDialog
179
- ? `<el-dialog :title="this.form.title" :visible.sync="dialogVisible" width="80%">
217
+ ? `<el-dialog :title="formConfig.title" :visible.sync="formConfig.dialogVisible" width="80%">
180
218
  <FormModule
181
- v-if="dialogVisible"
182
- :formData="formData"
219
+ v-if="formConfig.dialogVisible"
220
+ :formData="formConfig.formData"
221
+ :type="formConfig.type"
183
222
  @onCancel="onCancel"
184
223
  @onSubmit="onSubmit"
185
224
  />
@@ -205,39 +244,44 @@ export default {
205
244
  return {
206
245
  swaggerUrl: ${config.swaggerModule},
207
246
  multipleSelection: [],
247
+ // 查询表单
208
248
  formSearchData: {
209
- reset: true,
210
- expendShow: true,
249
+ reset: true, // 重置
250
+ expendShow: true, // 展开
211
251
  value: {},
212
252
  tableSearch: []
213
253
  },
254
+ // 表格数据
214
255
  tableData: {
215
256
  loading: false,
216
257
  emptyImg: true,
217
258
  options: {
218
- selection: true,
219
- index: null,
220
- headTool: true,
221
- refreshBtn: true,
222
- downloadBtn: true
223
- },
224
- rows: [],
259
+ selection: true, // 多选框
260
+ index: null, // 序号
261
+ headTool: true, // 开启头部工具栏
262
+ refreshBtn: true, // 开启表格头部刷新按钮
263
+ downloadBtn: true // 开启表格头部下载按钮
264
+ }, // 序号和复选框
265
+ rows: [], // 表数据
225
266
  columns: [],
226
267
  operatesAttrs: {},
227
- operates: [],
268
+ operates: [], // 表格里面的操作按钮
228
269
  tableHeightDiff: 330
229
270
  },
230
271
  paginations: {
231
- page: 1,
232
- total: 10,
233
- limit: 30,
272
+ page: 1, // 当前位于那页面
273
+ total: 10, // 总数
274
+ limit: 30, // 一页显示多少条
234
275
  pagetionShow: true
235
276
  },
236
277
  ${
237
278
  config.hasDialog
238
- ? `type: 1,
239
- formData: {},
240
- dialogVisible: false`
279
+ ? `formConfig: {
280
+ type: 1,
281
+ formData: {},
282
+ title:"",
283
+ dialogVisible: false
284
+ }`
241
285
  : ""
242
286
  }
243
287
  }
@@ -281,47 +325,26 @@ export default {
281
325
  handleindexChange(val) {
282
326
  this.paginations.page = val;
283
327
  this.init();
284
- },
285
- ${
286
- config.hasExport
287
- ? `export() {
288
- const timer = this.formSearchData.value.createdTime;
289
- this.formSearchData.value.BeginTime = timer ? timer[0] : "";
290
- this.formSearchData.value.EndTime = timer ? timer[1] : "";
291
- this.post({
292
- url: ${config.swaggerModule}.${exportUrlKey},
293
- isLoading: true,
294
- responseType: "blob",
295
- data: Object.assign(this.formSearchData.value, {
296
- Page: this.paginations.page,
297
- MaxResultCount: this.paginations.limit
298
- })
299
- }).then(res => {
300
- this.fnexsl(res);
301
- });
302
- },`
303
- : ""
304
- }${generateMethods()}
328
+ },${generateMethods()}
305
329
  }
306
330
  }
307
331
  </script>
308
332
  `;
309
- }
333
+ };
310
334
 
311
- // 复用现有的 vue2Form 函数
312
- function vue2Form(moduleName, config) {
335
+ const vue2Form = (moduleName, config = {}) => {
313
336
  let editUrlKey = "",
314
337
  detailUrlKey = "",
315
338
  baseUrlKey = "";
316
339
 
317
340
  if (config.detailUrl) {
318
341
  detailUrlKey = generateKeyName(config.detailUrl, "get");
319
- baseUrlKey = `${detailUrlKey}CompleteUrl`;
342
+ baseUrlKey = `${detailUrlKey}CompleteUrl`; //补充后缀
320
343
  }
321
344
 
322
345
  if (config.editUrl) {
323
346
  editUrlKey = generateKeyName(config.editUrl, "put");
324
- baseUrlKey = `${editUrlKey}CompleteUrl`;
347
+ baseUrlKey = `${editUrlKey}CompleteUrl`; //补充后缀
325
348
  }
326
349
 
327
350
  if (config.addUrl) baseUrlKey = generateKeyName(config.addUrl, "post");
@@ -334,7 +357,6 @@ function vue2Form(moduleName, config) {
334
357
  -->
335
358
  <template>
336
359
  <ol-form
337
- v-if="dialogVisible"
338
360
  :url="swaggerUrl.${baseUrlKey}"
339
361
  :form="form"
340
362
  @onCancel="onCancel"
@@ -359,9 +381,9 @@ export default {
359
381
  return {
360
382
  swaggerUrl: ${config.swaggerModule},
361
383
  form: {
362
- type: this.type,
384
+ type: this.type, // 0详情,1新增, 2编辑
363
385
  title: "",
364
- defaultValue: {},
386
+ defaultValue: {}, // 默认值
365
387
  value: {},
366
388
  model: [],
367
389
  rules: {},
@@ -378,7 +400,7 @@ export default {
378
400
  }
379
401
  },
380
402
  created(){
381
- this.form.value = { ...this.formData };
403
+ if(this.type !== 1) this.form.value = { ...this.formData };
382
404
  },
383
405
  methods: {
384
406
  onCancel() {
@@ -391,7 +413,7 @@ export default {
391
413
  }
392
414
  </script>
393
415
  `;
394
- }
416
+ };
395
417
 
396
418
  class GeneratorPanel {
397
419
  static currentPanel = undefined;
@@ -473,13 +495,13 @@ class GeneratorPanel {
473
495
  fs.writeFileSync(formPath, formContent);
474
496
  }
475
497
 
476
- vscode.window.showInformationMessage(`✅ 模板已生成并保存到 ${outputDir}`);
498
+ vscode.window.showInformationMessage(`✅ 页面模板已成功生成并保存到 ${outputDir}`);
477
499
 
478
500
  // 打开生成的文件
479
501
  const document = await vscode.workspace.openTextDocument(mainPath);
480
502
  vscode.window.showTextDocument(document);
481
503
  } catch (error) {
482
- vscode.window.showErrorMessage(`❌ 发生错误:${error.message}`);
504
+ vscode.window.showErrorMessage(`❌ 生成过程中发生错误:${error.message}`);
483
505
  }
484
506
  }
485
507