@dypnb/dev-tools 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-cb5f11a8.js +9419 -0
- package/dist/genPage/index.js +717 -0
- package/dist/genSwagger/index.js +203 -0
- package/dist/publishServer/index.js +44636 -0
- package/dist/wxServerNotice/index.js +18236 -0
- package/package.json +71 -0
@@ -0,0 +1,717 @@
|
|
1
|
+
import require$$0$1 from 'path';
|
2
|
+
import require$$0 from 'fs';
|
3
|
+
import { k as strCase, j as getDirname, e as getGlobalConfig, i as errorLog, l as log, s as successLog } from '../chunk-cb5f11a8.js';
|
4
|
+
import 'os';
|
5
|
+
import 'util';
|
6
|
+
import 'tty';
|
7
|
+
import 'child_process';
|
8
|
+
import 'assert';
|
9
|
+
import 'events';
|
10
|
+
import 'buffer';
|
11
|
+
import 'stream';
|
12
|
+
import 'node:url';
|
13
|
+
import 'node:path';
|
14
|
+
|
15
|
+
// template.js
|
16
|
+
var templateData = {
|
17
|
+
tablePageTemplate: (config = {}) => {
|
18
|
+
const {
|
19
|
+
name
|
20
|
+
} = config;
|
21
|
+
const titlCease = strCase(name);
|
22
|
+
return `<template>
|
23
|
+
<div class="app-container">
|
24
|
+
<CoustomTable
|
25
|
+
:queryFormJson="queryFormJson"
|
26
|
+
:pageButtonsJson="pageButtonsJson"
|
27
|
+
:tableJson="tableJson"
|
28
|
+
:tableData="tableData"
|
29
|
+
@onPageButton="handlerPageButton"
|
30
|
+
@onButton="handlerButton"
|
31
|
+
@onSearch="handlerSearch"
|
32
|
+
@onTableRowClick="handlerTableRowClick"
|
33
|
+
>
|
34
|
+
</CoustomTable>
|
35
|
+
|
36
|
+
<CoustomFormDialog
|
37
|
+
ref="formDialog"
|
38
|
+
:visible.sync="dialogVisible"
|
39
|
+
:dialogJson="dialogJson"
|
40
|
+
:initData="initFormData"
|
41
|
+
@onSubmit="handlerSubmit"
|
42
|
+
></CoustomFormDialog>
|
43
|
+
</div>
|
44
|
+
</template>
|
45
|
+
<script>
|
46
|
+
import CoustomTable from "@/components/CoustomTable";
|
47
|
+
import CoustomFormDialog from "@/components/CoustomFormDialog";
|
48
|
+
import { TableJson, QueryFormJson, PageButtonsJson, DialogJson } from "./constants";
|
49
|
+
import {
|
50
|
+
getDevApiIotClassesList,
|
51
|
+
postDevApiIotClasses,
|
52
|
+
getDevApiIotClassesClassId,
|
53
|
+
deleteDevApiIotClassesClassId,
|
54
|
+
putDevApiIotClasses
|
55
|
+
} from "@/api/iot/classes-controller.js";
|
56
|
+
import {
|
57
|
+
getDevApiIotPackagesList,
|
58
|
+
} from "@/api/iot/packages-controller.js";
|
59
|
+
export default {
|
60
|
+
name: '${titlCease}',
|
61
|
+
components: {
|
62
|
+
CoustomTable,
|
63
|
+
CoustomFormDialog
|
64
|
+
},
|
65
|
+
data() {
|
66
|
+
return {
|
67
|
+
queryFormJson: QueryFormJson,
|
68
|
+
pageButtonsJson: PageButtonsJson,
|
69
|
+
tableJson: TableJson,
|
70
|
+
dialogJson: DialogJson,
|
71
|
+
tableData: [],
|
72
|
+
// 总条数
|
73
|
+
total: 0,
|
74
|
+
// 查询参数
|
75
|
+
queryParams: {
|
76
|
+
pageNum: 1,
|
77
|
+
pageSize: 10,
|
78
|
+
},
|
79
|
+
dialogVisible: false,
|
80
|
+
initFormData: {},
|
81
|
+
}
|
82
|
+
},
|
83
|
+
created() {
|
84
|
+
},
|
85
|
+
mounted() {
|
86
|
+
this.getList();
|
87
|
+
},
|
88
|
+
computed: {
|
89
|
+
packageName() {
|
90
|
+
const { query } = this.$route;
|
91
|
+
return query.packageName
|
92
|
+
}
|
93
|
+
},
|
94
|
+
methods: {
|
95
|
+
async getPackageData() {
|
96
|
+
try {
|
97
|
+
const { rows = [] } = await getDevApiIotPackagesList();
|
98
|
+
return rows.map(item => {
|
99
|
+
return {
|
100
|
+
value: item.packageCode,
|
101
|
+
label: item.packageDispname,
|
102
|
+
}
|
103
|
+
})
|
104
|
+
} catch (error) {
|
105
|
+
return []
|
106
|
+
}
|
107
|
+
},
|
108
|
+
|
109
|
+
async handlerSubmit(formData) {
|
110
|
+
let params = {
|
111
|
+
...formData,
|
112
|
+
packageName: this.packageName
|
113
|
+
};
|
114
|
+
let msgText = '新增';
|
115
|
+
let func = postDevApiIotClasses;
|
116
|
+
if (this.dialogJson.type === 'Edit') {
|
117
|
+
params.classId = this.initFormData.classId;
|
118
|
+
msgText = '编辑';
|
119
|
+
func = putDevApiIotClasses;
|
120
|
+
}
|
121
|
+
try {
|
122
|
+
const { code } = await func(params);
|
123
|
+
if (code === 200) {
|
124
|
+
this.dialogVisible = false;
|
125
|
+
this.getList();
|
126
|
+
this.$modal.msgSuccess(msgText + "成功");
|
127
|
+
}
|
128
|
+
this.$refs.formDialog.resetLoading();
|
129
|
+
} catch (error) {
|
130
|
+
// 接口调用失败重置 loading
|
131
|
+
this.$refs.formDialog.resetLoading();
|
132
|
+
}
|
133
|
+
},
|
134
|
+
|
135
|
+
/** 查询表集合 */
|
136
|
+
getList(queryParams = {}) {
|
137
|
+
this.loading = true;
|
138
|
+
let queryData = {
|
139
|
+
...queryParams,
|
140
|
+
...this.queryParams,
|
141
|
+
packageName: this.packageName
|
142
|
+
}
|
143
|
+
getDevApiIotClassesList(queryData).then(response => {
|
144
|
+
this.tableData = response.rows;
|
145
|
+
this.total = response.total;
|
146
|
+
this.loading = false;
|
147
|
+
});
|
148
|
+
},
|
149
|
+
|
150
|
+
handlerTableRowClick(item) {
|
151
|
+
console.log('object :>>item ', item);
|
152
|
+
this.$router.push({
|
153
|
+
path: '/iot/packages/classes/detail',
|
154
|
+
query: {
|
155
|
+
classId: item.classId
|
156
|
+
}
|
157
|
+
})
|
158
|
+
},
|
159
|
+
|
160
|
+
// 搜索事件
|
161
|
+
handlerSearch(searchParams) {
|
162
|
+
this.queryParams = {
|
163
|
+
pageNum: 1,
|
164
|
+
pageSize: 10,
|
165
|
+
},
|
166
|
+
this.getList(searchParams);
|
167
|
+
},
|
168
|
+
|
169
|
+
//新增按钮事件
|
170
|
+
async handlerPageButton(item) {
|
171
|
+
const { type } = item;
|
172
|
+
if (type === 'Add') {
|
173
|
+
this.initFormData = {};
|
174
|
+
this.dialogJson.type = 'Add';
|
175
|
+
const packageData = await this.getPackageData()
|
176
|
+
this.$set(this.dialogJson.formJson.formItemJson[0], 'option',packageData )
|
177
|
+
console.log('object :>> ', this.dialogJson);
|
178
|
+
this.dialogVisible = true;
|
179
|
+
}
|
180
|
+
|
181
|
+
if (type === 'Delete') {
|
182
|
+
const tableIds = row.tableId || this.ids;
|
183
|
+
this.$modal.confirm('是否确认删除表编号为"' + tableIds + '"的数据项?').then(function () {
|
184
|
+
return delTable(tableIds);
|
185
|
+
}).then(() => {
|
186
|
+
this.getList();
|
187
|
+
this.$modal.msgSuccess("删除成功");
|
188
|
+
}).catch(() => { });
|
189
|
+
}
|
190
|
+
},
|
191
|
+
|
192
|
+
async getInfo(id) {
|
193
|
+
const { code, data } = await getDevApiIotClassesClassId(id);
|
194
|
+
if (code === 200) {
|
195
|
+
|
196
|
+
this.initFormData = data;
|
197
|
+
this.dialogJson.type = 'Edit';
|
198
|
+
this.dialogVisible = true;
|
199
|
+
}
|
200
|
+
},
|
201
|
+
|
202
|
+
deleteItem(id) {
|
203
|
+
this.$modal.confirm('是否确认删除该数据项?').then(function () {
|
204
|
+
return deleteDevApiIotClassesClassId(id);
|
205
|
+
}).then(() => {
|
206
|
+
this.getList();
|
207
|
+
this.$modal.msgSuccess("删除成功");
|
208
|
+
}).catch(() => { });
|
209
|
+
},
|
210
|
+
|
211
|
+
handlerButton(btnItem) {
|
212
|
+
const { row, item } = btnItem;
|
213
|
+
const { type } = item;
|
214
|
+
if (type === 'Edit') {
|
215
|
+
this.getInfo(row.classId);
|
216
|
+
}
|
217
|
+
|
218
|
+
if (type === 'Delete') {
|
219
|
+
this.deleteItem(row.classId);
|
220
|
+
}
|
221
|
+
},
|
222
|
+
},
|
223
|
+
}
|
224
|
+
</script>
|
225
|
+
<style scoped lang='scss'></style>`;
|
226
|
+
},
|
227
|
+
constantsTemplate: () => {
|
228
|
+
return `export const QueryFormJson = {
|
229
|
+
formOption: {
|
230
|
+
inline: true,
|
231
|
+
labelWidth: "100px",
|
232
|
+
size: 'small',
|
233
|
+
},
|
234
|
+
formItemJson: [
|
235
|
+
{
|
236
|
+
label: "类中文名称",
|
237
|
+
prop: "classDispname",
|
238
|
+
type: "Input",
|
239
|
+
isEnter: true,
|
240
|
+
options: {
|
241
|
+
clearable: true,
|
242
|
+
placeholder: '请输入类名称',
|
243
|
+
}
|
244
|
+
}
|
245
|
+
],
|
246
|
+
buttonJson: {
|
247
|
+
type: 'Search',
|
248
|
+
list: [
|
249
|
+
{
|
250
|
+
label: "搜索",
|
251
|
+
type: 'Query',
|
252
|
+
options: {
|
253
|
+
icon: "el-icon-search",
|
254
|
+
size: "mini",
|
255
|
+
type: "primary"
|
256
|
+
}
|
257
|
+
},
|
258
|
+
{
|
259
|
+
label: "重置",
|
260
|
+
type: 'Reset',
|
261
|
+
options: {
|
262
|
+
icon: "el-icon-refresh",
|
263
|
+
size: "mini",
|
264
|
+
}
|
265
|
+
},
|
266
|
+
]
|
267
|
+
|
268
|
+
}
|
269
|
+
}
|
270
|
+
|
271
|
+
export const PageButtonsJson = {
|
272
|
+
rowJson: {
|
273
|
+
gutter: 10,
|
274
|
+
},
|
275
|
+
buttonList: [
|
276
|
+
{
|
277
|
+
span: 1.5,
|
278
|
+
label: '新增',
|
279
|
+
permi: '',
|
280
|
+
type: 'Add',
|
281
|
+
options: [
|
282
|
+
{
|
283
|
+
icon: "el-icon-plus",
|
284
|
+
plain: true,
|
285
|
+
size: "mini",
|
286
|
+
type: "primary",
|
287
|
+
},
|
288
|
+
|
289
|
+
]
|
290
|
+
}
|
291
|
+
]
|
292
|
+
}
|
293
|
+
|
294
|
+
export const TableJson = {
|
295
|
+
columnJson: {
|
296
|
+
showSelect: false,
|
297
|
+
showIndex: true,
|
298
|
+
data: [
|
299
|
+
{
|
300
|
+
type: "index",
|
301
|
+
width: "55",
|
302
|
+
align: "left",
|
303
|
+
headerAlign: "left",
|
304
|
+
label: "序号"
|
305
|
+
},
|
306
|
+
{
|
307
|
+
align: "left",
|
308
|
+
headerAlign: "left",
|
309
|
+
label: "类中文名称",
|
310
|
+
prop: "classDispname",
|
311
|
+
showOverflowTooltip: true,
|
312
|
+
isLink: true,
|
313
|
+
},
|
314
|
+
{
|
315
|
+
align: "left",
|
316
|
+
headerAlign: "left",
|
317
|
+
label: "类英文名称",
|
318
|
+
prop: "classCode",
|
319
|
+
showOverflowTooltip: true,
|
320
|
+
},
|
321
|
+
{
|
322
|
+
align: "left",
|
323
|
+
headerAlign: "left",
|
324
|
+
label: "类类型",
|
325
|
+
prop: "classesType",
|
326
|
+
showOverflowTooltip: true,
|
327
|
+
},
|
328
|
+
{
|
329
|
+
align: "left",
|
330
|
+
headerAlign: "left",
|
331
|
+
label: "访问类型",
|
332
|
+
prop: "accessType",
|
333
|
+
showOverflowTooltip: true,
|
334
|
+
},
|
335
|
+
{
|
336
|
+
align: "left",
|
337
|
+
headerAlign: "left",
|
338
|
+
label: "实例存储表名称",
|
339
|
+
prop: "delFlag",
|
340
|
+
showOverflowTooltip: true,
|
341
|
+
},
|
342
|
+
{
|
343
|
+
align: "left",
|
344
|
+
headerAlign: "left",
|
345
|
+
label: "备注",
|
346
|
+
prop: "remark",
|
347
|
+
showOverflowTooltip: true,
|
348
|
+
},
|
349
|
+
{
|
350
|
+
align: "left",
|
351
|
+
headerAlign: "left",
|
352
|
+
label: "创建时间",
|
353
|
+
prop: "createTime",
|
354
|
+
showOverflowTooltip: true,
|
355
|
+
},
|
356
|
+
{
|
357
|
+
align: "center",
|
358
|
+
headerAlign: "center",
|
359
|
+
label: "操作",
|
360
|
+
type: "func",
|
361
|
+
buttonList: [
|
362
|
+
{
|
363
|
+
label: "编辑",
|
364
|
+
type: 'Edit',
|
365
|
+
permi: '',
|
366
|
+
options: {
|
367
|
+
icon: "el-icon-edit",
|
368
|
+
size: "mini",
|
369
|
+
type: "text",
|
370
|
+
}
|
371
|
+
},
|
372
|
+
{
|
373
|
+
label: "删除",
|
374
|
+
type: 'Delete',
|
375
|
+
permi: '',
|
376
|
+
options: {
|
377
|
+
icon: "el-icon-delete",
|
378
|
+
size: "mini",
|
379
|
+
type: "text",
|
380
|
+
}
|
381
|
+
},
|
382
|
+
],
|
383
|
+
},
|
384
|
+
],
|
385
|
+
},
|
386
|
+
};
|
387
|
+
|
388
|
+
export const DialogJson = {
|
389
|
+
type: 'Add',
|
390
|
+
title: "类",
|
391
|
+
options: {
|
392
|
+
width: "600px",
|
393
|
+
appendToBody: true,
|
394
|
+
destroyOnClose: true,
|
395
|
+
closeOnClickModal: false,
|
396
|
+
},
|
397
|
+
buttonList: [
|
398
|
+
{
|
399
|
+
label: "确定",
|
400
|
+
type: 'Ok',
|
401
|
+
permi: '',
|
402
|
+
options: {
|
403
|
+
type: "primary",
|
404
|
+
}
|
405
|
+
},
|
406
|
+
{
|
407
|
+
label: "取消",
|
408
|
+
type: 'Cancel',
|
409
|
+
permi: '',
|
410
|
+
options: {
|
411
|
+
type: "",
|
412
|
+
}
|
413
|
+
},
|
414
|
+
],
|
415
|
+
formJson: {
|
416
|
+
// 表单设置
|
417
|
+
formOption: {
|
418
|
+
inline: false,
|
419
|
+
labelWidth: "120px",
|
420
|
+
size: 'small',
|
421
|
+
},
|
422
|
+
// 表单项
|
423
|
+
formItemJson: [
|
424
|
+
// {
|
425
|
+
// label: "包编码",
|
426
|
+
// prop: "packageCode",
|
427
|
+
// type: "Select",
|
428
|
+
// rules: [{ required: true, message: "请选择包编码", trigger: "change" }],
|
429
|
+
// options: {
|
430
|
+
// clearable: true,
|
431
|
+
// placeholder: "请选择包编码",
|
432
|
+
// },
|
433
|
+
// option: [],
|
434
|
+
// },
|
435
|
+
{
|
436
|
+
label: "类中文名称",
|
437
|
+
prop: "classDispname",
|
438
|
+
type: "Input",
|
439
|
+
rules: [
|
440
|
+
{ required: true, message: '请输入类中文名称', trigger: 'blur' },
|
441
|
+
],
|
442
|
+
options: {
|
443
|
+
clearable: true,
|
444
|
+
placeholder: '请输入类中文名称',
|
445
|
+
}
|
446
|
+
},
|
447
|
+
{
|
448
|
+
label: "类英文名称",
|
449
|
+
prop: "className",
|
450
|
+
type: "Input",
|
451
|
+
rules: [
|
452
|
+
{ required: true, message: '请输入类英文名称', trigger: 'blur' },
|
453
|
+
{
|
454
|
+
required: true,
|
455
|
+
validator: (rule, value, callback) => {
|
456
|
+
const reg = /^[a-zA-Z]{1}\w*$/;
|
457
|
+
if (!reg.test(value)) {
|
458
|
+
callback(
|
459
|
+
new Error(
|
460
|
+
"请输入以字母(不区分大小写)、数字、下划线(_)随意组合的字符串"
|
461
|
+
)
|
462
|
+
);
|
463
|
+
}
|
464
|
+
callback();
|
465
|
+
},
|
466
|
+
trigger: ["blur"],
|
467
|
+
},
|
468
|
+
],
|
469
|
+
options: {
|
470
|
+
clearable: true,
|
471
|
+
placeholder: '请输入类英文名称',
|
472
|
+
}
|
473
|
+
},
|
474
|
+
{
|
475
|
+
label: "类类型",
|
476
|
+
prop: "classesType",
|
477
|
+
type: "Select",
|
478
|
+
rules: [{ required: true, message: "请选择类类型", trigger: "change" }],
|
479
|
+
options: {
|
480
|
+
clearable: true,
|
481
|
+
placeholder: "请选择类型",
|
482
|
+
},
|
483
|
+
option: [
|
484
|
+
{
|
485
|
+
value: '继承',
|
486
|
+
label: '继承',
|
487
|
+
},
|
488
|
+
{
|
489
|
+
value: '虚类',
|
490
|
+
label: '虚类',
|
491
|
+
},
|
492
|
+
{
|
493
|
+
value: '实体类',
|
494
|
+
label: '实体类',
|
495
|
+
},
|
496
|
+
],
|
497
|
+
},
|
498
|
+
{
|
499
|
+
label: "继承父类code",
|
500
|
+
prop: "classesExtends",
|
501
|
+
type: "Input",
|
502
|
+
rules: [
|
503
|
+
{ required: true, message: '请输入继承父类code', trigger: 'blur' },
|
504
|
+
],
|
505
|
+
options: {
|
506
|
+
clearable: true,
|
507
|
+
placeholder: '请输入继承父类code',
|
508
|
+
}
|
509
|
+
},
|
510
|
+
{
|
511
|
+
label: "访问类型",
|
512
|
+
prop: "accessType",
|
513
|
+
type: "Select",
|
514
|
+
rules: [{ required: true, message: "请选择访问类型", trigger: "change" }],
|
515
|
+
options: {
|
516
|
+
clearable: true,
|
517
|
+
placeholder: "请选择访问类型",
|
518
|
+
},
|
519
|
+
option: [
|
520
|
+
{
|
521
|
+
value: 'default',
|
522
|
+
label: 'default',
|
523
|
+
},
|
524
|
+
{
|
525
|
+
value: 'public',
|
526
|
+
label: 'public',
|
527
|
+
},
|
528
|
+
{
|
529
|
+
value: 'protected',
|
530
|
+
label: 'protected',
|
531
|
+
},
|
532
|
+
{
|
533
|
+
value: 'private',
|
534
|
+
label: 'private',
|
535
|
+
},
|
536
|
+
],
|
537
|
+
},
|
538
|
+
{
|
539
|
+
label: "实例存储表名称",
|
540
|
+
prop: "objTableName",
|
541
|
+
type: "Input",
|
542
|
+
rules: [
|
543
|
+
{ required: true, message: '请输入实例存储表名称', trigger: 'blur' },
|
544
|
+
],
|
545
|
+
options: {
|
546
|
+
clearable: true,
|
547
|
+
placeholder: '请输入实例存储表名称',
|
548
|
+
}
|
549
|
+
},
|
550
|
+
{
|
551
|
+
label: "视图样式",
|
552
|
+
prop: "viewStyle",
|
553
|
+
type: "Input",
|
554
|
+
rules: [
|
555
|
+
{ required: false, message: '请输入视图样式', trigger: 'blur' },
|
556
|
+
],
|
557
|
+
options: {
|
558
|
+
clearable: true,
|
559
|
+
placeholder: '请输入视图样式',
|
560
|
+
}
|
561
|
+
},
|
562
|
+
{
|
563
|
+
label: "备注",
|
564
|
+
prop: "remark",
|
565
|
+
type: "Input",
|
566
|
+
rules: [],
|
567
|
+
options: {
|
568
|
+
clearable: true,
|
569
|
+
placeholder: '请输入备注',
|
570
|
+
type: 'textarea',
|
571
|
+
row: 4
|
572
|
+
}
|
573
|
+
},
|
574
|
+
],
|
575
|
+
}
|
576
|
+
|
577
|
+
}`;
|
578
|
+
}
|
579
|
+
};
|
580
|
+
|
581
|
+
// 导入模板
|
582
|
+
var defaultConfig = {
|
583
|
+
// 是否命令行创建
|
584
|
+
isEnter: true,
|
585
|
+
// 文件名
|
586
|
+
name: 'genPageTable',
|
587
|
+
// 默认 view 目录下生成,如果需要指定父目录则写入 fatherFileName
|
588
|
+
path: 'dome',
|
589
|
+
// 子文件配置
|
590
|
+
child: [{
|
591
|
+
name: 'index.vue',
|
592
|
+
template: (params = {}) => {
|
593
|
+
return templateData.tablePageTemplate({
|
594
|
+
// 文件标题,替换模板
|
595
|
+
title: 'pageTable',
|
596
|
+
...params
|
597
|
+
});
|
598
|
+
},
|
599
|
+
templateConfig: {}
|
600
|
+
}, {
|
601
|
+
name: 'constants.js',
|
602
|
+
template: (params = {}) => {
|
603
|
+
return templateData.constantsTemplate({
|
604
|
+
// 文件标题,替换模板
|
605
|
+
title: 'pageTable',
|
606
|
+
...params
|
607
|
+
});
|
608
|
+
},
|
609
|
+
templateConfig: {
|
610
|
+
// 文件标题,替换模板
|
611
|
+
title: ''
|
612
|
+
}
|
613
|
+
}]
|
614
|
+
};
|
615
|
+
|
616
|
+
const __dirname = getDirname();
|
617
|
+
const resolve = (...file) => require$$0$1.resolve(__dirname, ...file);
|
618
|
+
|
619
|
+
// 模板配置
|
620
|
+
const globalConfig = await getGlobalConfig('genPageConfig');
|
621
|
+
if (globalConfig) {
|
622
|
+
errorLog('全局模板未配置,使用默认配置');
|
623
|
+
}
|
624
|
+
const config = globalConfig || defaultConfig;
|
625
|
+
|
626
|
+
// 生成文件
|
627
|
+
const generateFile = (path, data) => {
|
628
|
+
if (require$$0.existsSync(path)) {
|
629
|
+
errorLog(`${path}文件已存在`);
|
630
|
+
return;
|
631
|
+
}
|
632
|
+
require$$0.writeFileSync(path, data, 'utf8', err => {
|
633
|
+
if (err) {
|
634
|
+
errorLog(err.message);
|
635
|
+
reject(err);
|
636
|
+
} else {
|
637
|
+
resolve(true);
|
638
|
+
}
|
639
|
+
});
|
640
|
+
};
|
641
|
+
function dotExistDirectoryCreate(directory) {
|
642
|
+
return new Promise(resolve => {
|
643
|
+
mkdirs(directory, function () {
|
644
|
+
resolve(true);
|
645
|
+
});
|
646
|
+
});
|
647
|
+
}
|
648
|
+
// 递归创建目录
|
649
|
+
function mkdirs(directory, callback) {
|
650
|
+
var exists = require$$0.existsSync(directory);
|
651
|
+
if (exists) {
|
652
|
+
callback();
|
653
|
+
} else {
|
654
|
+
mkdirs(require$$0$1.dirname(directory), function () {
|
655
|
+
require$$0.mkdirSync(directory);
|
656
|
+
callback();
|
657
|
+
});
|
658
|
+
}
|
659
|
+
}
|
660
|
+
async function genPageProcess(enterName) {
|
661
|
+
// 组件名称
|
662
|
+
const pageName = !enterName ? config.name : enterName;
|
663
|
+
// Vue页面组件路径
|
664
|
+
const pathStr = !config.path ? `${process.env.PWD}/src/views` : `${process.env.PWD}/src/views/${config.path}`;
|
665
|
+
const pagePath = resolve(pathStr, pageName);
|
666
|
+
|
667
|
+
// 判断组件文件夹是否存在
|
668
|
+
const hasComponentExists = require$$0.existsSync(pagePath);
|
669
|
+
if (hasComponentExists) {
|
670
|
+
errorLog(`${pageName}页面已存在`);
|
671
|
+
if (pageName) {
|
672
|
+
process.stdin.emit('end');
|
673
|
+
}
|
674
|
+
return;
|
675
|
+
} else {
|
676
|
+
log(`正在生成${pageName}目录 ${pagePath}`);
|
677
|
+
await dotExistDirectoryCreate(pagePath);
|
678
|
+
}
|
679
|
+
try {
|
680
|
+
// // 获取组件名
|
681
|
+
// if (enterName.includes('/')) {
|
682
|
+
// const inputArr = enterName.split('/')
|
683
|
+
// pageName = inputArr[inputArr.length - 1]
|
684
|
+
// } else {
|
685
|
+
// pageName = enterName
|
686
|
+
// }
|
687
|
+
|
688
|
+
config.child.forEach(item => {
|
689
|
+
const filePath = resolve(pagePath, item.name);
|
690
|
+
log(`正在生成子文件${item.name} ${filePath}`);
|
691
|
+
generateFile(filePath, item.template({
|
692
|
+
name: pageName
|
693
|
+
}));
|
694
|
+
});
|
695
|
+
successLog('生成成功');
|
696
|
+
} catch (e) {
|
697
|
+
errorLog(e.message);
|
698
|
+
}
|
699
|
+
}
|
700
|
+
function genPage() {
|
701
|
+
if (!config.isEnter) {
|
702
|
+
genPageProcess();
|
703
|
+
} else {
|
704
|
+
log('请输入要生成的页面组件名称、会生成在 views/目录下');
|
705
|
+
process.stdin.on('data', async chunk => {
|
706
|
+
// 组件名称
|
707
|
+
const enterName = String(chunk).trim().toString();
|
708
|
+
genPageProcess(enterName);
|
709
|
+
process.stdin.emit('end');
|
710
|
+
});
|
711
|
+
process.stdin.on('end', () => {
|
712
|
+
log('exit');
|
713
|
+
process.exit();
|
714
|
+
});
|
715
|
+
}
|
716
|
+
}
|
717
|
+
genPage();
|