cloud-web-corejs 1.0.54-dev.757 → 1.0.54-dev.759

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.
@@ -1,655 +1,655 @@
1
- import {
2
- deepClone,
3
- copyToClipboard,
4
- generateId,
5
- getQueryParam,
6
- traverseAllWidgets,
7
- addWindowResizeHandler,
8
- } from "../../../../components/xform/utils/util";
9
- import i18n from "../../../../components/xform/utils/i18n";
10
- import { generateCode } from "../../../../components/xform/utils/code-generator";
11
- import { genSFC } from "../../../../components/xform/utils/sfc-generator";
12
- import loadBeautifier from "../../../../components/xform/utils/beautifierLoader";
13
- import { saveAs } from "file-saver";
14
- import axios from "axios";
15
-
16
- let modules = {};
17
- const baseRefUtil = {
18
- i18n,
19
- generateCode,
20
- genSFC,
21
- loadBeautifier,
22
- saveAs,
23
- axios,
24
- deepClone,
25
- copyToClipboard,
26
- generateId,
27
- getQueryParam,
28
- traverseAllWidgets,
29
- addWindowResizeHandler,
30
- };
31
-
32
- modules = {
33
- mixins: [baseRefUtil.i18n],
34
- props: {
35
- designer: Object,
36
- },
37
- inject: [
38
- "getDesignerConfig",
39
- "saveReportTemplate",
40
- "getReportTemplate",
41
- "getFormTemplateTableDTOs",
42
- "readonly",
43
- ],
44
- data() {
45
- return {
46
- designerConfig: this.getDesignerConfig(),
47
- showRender: true,
48
- toolbarWidth: 600,
49
- showPreviewDialogFlag: false,
50
- showImportJsonDialogFlag: false,
51
- showExportJsonDialogFlag: false,
52
- showExportCodeDialogFlag: false,
53
- showFormDataDialogFlag: false,
54
- showExportSFCDialogFlag: false,
55
- showNodeTreeDrawerFlag: false,
56
-
57
- nodeTreeData: [],
58
-
59
- testFunc: "",
60
- importTemplate: "",
61
- jsonContent: "",
62
- jsonRawContent: "",
63
-
64
- formDataJson: "",
65
- formDataRawJson: "",
66
-
67
- vueCode: "",
68
- htmlCode: "",
69
-
70
- sfcCode: "",
71
- sfcCodeV3: "",
72
-
73
- activeCodeTab: "vue",
74
- activeSFCTab: "vue2",
75
-
76
- testFormData: {},
77
- testOptionData: {},
78
-
79
- activeName: "first",
80
- formInsListFieldDTOs: [],
81
- vxeOption: {},
82
- formData: {},
83
- showFormConfigDialog: false,
84
- };
85
- },
86
- computed: {
87
- formJson() {
88
- return {
89
- // widgetList: this.designer.widgetList,
90
- // formConfig: this.designer.formConfig
91
-
92
- widgetList: baseRefUtil.deepClone(this.designer.widgetList),
93
- formConfig: baseRefUtil.deepClone(this.designer.formConfig),
94
- };
95
- },
96
-
97
- undoDisabled() {
98
- return !this.designer.undoEnabled();
99
- },
100
-
101
- redoDisabled() {
102
- return !this.designer.redoEnabled();
103
- },
104
-
105
- layoutType() {
106
- return this.designer.getLayoutType();
107
- },
108
- },
109
- watch: {
110
- "designer.widgetList": {
111
- deep: true,
112
- handler(val) {
113
- //console.log('test-----', val)
114
- //this.refreshNodeTree()
115
- },
116
- },
117
- },
118
- mounted() {
119
- let maxTBWidth = this.designerConfig.toolbarMaxWidth || 380;
120
- let minTBWidth = this.designerConfig.toolbarMinWidth || 300;
121
- let newTBWidth = window.innerWidth - 260 - 300 - 320 - 80;
122
- //this.toolbarWidth = newTBWidth >= maxTBWidth ? maxTBWidth : newTBWidth <= minTBWidth ? minTBWidth : newTBWidth;
123
- this.winResizeUnbind = baseRefUtil.addWindowResizeHandler(() => {
124
- this.$nextTick(() => {
125
- let newTBWidth2 = window.innerWidth - 260 - 300 - 320 - 80;
126
- //this.toolbarWidth = newTBWidth2 >= maxTBWidth ? maxTBWidth : newTBWidth2 <= minTBWidth ? minTBWidth :
127
- newTBWidth2;
128
- });
129
- });
130
- },
131
- beforeDestroy() {
132
- // window 级监听持有本实例,销毁时必须解绑,否则工具栏面板整树泄露
133
- if (this.winResizeUnbind) {
134
- this.winResizeUnbind();
135
- this.winResizeUnbind = null;
136
- }
137
- },
138
- methods: {
139
- showToolButton(configName) {
140
- if (this.designerConfig[configName] === undefined) {
141
- return true;
142
- }
143
-
144
- return !!this.designerConfig[configName];
145
- },
146
-
147
- buildTreeNodeOfWidget(widget, treeNode) {
148
- let curNode = {
149
- id: widget.id,
150
- label: widget.options.label || widget.type,
151
- //selectable: true,
152
- };
153
- treeNode.push(curNode);
154
-
155
- if (widget.category === undefined) {
156
- return;
157
- }
158
-
159
- curNode.children = [];
160
- if (widget.type === "grid") {
161
- widget.cols.map((col) => {
162
- let colNode = {
163
- id: col.id,
164
- label: col.options.name || widget.type,
165
- children: [],
166
- };
167
- curNode.children.push(colNode);
168
- col.widgetList.map((wChild) => {
169
- this.buildTreeNodeOfWidget(wChild, colNode.children);
170
- });
171
- });
172
- } else if (widget.type === "table") {
173
- //TODO: 需要考虑合并单元格!!
174
- widget.rows.map((row) => {
175
- let rowNode = {
176
- id: row.id,
177
- label: "table-row",
178
- selectable: false,
179
- children: [],
180
- };
181
- curNode.children.push(rowNode);
182
-
183
- row.cols.map((cell) => {
184
- if (!!cell.merged) {
185
- //跳过合并单元格!!
186
- return;
187
- }
188
-
189
- let rowChildren = rowNode.children;
190
- let cellNode = {
191
- id: cell.id,
192
- label: "table-cell",
193
- children: [],
194
- };
195
- rowChildren.push(cellNode);
196
-
197
- cell.widgetList.map((wChild) => {
198
- this.buildTreeNodeOfWidget(wChild, cellNode.children);
199
- });
200
- });
201
- });
202
- } else if (widget.type === "h5-table") {
203
- //TODO: 需要考虑合并单元格!!
204
- widget.rows.map((row) => {
205
- let rowNode = {
206
- id: row.id,
207
- label: "table-row",
208
- selectable: false,
209
- children: [],
210
- };
211
- curNode.children.push(rowNode);
212
-
213
- row.cols.map((cell) => {
214
- if (!!cell.merged) {
215
- //跳过合并单元格!!
216
- return;
217
- }
218
-
219
- let rowChildren = rowNode.children;
220
- let cellNode = {
221
- id: cell.id,
222
- label: "table-cell",
223
- children: [],
224
- };
225
- rowChildren.push(cellNode);
226
-
227
- cell.widgetList.map((wChild) => {
228
- this.buildTreeNodeOfWidget(wChild, cellNode.children);
229
- });
230
- });
231
- });
232
- } else if (widget.type === "tab") {
233
- widget.tabs.map((tab) => {
234
- let tabNode = {
235
- id: tab.id,
236
- label: tab.options.name || widget.type,
237
- selectable: false,
238
- children: [],
239
- };
240
- curNode.children.push(tabNode);
241
- tab.widgetList.map((wChild) => {
242
- this.buildTreeNodeOfWidget(wChild, tabNode.children);
243
- });
244
- });
245
- } else if (widget.type === "sub-form") {
246
- widget.widgetList.map((wChild) => {
247
- this.buildTreeNodeOfWidget(wChild, curNode.children);
248
- });
249
- } else if (widget.category === "container") {
250
- //自定义容器
251
- widget.widgetList.map((wChild) => {
252
- this.buildTreeNodeOfWidget(wChild, curNode.children);
253
- });
254
- }
255
- },
256
-
257
- refreshNodeTree() {
258
- this.nodeTreeData.length = 0;
259
- this.designer.widgetList.forEach((wItem) => {
260
- this.buildTreeNodeOfWidget(wItem, this.nodeTreeData);
261
- });
262
- },
263
-
264
- showNodeTreeDrawer() {
265
- this.refreshNodeTree();
266
- this.showNodeTreeDrawerFlag = true;
267
- this.$nextTick(() => {
268
- if (!!this.designer.selectedId) {
269
- //同步当前选中组件到节点树!!!
270
- this.$refs.nodeTree.setCurrentKey(this.designer.selectedId);
271
- }
272
- });
273
- },
274
-
275
- undoHistory() {
276
- this.designer.undoHistoryStep();
277
- },
278
-
279
- redoHistory() {
280
- this.designer.redoHistoryStep();
281
- },
282
-
283
- changeLayoutType(newType) {
284
- this.designer.changeLayoutType(newType);
285
- this.$emit("loadWidgets");
286
- },
287
-
288
- clearFormWidget() {
289
- this.designer.clearDesigner(),
290
- this.designer.formWidget.clearWidgetRefList(),
291
- this.designer.emitEvent("form-json-imported", []);
292
- this.$emit("loadWidgets");
293
- },
294
-
295
- previewForm() {
296
- this.reportTemplate = this.getReportTemplate();
297
- this.showPreviewDialogFlag = true;
298
- this.activeName = "first";
299
- },
300
-
301
- saveAsFile(fileContent, defaultFileName) {
302
- this.$prompt(
303
- this.i18nt("designer.hint.fileNameForSave"),
304
- this.i18nt("designer.hint.saveFileTitle"),
305
- {
306
- inputValue: defaultFileName,
307
- closeOnClickModal: false,
308
- inputPlaceholder: this.i18nt(
309
- "designer.hint.fileNameInputPlaceholder"
310
- ),
311
- }
312
- )
313
- .then(({ value }) => {
314
- if (!value) {
315
- value = defaultFileName;
316
- }
317
-
318
- if (baseRefUtil.getQueryParam("vscode") == 1) {
319
- this.vsSaveFile(value, fileContent);
320
- return;
321
- }
322
-
323
- const fileBlob = new Blob([fileContent], {
324
- type: "text/plain;charset=utf-8",
325
- });
326
- baseRefUtil.saveAs(fileBlob, value);
327
- })
328
- .catch(() => {
329
- //
330
- });
331
- },
332
-
333
- vsSaveFile(fileName, fileContent) {
334
- const msgObj = {
335
- cmd: "writeFile",
336
- data: {
337
- fileName,
338
- code: fileContent,
339
- },
340
- };
341
- window.parent.postMessage(msgObj, "*");
342
- },
343
-
344
- importJson() {
345
- this.importTemplate = JSON.stringify(
346
- this.designer.getImportTemplate(),
347
- null,
348
- " "
349
- );
350
- this.showImportJsonDialogFlag = true;
351
- },
352
- doJsonImport() {
353
- try {
354
- let importObj = JSON.parse(this.importTemplate);
355
- this.designer.handleImportJson(importObj);
356
- this.designer.loadFormJson(importObj);
357
-
358
- this.showImportJsonDialogFlag = false;
359
- this.$message.success(this.i18nt("designer.hint.importJsonSuccess"));
360
-
361
- this.designer.emitHistoryChange();
362
-
363
- this.designer.emitEvent("form-json-imported", []);
364
- } catch (ex) {
365
- this.$message.error(ex + "");
366
- }
367
- },
368
-
369
- exportJson() {
370
- let widgetList = baseRefUtil.deepClone(this.designer.widgetList);
371
- let formConfig = baseRefUtil.deepClone(this.designer.formConfig);
372
- let formCode = this.designer?.vueInstance?.reportTemplate?.formCode;
373
- if (formCode) {
374
- formConfig.formCode = formCode;
375
- }
376
- this.jsonContent = JSON.stringify(
377
- {
378
- widgetList,
379
- formConfig,
380
- },
381
- null,
382
- " "
383
- );
384
- this.jsonRawContent = JSON.stringify({
385
- widgetList,
386
- formConfig,
387
- });
388
- this.showExportJsonDialogFlag = true;
389
- },
390
-
391
- copyFormJson(e) {
392
- baseRefUtil.copyToClipboard(
393
- this.jsonRawContent,
394
- e,
395
- this.$message,
396
- this.i18nt("designer.hint.copyJsonSuccess"),
397
- this.i18nt("designer.hint.copyJsonFail")
398
- );
399
- },
400
-
401
- saveFormJson() {
402
- this.saveAsFile(
403
- this.jsonContent,
404
- `vform${baseRefUtil.generateId()}.json`
405
- );
406
- },
407
-
408
- exportCode() {
409
- this.vueCode = baseRefUtil.generateCode(this.formJson);
410
- this.htmlCode = baseRefUtil.generateCode(this.formJson, "html");
411
- this.showExportCodeDialogFlag = true;
412
- },
413
-
414
- copyVueCode(e) {
415
- baseRefUtil.copyToClipboard(
416
- this.vueCode,
417
- e,
418
- this.$message,
419
- this.i18nt("designer.hint.copyVueCodeSuccess"),
420
- this.i18nt("designer.hint.copyVueCodeFail")
421
- );
422
- },
423
-
424
- copyHtmlCode(e) {
425
- baseRefUtil.copyToClipboard(
426
- this.htmlCode,
427
- e,
428
- this.$message,
429
- this.i18nt("designer.hint.copyHtmlCodeSuccess"),
430
- this.i18nt("designer.hint.copyHtmlCodeFail")
431
- );
432
- },
433
-
434
- saveVueCode() {
435
- this.saveAsFile(this.vueCode, `vform${baseRefUtil.generateId()}.vue`);
436
- },
437
-
438
- saveHtmlCode() {
439
- this.saveAsFile(this.htmlCode, `vform${baseRefUtil.generateId()}.html`);
440
- },
441
-
442
- generateSFC() {
443
- baseRefUtil.loadBeautifier((beautifier) => {
444
- this.sfcCode = baseRefUtil.genSFC(
445
- this.designer.formConfig,
446
- this.designer.widgetList,
447
- beautifier
448
- );
449
- this.sfcCodeV3 = baseRefUtil.genSFC(
450
- this.designer.formConfig,
451
- this.designer.widgetList,
452
- beautifier,
453
- true
454
- );
455
- this.showExportSFCDialogFlag = true;
456
- });
457
- },
458
-
459
- copyV2SFC(e) {
460
- baseRefUtil.copyToClipboard(
461
- this.sfcCode,
462
- e,
463
- this.$message,
464
- this.i18nt("designer.hint.copySFCSuccess"),
465
- this.i18nt("designer.hint.copySFCFail")
466
- );
467
- },
468
-
469
- copyV3SFC(e) {
470
- baseRefUtil.copyToClipboard(
471
- this.sfcCodeV3,
472
- e,
473
- this.$message,
474
- this.i18nt("designer.hint.copySFCSuccess"),
475
- this.i18nt("designer.hint.copySFCFail")
476
- );
477
- },
478
-
479
- saveV2SFC() {
480
- this.saveAsFile(this.sfcCode, `vformV2-${baseRefUtil.generateId()}.vue`);
481
- },
482
-
483
- saveV3SFC() {
484
- this.saveAsFile(
485
- this.sfcCodeV3,
486
- `vformV3-${baseRefUtil.generateId()}.vue`
487
- );
488
- },
489
-
490
- getFormData() {
491
- this.$refs["preForm"]
492
- .getFormData()
493
- .then((formData) => {
494
- this.formDataJson = JSON.stringify(formData, null, " ");
495
- this.formDataRawJson = JSON.stringify(formData);
496
-
497
- this.showFormDataDialogFlag = true;
498
- })
499
- .catch((error) => {
500
- this.$message.error(error);
501
- });
502
- },
503
-
504
- copyFormDataJson(e) {
505
- baseRefUtil.copyToClipboard(
506
- this.formDataRawJson,
507
- e,
508
- this.$message,
509
- this.i18nt("designer.hint.copyJsonSuccess"),
510
- this.i18nt("designer.hint.copyJsonFail")
511
- );
512
- },
513
-
514
- saveFormData() {
515
- this.saveAsFile(
516
- this.htmlCode,
517
- `formData${baseRefUtil.generateId()}.json`
518
- );
519
- },
520
-
521
- resetForm() {
522
- this.$refs["preForm"].resetForm();
523
- },
524
-
525
- setFormDisabled() {
526
- this.$refs["preForm"].disableForm();
527
- },
528
-
529
- setFormEnabled() {
530
- this.$refs["preForm"].enableForm();
531
- },
532
-
533
- printFormJson() {
534
- let tmpFS = {
535
- widgetList: baseRefUtil.deepClone(this.designer.widgetList),
536
- formConfig: baseRefUtil.deepClone(this.designer.formConfig),
537
- };
538
-
539
- console.log(tmpFS);
540
- },
541
-
542
- testValidate() {
543
- console.log("test===", this.$refs["preForm"].validateForm());
544
- },
545
-
546
- testSetFormData() {
547
- // let fData = {
548
- // 'fuTest': [
549
- // {
550
- // name: '上传文件测试.xlsx',
551
- // url: 'https://www.vform666.com/123.xlsx'
552
- // }
553
- // ]
554
- // }
555
- // this.$refs['preForm'].setFormData(fData)
556
-
557
- let nfData = {
558
- checkbox45524: [1, 2],
559
- };
560
- this.$refs["preForm"].setFormData(nfData);
561
- },
562
-
563
- handleFormChange(fieldName, newValue, oldValue, formModel) {
564
- /*
565
- console.log('---formChange start---')
566
- console.log('fieldName', fieldName)
567
- console.log('newValue', newValue)
568
- console.log('oldValue', oldValue)
569
- console.log('formModel', formModel)
570
- console.log('---formChange end---')
571
- */
572
- },
573
-
574
- testOnAppendButtonClick(clickedWidget) {
575
- console.log("test", clickedWidget);
576
- },
577
-
578
- testOnButtonClick(button) {
579
- console.log("test", button);
580
- },
581
-
582
- findWidgetById(wId) {
583
- let foundW = null;
584
- baseRefUtil.traverseAllWidgets(this.designer.widgetList, (w) => {
585
- if (w.id === wId) {
586
- foundW = w;
587
- }
588
- });
589
-
590
- return foundW;
591
- },
592
-
593
- onNodeTreeClick(nodeData, node, nodeEl) {
594
- //console.log('test', JSON.stringify(nodeData))
595
-
596
- if (nodeData.selectable !== undefined && !nodeData.selectable) {
597
- this.$message.info(
598
- this.i18nt("designer.hint.currentNodeCannotBeSelected")
599
- );
600
- } else {
601
- const selectedId = nodeData.id;
602
- const foundW = this.findWidgetById(selectedId);
603
- if (!!foundW) {
604
- this.designer.setSelected(foundW);
605
- }
606
- }
607
- },
608
- initSearchCondition() {
609
- let formConfig = this.designer.formConfig;
610
- let gridConfig = formConfig.gridConfig || {};
611
- let searchFields = gridConfig.searchFields || [];
612
- searchFields = searchFields.filter((item) => {
613
- return !!item.prop && !!item.label;
614
- });
615
- this.searchFields = searchFields;
616
- },
617
- createColumns() {
618
- let formConfig = this.designer.formConfig;
619
- let gridConfig = formConfig.gridConfig || {};
620
- let tableColumns = gridConfig.tableColumns || [];
621
- if (tableColumns.length) {
622
- return tableColumns.map((row, index) => {
623
- let column = {
624
- title: row.label,
625
- field: row.prop,
626
- width: 150,
627
- };
628
- if (index === 0) {
629
- column.fixed = "left";
630
- }
631
- return column;
632
- });
633
- } else {
634
- let formTemplateTableDTOs = this.getFormTemplateTableDTOs();
635
- let formTemplateTableDTO = formTemplateTableDTOs.find(
636
- (item) => item.tableType == 0
637
- );
638
- let formInsListFieldDTOs = [];
639
- if (formTemplateTableDTO) {
640
- formInsListFieldDTOs =
641
- formTemplateTableDTO.formTemplateFieldDTOs || [];
642
- }
643
- return formInsListFieldDTOs.map((row) => {
644
- return {
645
- title: row.fieldDesc,
646
- field: row.fieldName,
647
- width: 150,
648
- };
649
- });
650
- }
651
- },
652
- },
653
- };
654
-
655
- export default modules;
1
+ import {
2
+ deepClone,
3
+ copyToClipboard,
4
+ generateId,
5
+ getQueryParam,
6
+ traverseAllWidgets,
7
+ addWindowResizeHandler,
8
+ } from "../../../../components/xform/utils/util";
9
+ import i18n from "../../../../components/xform/utils/i18n";
10
+ import { generateCode } from "../../../../components/xform/utils/code-generator";
11
+ import { genSFC } from "../../../../components/xform/utils/sfc-generator";
12
+ import loadBeautifier from "../../../../components/xform/utils/beautifierLoader";
13
+ import { saveAs } from "file-saver";
14
+ import axios from "axios";
15
+
16
+ let modules = {};
17
+ const baseRefUtil = {
18
+ i18n,
19
+ generateCode,
20
+ genSFC,
21
+ loadBeautifier,
22
+ saveAs,
23
+ axios,
24
+ deepClone,
25
+ copyToClipboard,
26
+ generateId,
27
+ getQueryParam,
28
+ traverseAllWidgets,
29
+ addWindowResizeHandler,
30
+ };
31
+
32
+ modules = {
33
+ mixins: [baseRefUtil.i18n],
34
+ props: {
35
+ designer: Object,
36
+ },
37
+ inject: [
38
+ "getDesignerConfig",
39
+ "saveReportTemplate",
40
+ "getReportTemplate",
41
+ "getFormTemplateTableDTOs",
42
+ "readonly",
43
+ ],
44
+ data() {
45
+ return {
46
+ designerConfig: this.getDesignerConfig(),
47
+ showRender: true,
48
+ toolbarWidth: 600,
49
+ showPreviewDialogFlag: false,
50
+ showImportJsonDialogFlag: false,
51
+ showExportJsonDialogFlag: false,
52
+ showExportCodeDialogFlag: false,
53
+ showFormDataDialogFlag: false,
54
+ showExportSFCDialogFlag: false,
55
+ showNodeTreeDrawerFlag: false,
56
+
57
+ nodeTreeData: [],
58
+
59
+ testFunc: "",
60
+ importTemplate: "",
61
+ jsonContent: "",
62
+ jsonRawContent: "",
63
+
64
+ formDataJson: "",
65
+ formDataRawJson: "",
66
+
67
+ vueCode: "",
68
+ htmlCode: "",
69
+
70
+ sfcCode: "",
71
+ sfcCodeV3: "",
72
+
73
+ activeCodeTab: "vue",
74
+ activeSFCTab: "vue2",
75
+
76
+ testFormData: {},
77
+ testOptionData: {},
78
+
79
+ activeName: "first",
80
+ formInsListFieldDTOs: [],
81
+ vxeOption: {},
82
+ formData: {},
83
+ showFormConfigDialog: false,
84
+ };
85
+ },
86
+ computed: {
87
+ formJson() {
88
+ return {
89
+ // widgetList: this.designer.widgetList,
90
+ // formConfig: this.designer.formConfig
91
+
92
+ widgetList: baseRefUtil.deepClone(this.designer.widgetList),
93
+ formConfig: baseRefUtil.deepClone(this.designer.formConfig),
94
+ };
95
+ },
96
+
97
+ undoDisabled() {
98
+ return !this.designer.undoEnabled();
99
+ },
100
+
101
+ redoDisabled() {
102
+ return !this.designer.redoEnabled();
103
+ },
104
+
105
+ layoutType() {
106
+ return this.designer.getLayoutType();
107
+ },
108
+ },
109
+ watch: {
110
+ "designer.widgetList": {
111
+ deep: true,
112
+ handler(val) {
113
+ //console.log('test-----', val)
114
+ //this.refreshNodeTree()
115
+ },
116
+ },
117
+ },
118
+ mounted() {
119
+ let maxTBWidth = this.designerConfig.toolbarMaxWidth || 380;
120
+ let minTBWidth = this.designerConfig.toolbarMinWidth || 300;
121
+ let newTBWidth = window.innerWidth - 260 - 300 - 320 - 80;
122
+ //this.toolbarWidth = newTBWidth >= maxTBWidth ? maxTBWidth : newTBWidth <= minTBWidth ? minTBWidth : newTBWidth;
123
+ this.winResizeUnbind = baseRefUtil.addWindowResizeHandler(() => {
124
+ this.$nextTick(() => {
125
+ let newTBWidth2 = window.innerWidth - 260 - 300 - 320 - 80;
126
+ //this.toolbarWidth = newTBWidth2 >= maxTBWidth ? maxTBWidth : newTBWidth2 <= minTBWidth ? minTBWidth :
127
+ newTBWidth2;
128
+ });
129
+ });
130
+ },
131
+ beforeDestroy() {
132
+ // window 级监听持有本实例,销毁时必须解绑,否则工具栏面板整树泄露
133
+ if (this.winResizeUnbind) {
134
+ this.winResizeUnbind();
135
+ this.winResizeUnbind = null;
136
+ }
137
+ },
138
+ methods: {
139
+ showToolButton(configName) {
140
+ if (this.designerConfig[configName] === undefined) {
141
+ return true;
142
+ }
143
+
144
+ return !!this.designerConfig[configName];
145
+ },
146
+
147
+ buildTreeNodeOfWidget(widget, treeNode) {
148
+ let curNode = {
149
+ id: widget.id,
150
+ label: widget.options.label || widget.type,
151
+ //selectable: true,
152
+ };
153
+ treeNode.push(curNode);
154
+
155
+ if (widget.category === undefined) {
156
+ return;
157
+ }
158
+
159
+ curNode.children = [];
160
+ if (widget.type === "grid") {
161
+ widget.cols.map((col) => {
162
+ let colNode = {
163
+ id: col.id,
164
+ label: col.options.name || widget.type,
165
+ children: [],
166
+ };
167
+ curNode.children.push(colNode);
168
+ col.widgetList.map((wChild) => {
169
+ this.buildTreeNodeOfWidget(wChild, colNode.children);
170
+ });
171
+ });
172
+ } else if (widget.type === "table") {
173
+ //TODO: 需要考虑合并单元格!!
174
+ widget.rows.map((row) => {
175
+ let rowNode = {
176
+ id: row.id,
177
+ label: "table-row",
178
+ selectable: false,
179
+ children: [],
180
+ };
181
+ curNode.children.push(rowNode);
182
+
183
+ row.cols.map((cell) => {
184
+ if (!!cell.merged) {
185
+ //跳过合并单元格!!
186
+ return;
187
+ }
188
+
189
+ let rowChildren = rowNode.children;
190
+ let cellNode = {
191
+ id: cell.id,
192
+ label: "table-cell",
193
+ children: [],
194
+ };
195
+ rowChildren.push(cellNode);
196
+
197
+ cell.widgetList.map((wChild) => {
198
+ this.buildTreeNodeOfWidget(wChild, cellNode.children);
199
+ });
200
+ });
201
+ });
202
+ } else if (widget.type === "h5-table") {
203
+ //TODO: 需要考虑合并单元格!!
204
+ widget.rows.map((row) => {
205
+ let rowNode = {
206
+ id: row.id,
207
+ label: "table-row",
208
+ selectable: false,
209
+ children: [],
210
+ };
211
+ curNode.children.push(rowNode);
212
+
213
+ row.cols.map((cell) => {
214
+ if (!!cell.merged) {
215
+ //跳过合并单元格!!
216
+ return;
217
+ }
218
+
219
+ let rowChildren = rowNode.children;
220
+ let cellNode = {
221
+ id: cell.id,
222
+ label: "table-cell",
223
+ children: [],
224
+ };
225
+ rowChildren.push(cellNode);
226
+
227
+ cell.widgetList.map((wChild) => {
228
+ this.buildTreeNodeOfWidget(wChild, cellNode.children);
229
+ });
230
+ });
231
+ });
232
+ } else if (widget.type === "tab") {
233
+ widget.tabs.map((tab) => {
234
+ let tabNode = {
235
+ id: tab.id,
236
+ label: tab.options.name || widget.type,
237
+ selectable: false,
238
+ children: [],
239
+ };
240
+ curNode.children.push(tabNode);
241
+ tab.widgetList.map((wChild) => {
242
+ this.buildTreeNodeOfWidget(wChild, tabNode.children);
243
+ });
244
+ });
245
+ } else if (widget.type === "sub-form") {
246
+ widget.widgetList.map((wChild) => {
247
+ this.buildTreeNodeOfWidget(wChild, curNode.children);
248
+ });
249
+ } else if (widget.category === "container") {
250
+ //自定义容器
251
+ widget.widgetList.map((wChild) => {
252
+ this.buildTreeNodeOfWidget(wChild, curNode.children);
253
+ });
254
+ }
255
+ },
256
+
257
+ refreshNodeTree() {
258
+ this.nodeTreeData.length = 0;
259
+ this.designer.widgetList.forEach((wItem) => {
260
+ this.buildTreeNodeOfWidget(wItem, this.nodeTreeData);
261
+ });
262
+ },
263
+
264
+ showNodeTreeDrawer() {
265
+ this.refreshNodeTree();
266
+ this.showNodeTreeDrawerFlag = true;
267
+ this.$nextTick(() => {
268
+ if (!!this.designer.selectedId) {
269
+ //同步当前选中组件到节点树!!!
270
+ this.$refs.nodeTree.setCurrentKey(this.designer.selectedId);
271
+ }
272
+ });
273
+ },
274
+
275
+ undoHistory() {
276
+ this.designer.undoHistoryStep();
277
+ },
278
+
279
+ redoHistory() {
280
+ this.designer.redoHistoryStep();
281
+ },
282
+
283
+ changeLayoutType(newType) {
284
+ this.designer.changeLayoutType(newType);
285
+ this.$emit("loadWidgets");
286
+ },
287
+
288
+ clearFormWidget() {
289
+ this.designer.clearDesigner(),
290
+ this.designer.formWidget.clearWidgetRefList(),
291
+ this.designer.emitEvent("form-json-imported", []);
292
+ this.$emit("loadWidgets");
293
+ },
294
+
295
+ previewForm() {
296
+ this.reportTemplate = this.getReportTemplate();
297
+ this.showPreviewDialogFlag = true;
298
+ this.activeName = "first";
299
+ },
300
+
301
+ saveAsFile(fileContent, defaultFileName) {
302
+ this.$prompt(
303
+ this.i18nt("designer.hint.fileNameForSave"),
304
+ this.i18nt("designer.hint.saveFileTitle"),
305
+ {
306
+ inputValue: defaultFileName,
307
+ closeOnClickModal: false,
308
+ inputPlaceholder: this.i18nt(
309
+ "designer.hint.fileNameInputPlaceholder"
310
+ ),
311
+ }
312
+ )
313
+ .then(({ value }) => {
314
+ if (!value) {
315
+ value = defaultFileName;
316
+ }
317
+
318
+ if (baseRefUtil.getQueryParam("vscode") == 1) {
319
+ this.vsSaveFile(value, fileContent);
320
+ return;
321
+ }
322
+
323
+ const fileBlob = new Blob([fileContent], {
324
+ type: "text/plain;charset=utf-8",
325
+ });
326
+ baseRefUtil.saveAs(fileBlob, value);
327
+ })
328
+ .catch(() => {
329
+ //
330
+ });
331
+ },
332
+
333
+ vsSaveFile(fileName, fileContent) {
334
+ const msgObj = {
335
+ cmd: "writeFile",
336
+ data: {
337
+ fileName,
338
+ code: fileContent,
339
+ },
340
+ };
341
+ window.parent.postMessage(msgObj, "*");
342
+ },
343
+
344
+ importJson() {
345
+ this.importTemplate = JSON.stringify(
346
+ this.designer.getImportTemplate(),
347
+ null,
348
+ " "
349
+ );
350
+ this.showImportJsonDialogFlag = true;
351
+ },
352
+ doJsonImport() {
353
+ try {
354
+ let importObj = JSON.parse(this.importTemplate);
355
+ this.designer.handleImportJson(importObj);
356
+ this.designer.loadFormJson(importObj);
357
+
358
+ this.showImportJsonDialogFlag = false;
359
+ this.$message.success(this.i18nt("designer.hint.importJsonSuccess"));
360
+
361
+ this.designer.emitHistoryChange();
362
+
363
+ this.designer.emitEvent("form-json-imported", []);
364
+ } catch (ex) {
365
+ this.$message.error(ex + "");
366
+ }
367
+ },
368
+
369
+ exportJson() {
370
+ let widgetList = baseRefUtil.deepClone(this.designer.widgetList);
371
+ let formConfig = baseRefUtil.deepClone(this.designer.formConfig);
372
+ let formCode = this.designer?.vueInstance?.reportTemplate?.formCode;
373
+ if (formCode) {
374
+ formConfig.formCode = formCode;
375
+ }
376
+ this.jsonContent = JSON.stringify(
377
+ {
378
+ widgetList,
379
+ formConfig,
380
+ },
381
+ null,
382
+ " "
383
+ );
384
+ this.jsonRawContent = JSON.stringify({
385
+ widgetList,
386
+ formConfig,
387
+ });
388
+ this.showExportJsonDialogFlag = true;
389
+ },
390
+
391
+ copyFormJson(e) {
392
+ baseRefUtil.copyToClipboard(
393
+ this.jsonRawContent,
394
+ e,
395
+ this.$message,
396
+ this.i18nt("designer.hint.copyJsonSuccess"),
397
+ this.i18nt("designer.hint.copyJsonFail")
398
+ );
399
+ },
400
+
401
+ saveFormJson() {
402
+ this.saveAsFile(
403
+ this.jsonContent,
404
+ `vform${baseRefUtil.generateId()}.json`
405
+ );
406
+ },
407
+
408
+ exportCode() {
409
+ this.vueCode = baseRefUtil.generateCode(this.formJson);
410
+ this.htmlCode = baseRefUtil.generateCode(this.formJson, "html");
411
+ this.showExportCodeDialogFlag = true;
412
+ },
413
+
414
+ copyVueCode(e) {
415
+ baseRefUtil.copyToClipboard(
416
+ this.vueCode,
417
+ e,
418
+ this.$message,
419
+ this.i18nt("designer.hint.copyVueCodeSuccess"),
420
+ this.i18nt("designer.hint.copyVueCodeFail")
421
+ );
422
+ },
423
+
424
+ copyHtmlCode(e) {
425
+ baseRefUtil.copyToClipboard(
426
+ this.htmlCode,
427
+ e,
428
+ this.$message,
429
+ this.i18nt("designer.hint.copyHtmlCodeSuccess"),
430
+ this.i18nt("designer.hint.copyHtmlCodeFail")
431
+ );
432
+ },
433
+
434
+ saveVueCode() {
435
+ this.saveAsFile(this.vueCode, `vform${baseRefUtil.generateId()}.vue`);
436
+ },
437
+
438
+ saveHtmlCode() {
439
+ this.saveAsFile(this.htmlCode, `vform${baseRefUtil.generateId()}.html`);
440
+ },
441
+
442
+ generateSFC() {
443
+ baseRefUtil.loadBeautifier((beautifier) => {
444
+ this.sfcCode = baseRefUtil.genSFC(
445
+ this.designer.formConfig,
446
+ this.designer.widgetList,
447
+ beautifier
448
+ );
449
+ this.sfcCodeV3 = baseRefUtil.genSFC(
450
+ this.designer.formConfig,
451
+ this.designer.widgetList,
452
+ beautifier,
453
+ true
454
+ );
455
+ this.showExportSFCDialogFlag = true;
456
+ });
457
+ },
458
+
459
+ copyV2SFC(e) {
460
+ baseRefUtil.copyToClipboard(
461
+ this.sfcCode,
462
+ e,
463
+ this.$message,
464
+ this.i18nt("designer.hint.copySFCSuccess"),
465
+ this.i18nt("designer.hint.copySFCFail")
466
+ );
467
+ },
468
+
469
+ copyV3SFC(e) {
470
+ baseRefUtil.copyToClipboard(
471
+ this.sfcCodeV3,
472
+ e,
473
+ this.$message,
474
+ this.i18nt("designer.hint.copySFCSuccess"),
475
+ this.i18nt("designer.hint.copySFCFail")
476
+ );
477
+ },
478
+
479
+ saveV2SFC() {
480
+ this.saveAsFile(this.sfcCode, `vformV2-${baseRefUtil.generateId()}.vue`);
481
+ },
482
+
483
+ saveV3SFC() {
484
+ this.saveAsFile(
485
+ this.sfcCodeV3,
486
+ `vformV3-${baseRefUtil.generateId()}.vue`
487
+ );
488
+ },
489
+
490
+ getFormData() {
491
+ this.$refs["preForm"]
492
+ .getFormData()
493
+ .then((formData) => {
494
+ this.formDataJson = JSON.stringify(formData, null, " ");
495
+ this.formDataRawJson = JSON.stringify(formData);
496
+
497
+ this.showFormDataDialogFlag = true;
498
+ })
499
+ .catch((error) => {
500
+ this.$message.error(error);
501
+ });
502
+ },
503
+
504
+ copyFormDataJson(e) {
505
+ baseRefUtil.copyToClipboard(
506
+ this.formDataRawJson,
507
+ e,
508
+ this.$message,
509
+ this.i18nt("designer.hint.copyJsonSuccess"),
510
+ this.i18nt("designer.hint.copyJsonFail")
511
+ );
512
+ },
513
+
514
+ saveFormData() {
515
+ this.saveAsFile(
516
+ this.htmlCode,
517
+ `formData${baseRefUtil.generateId()}.json`
518
+ );
519
+ },
520
+
521
+ resetForm() {
522
+ this.$refs["preForm"].resetForm();
523
+ },
524
+
525
+ setFormDisabled() {
526
+ this.$refs["preForm"].disableForm();
527
+ },
528
+
529
+ setFormEnabled() {
530
+ this.$refs["preForm"].enableForm();
531
+ },
532
+
533
+ printFormJson() {
534
+ let tmpFS = {
535
+ widgetList: baseRefUtil.deepClone(this.designer.widgetList),
536
+ formConfig: baseRefUtil.deepClone(this.designer.formConfig),
537
+ };
538
+
539
+ console.log(tmpFS);
540
+ },
541
+
542
+ testValidate() {
543
+ console.log("test===", this.$refs["preForm"].validateForm());
544
+ },
545
+
546
+ testSetFormData() {
547
+ // let fData = {
548
+ // 'fuTest': [
549
+ // {
550
+ // name: '上传文件测试.xlsx',
551
+ // url: 'https://www.vform666.com/123.xlsx'
552
+ // }
553
+ // ]
554
+ // }
555
+ // this.$refs['preForm'].setFormData(fData)
556
+
557
+ let nfData = {
558
+ checkbox45524: [1, 2],
559
+ };
560
+ this.$refs["preForm"].setFormData(nfData);
561
+ },
562
+
563
+ handleFormChange(fieldName, newValue, oldValue, formModel) {
564
+ /*
565
+ console.log('---formChange start---')
566
+ console.log('fieldName', fieldName)
567
+ console.log('newValue', newValue)
568
+ console.log('oldValue', oldValue)
569
+ console.log('formModel', formModel)
570
+ console.log('---formChange end---')
571
+ */
572
+ },
573
+
574
+ testOnAppendButtonClick(clickedWidget) {
575
+ console.log("test", clickedWidget);
576
+ },
577
+
578
+ testOnButtonClick(button) {
579
+ console.log("test", button);
580
+ },
581
+
582
+ findWidgetById(wId) {
583
+ let foundW = null;
584
+ baseRefUtil.traverseAllWidgets(this.designer.widgetList, (w) => {
585
+ if (w.id === wId) {
586
+ foundW = w;
587
+ }
588
+ });
589
+
590
+ return foundW;
591
+ },
592
+
593
+ onNodeTreeClick(nodeData, node, nodeEl) {
594
+ //console.log('test', JSON.stringify(nodeData))
595
+
596
+ if (nodeData.selectable !== undefined && !nodeData.selectable) {
597
+ this.$message.info(
598
+ this.i18nt("designer.hint.currentNodeCannotBeSelected")
599
+ );
600
+ } else {
601
+ const selectedId = nodeData.id;
602
+ const foundW = this.findWidgetById(selectedId);
603
+ if (!!foundW) {
604
+ this.designer.setSelected(foundW);
605
+ }
606
+ }
607
+ },
608
+ initSearchCondition() {
609
+ let formConfig = this.designer.formConfig;
610
+ let gridConfig = formConfig.gridConfig || {};
611
+ let searchFields = gridConfig.searchFields || [];
612
+ searchFields = searchFields.filter((item) => {
613
+ return !!item.prop && !!item.label;
614
+ });
615
+ this.searchFields = searchFields;
616
+ },
617
+ createColumns() {
618
+ let formConfig = this.designer.formConfig;
619
+ let gridConfig = formConfig.gridConfig || {};
620
+ let tableColumns = gridConfig.tableColumns || [];
621
+ if (tableColumns.length) {
622
+ return tableColumns.map((row, index) => {
623
+ let column = {
624
+ title: row.label,
625
+ field: row.prop,
626
+ width: 150,
627
+ };
628
+ if (index === 0) {
629
+ column.fixed = "left";
630
+ }
631
+ return column;
632
+ });
633
+ } else {
634
+ let formTemplateTableDTOs = this.getFormTemplateTableDTOs();
635
+ let formTemplateTableDTO = formTemplateTableDTOs.find(
636
+ (item) => item.tableType == 0
637
+ );
638
+ let formInsListFieldDTOs = [];
639
+ if (formTemplateTableDTO) {
640
+ formInsListFieldDTOs =
641
+ formTemplateTableDTO.formTemplateFieldDTOs || [];
642
+ }
643
+ return formInsListFieldDTOs.map((row) => {
644
+ return {
645
+ title: row.fieldDesc,
646
+ field: row.fieldName,
647
+ width: 150,
648
+ };
649
+ });
650
+ }
651
+ },
652
+ },
653
+ };
654
+
655
+ export default modules;