forked from sahadev/vue-component-creater-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_vue3.diff
1847 lines (1758 loc) · 63.8 KB
/
master_vue3.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/package.json b/package.json
index 4d30ebf..481c92d 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,8 @@
],
"main": "./dist/vcc.umd.min.js",
"scripts": {
- "serve": "vue-cli-service serve --open --port 8008",
+ "dev": "vite --port 8008",
+ "serve": "vite --port 8008",
"build:release": "vue-cli-service build",
"build": "vue-cli-service build --report --target lib --name vcc './src/components-v2/VCC.vue' && node ./src/script/distClear.js",
"build:win": "vue-cli-service build --report --target lib --name vcc ./src/components-v2/VCC.vue && node ./src/script/distClear.js",
@@ -21,13 +22,16 @@
"debugParser": "node ./src/test/parserJsCode.js"
},
"dependencies": {
- "ant-design-vue": "^1.7.2",
+ "@element-plus/icons": "0.0.11",
+ "@vitejs/plugin-vue": "^1.10.0",
+ "@vue/compiler-sfc": "^3.2.22",
"axios": "^0.21.4",
+ "codemirror-editor-vue3": "^0.2.4",
"copy-to-clipboard": "^3.3.1",
- "crypto-random-string": "^3.3.0",
+ "crypto-random-string": "^3.3.1",
"css": "^3.0.0",
+ "element-plus": "^1.2.0-beta.3",
"css-scoped": "^1.0.0",
- "element-ui": "^2.15.6",
"escodegen": "^2.0.0",
"espree": "^7.3.0",
"eventemitter3": "^4.0.7",
@@ -35,16 +39,17 @@
"fs-extra": "^9.0.1",
"glob": "^7.1.6",
"keymaster": "^1.6.2",
- "lodash": "^4.17.20",
+ "lodash-es": "^4.17.21",
+ "nanoid": "^3.1.30",
"prettier": "^2.4.0",
- "prismjs": "^1.20.0",
"split.js": "^1.6.2",
- "stringify-object": "^3.3.0",
"vant": "^2.10.7",
- "vue": "^2.6.14",
- "vue-codemirror": "^4.0.6",
- "vue-github-button": "^1.3.0",
- "vue-nestable": "^2.6.0"
+ "vite": "^2.6.14",
+ "vue": "^3.2.22",
+ "vuedraggable": "^4.1.0",
+ "vuex": "^4.0.2",
+ "vue-template-compiler": "^2.6.14",
+ "vue-github-button": "^1.3.0"
},
"devDependencies": {
"@babel/generator": "^7.11.6",
@@ -60,7 +65,8 @@
"lint-staged": "^9.5.0",
"sass": "^1.25.0",
"sass-loader": "^8.0.2",
- "vue-template-compiler": "^2.6.14"
+ "is-obj": "^3.0.0",
+ "is-regexp": "^3.0.0"
},
"eslintConfig": {
"root": true,
diff --git a/public/index.html b/public/index.html
index 851ae63..2d5bb51 100644
--- a/public/index.html
+++ b/public/index.html
@@ -11,7 +11,7 @@
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
- <div id="app"></div>
+ <div id="app" style="height:100%;"></div>
<!-- built files will be auto injected -->
</body>
</html>
diff --git a/src/App.vue b/src/App.vue
index 272d6ee..7122e26 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -3,12 +3,13 @@
</template>
<script>
+import { defineAsyncComponent } from 'vue'
// 以这样一段结构初始化VCC组件
const initCodeStr = '{"template":{"lc_id":"root","__children":[{"div":{"class":"container","style":"min-height: 100%; padding-bottom: 100px;","lc_id":"container","__text__":"Hello,欢迎使用LCG,请往此区域拖拽组件","__children":[{"el-button":{"lc-mark":"","type":"danger","lc_id":"COAAYXizyI","__children":[],"__text__":"危险按钮","@click":"onButtonClick","size":"small"}}]}}]}}'
export default {
components: {
- vcc: () => import('./components-v2/VCC.vue'),
+ vcc: defineAsyncComponent(() => import('./components-v2/VCC.vue')),
},
data() {
return {
diff --git a/src/components-v2/ToolsBar.vue b/src/components-v2/ToolsBar.vue
index 2e6ea8f..d9168a3 100644
--- a/src/components-v2/ToolsBar.vue
+++ b/src/components-v2/ToolsBar.vue
@@ -25,8 +25,8 @@
Structure</el-link>
</el-col>
<el-col :span="3">
- <github-button href="https://github.com/sahadev/vue-component-creater-ui" data-icon="octicon-star"
- data-show-count="true" aria-label="Star sahadev/vue-component-creater-ui on GitHub">Star</github-button>
+ <a class="github-button" href="https://github.com/sahadev/vue-component-creater-ui" data-icon="octicon-star"
+ data-show-count="true" aria-label="Star sahadev/vue-component-creater-ui on GitHub">Star</a>
</el-col>
</el-row>
@@ -47,11 +47,9 @@
</template>
<script>
-import GithubButton from 'vue-github-button'
-
export default {
props: [],
- components: { GithubButton },
+ components: { },
data() {
return {
previewMode: false,
@@ -85,6 +83,10 @@ export default {
onEditModeChange() {
this.editMode = !this.editMode;
this.$emit('onEditModeChange', this.editMode);
+
+ setTimeout(() => {
+ this.editMode = true;
+ }, 500);
}
},
fillter: {},
@@ -103,9 +105,6 @@ export default {
border-radius: 0px;
align-content: center;
border-bottom: 1px solid #f0f0f0;
- > * {
- margin-right: 5px;
- }
}
.edit {
diff --git a/src/components-v2/VCC.vue b/src/components-v2/VCC.vue
index eee0b81..c867402 100644
--- a/src/components-v2/VCC.vue
+++ b/src/components-v2/VCC.vue
@@ -16,8 +16,7 @@
</div>
</div>
<attribute-input :enableRemoveButton="true" class="attribute" @save="onSaveAttr" @remove="onRemove"
- ref="attributeInput" shortcutInitMode="hand" @codeRefresh="generateVueCode" style="display:none;"
- :__rawVueInfo__="currentEditRawInfo">
+ ref="attributeInput" shortcutInitMode="hand" :__rawVueInfo__="currentEditRawInfo">
</attribute-input>
</div>
</div>
@@ -38,22 +37,22 @@
<el-tooltip effect="dark" content="查看实时代码" placement="top-start">
<img class="round-icon" :src="iconCode" alt="" @click="codeDialogVisible = true">
</el-tooltip>
- <el-tooltip effect="dark" content="清空当前编辑内容" placement="top-start">
- <el-popconfirm confirmButtonText="确认" cancelButtonText="点错了" icon="el-icon-info" iconColor="red"
- title="点我将清空所有编辑的内容, 确认吗?" @onConfirm="clear">
- <img slot="reference" class="round-icon" :src="iconClear" alt="">
- </el-popconfirm>
- </el-tooltip>
+ <el-popconfirm confirmButtonText="确认" cancelButtonText="点错了" icon="el-icon-info" iconColor="red"
+ title="点我将清空所有编辑的内容, 确认吗?" @confirm="clear">
+ <template #reference>
+ <img class="round-icon" :src="iconClear" alt="">
+ </template>
+ </el-popconfirm>
</div>
<div>
- <lc-code :rawCode="code" :codeDialogVisible.sync="codeDialogVisible">
+ <lc-code :rawCode="code" v-model:codeDialogVisible="codeDialogVisible">
</lc-code>
- <code-structure @save="onSaveAttr" @remove="onRemove" ref="codeStructure" :visible.sync="structureVisible"
- @codeRefresh="generateVueCode" @onLevelChange="onLevelChange">
+ <code-structure @save="onSaveAttr" @remove="onRemove" ref="codeStructure" v-model="structureVisible"
+ @reRender="render">
</code-structure>
- <CodeEditor :codeDialogVisible.sync="jsDialogVisible" @saveJSCode="saveJSCode"></CodeEditor>
- <VueEditor :vueDialogVisible.sync="vueDialogVisible" @codeParseSucess="codeParseSucess"></VueEditor>
+ <CodeEditor v-model:codeDialogVisible="jsDialogVisible" @saveJSCode="saveJSCode"></CodeEditor>
+ <VueEditor v-model:vueDialogVisible="vueDialogVisible" @codeParseSucess="codeParseSucess"></VueEditor>
</div>
<!-- 辅助定位线 -->
@@ -61,27 +60,33 @@
<div class="x"></div>
</div>
</div>
+
+ <div id="fullScreen" v-if="!editMode">
+ <div style="margin: 20px; font-weight: bold;">按下ESC退出预览模式</div>
+ <div id="mountedEle"></div>
+ </div>
</template>
<script>
+import { defineAsyncComponent } from 'vue'
import { splitInit } from "../libs/split-init";
-// 这个文件不可以进行懒加载,它会导致运行时不可点击的行为,具体原因未知
+// // 这个文件不可以进行懒加载,它会导致运行时不可点击的行为,具体原因未知
import { MainPanelProvider } from "../libs/main-panel";
import { initContainerForLine } from "@/utils/lineHelper";
-
-const keymaster = require('keymaster');
+import keymaster from "keymaster"
export default {
name: "vcc",
props: ['initCodeEntity'],
+ emits: ['updateCodeEntity'],
components: {
- RawComponents: () => import("../components/RawComponents"),
- ToolsBar: () => import("./ToolsBar"),
- AttributeInput: () => import("../components/AttributeInput"),
- CodeStructure: () => import("../components/CodeStructure"),
- "lc-code": () => import("../components/Code"),
- CodeEditor: () => import('../components/JSCodeEditorDialog.vue'),
- VueEditor: () => import('../components/VueCodeParseDialog.vue')
+ RawComponents: defineAsyncComponent(() => import("@/components/RawComponents.vue")),
+ ToolsBar: defineAsyncComponent(() => import("./ToolsBar")),
+ AttributeInput: defineAsyncComponent(() => import("../components/AttributeInput")),
+ CodeStructure: defineAsyncComponent(() => import("../components/CodeStructure")),
+ "lc-code": defineAsyncComponent(() => import("../components/Code")),
+ CodeEditor: defineAsyncComponent(() => import('../components/JSCodeEditorDialog.vue')),
+ VueEditor: defineAsyncComponent(() => import('../components/VueCodeParseDialog.vue'))
},
data() {
return {
@@ -94,14 +99,14 @@ export default {
iconCode: ("https://static.imonkey.xueersi.com/download/vcc-resource/icon/code-working-outline.svg"),
iconClear: ("https://static.imonkey.xueersi.com/download/vcc-resource/icon/trash-outline.svg"),
- viewMode: false
+ editMode: true
};
},
watch: {
currentEditRawInfo(newValue) {
const attributeContainter = document.querySelector(".attribute");
if (newValue) {
- attributeContainter.style = "right:10px;";
+ attributeContainter.style = "right:10px; display:block;";
this.$refs['attributeInput'].onShow();
} else {
attributeContainter.style = "right: calc(-300px - 20px); display:none;";
@@ -139,6 +144,13 @@ export default {
this.undo();
return false
});
+
+
+ keymaster('esc', () => {
+ this.editMode = true;
+ this.mainPanelProvider.setEditMode(true);
+ return false
+ });
},
init() {
@@ -205,7 +217,11 @@ export default {
},
onEditModeChange(newValue) {
- this.mainPanelProvider.setEditMode(newValue);
+ this.editMode = newValue;
+
+ this.$nextTick(() => {
+ this.mainPanelProvider.setEditMode(newValue, document.querySelector("#mountedEle"));
+ })
},
renderCode() {
@@ -220,11 +236,6 @@ export default {
this.mainPanelProvider.saveAttribute(resultList, lc_id);
},
- onLevelChange(removeID, movePath) {
- this.mainPanelProvider.onLevelChange(removeID, movePath);
- },
-
- generateVueCode() { },
onRemove({ lc_id }) {
this.mainPanelProvider.remove(lc_id);
},
@@ -240,10 +251,20 @@ export default {
this.mainPanelProvider.saveJSCode(code);
},
+ /**
+ * 二级编辑解析
+ */
codeParseSucess(vueCodeEntity) {
this.mainPanelProvider.render(vueCodeEntity);
},
+ /**
+ * 渲染指定结构
+ */
+ render(codeEntity) {
+ this.mainPanelProvider.render(codeEntity);
+ },
+
help() {
window.open('/doc')
}
@@ -365,6 +386,21 @@ export default {
pointer-events: none;
}
}
+
+#fullScreen {
+ width: 100%;
+ height: 100%;
+ position: fixed;
+ z-index: 3;
+ top: 0;
+ background: white;
+}
+
+#mountedEle {
+ border: 1px dashed rgb(126, 126, 128);
+ border-radius: 10px;
+ margin: 20px;
+}
</style>
<!-- 以下的样式作用于渲染容器中-->
diff --git a/src/components/AttributeInput.vue b/src/components/AttributeInput.vue
index f576218..4041bf3 100644
--- a/src/components/AttributeInput.vue
+++ b/src/components/AttributeInput.vue
@@ -1,11 +1,11 @@
<template>
<el-card class="attribute-container">
- <center>
+ <div style="text-align: center;">
<el-switch v-model="editMode" active-text="自由编辑" inactive-text="约束编辑" active-color="#13ce66"
inactive-color="#13ce66">
</el-switch>
- </center>
+ </div>
<div style="margin-top: 20px;">
<div name="1" v-show="!editMode">
@@ -13,8 +13,8 @@
<div class="item" v-for="(item, index) in localAttributes" :key="index">
<el-input v-model="item.key" :placeholder="'key' + index" class="half-width"></el-input>
<div class="split">:</div>
- <el-input v-model="item.value" :placeholder="'value' + index" class="half-width"></el-input>
- <i class="el-icon-minus" @click="deleteItem(index)"></i>
+ <el-input v-model="item.value" :placeholder="'value' + index" class="half-width" style="flex-grow: 3;"></el-input>
+ <el-icon @click="deleteItem(index)" style="margin-left: 5px;"><minus /></el-icon>
</div>
<div class="quick-add-root">
@@ -44,28 +44,31 @@
</div>
</div>
- <center style="margin-top: 10px;">
+ <div style="margin-top: 10px;text-align:center;">
<el-tooltip class="item" effect="dark" content="新增属性 ctrl+a" placement="bottom">
- <el-button type="primary" class="center" @click="createNew" icon="el-icon-circle-plus-outline" circle>
+ <el-button type="primary" class="center" @click="createNew" circle>
+ <el-icon><circle-plus /></el-icon>
</el-button>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="保存属性 ctrl+s" placement="bottom">
- <el-button type="success" class="center" @click="save" icon="el-icon-refresh" circle></el-button>
+ <el-button type="success" class="center" @click="save" circle>
+ <el-icon><refresh /></el-icon>
+ </el-button>
</el-tooltip>
- <el-tooltip class="item" effect="dark" content="移除该组件 ctrl+d" placement="bottom">
- <el-button v-if="enableRemoveButton" type="danger" class="center" icon="el-icon-delete" @click="remove" circle>
+ <el-tooltip v-if="enableRemoveButton" class="item" effect="dark" content="移除该组件 ctrl+d" placement="bottom">
+ <el-button type="danger" class="center" @click="remove" circle>
+ <el-icon><delete /></el-icon>
</el-button>
</el-tooltip>
- <el-tooltip class="item" effect="dark" content="复制一个兄弟组件 ctrl+c" placement="bottom">
- <el-button v-if="enableBroButton" type="primary" class="center" icon="el-icon-copy-document" @click="copyBro"
- circle>
+ <el-tooltip v-if="enableBroButton" class="item" effect="dark" content="复制一个兄弟组件 ctrl+c" placement="bottom">
+ <el-button type="primary" class="center" @click="copyBro" circle>
+ <el-icon><document-copy /></el-icon>
</el-button>
</el-tooltip>
-
- <center>
+ <div style="text-algin: center;">
<span class="shortcut-tip">支持快捷键操作</span>
- </center>
- </center>
+ </div>
+ </div>
</el-card>
</template>
@@ -73,7 +76,7 @@
<script>
import { getRawComponentKey, getRawComponentContent } from "@/utils/common";
import { brotherEleEnum, copyBroCode } from "@/libs/bro-ele-config";
-const keymaster = require('keymaster');
+import keymaster from "keymaster"
export default {
props: ['__rawVueInfo__', 'enableRemoveButton', 'shortcutInitMode'],// __rawVueInfo__为当前编辑的原始代码对象, shortcutInitMode快捷键的初始化方式
@@ -117,8 +120,6 @@ export default {
initShortcut() {
console.log(`init by mode: ${this.shortcutInitMode}`)
-
-
keymaster('⌘+a, ctrl+a', () => {
if (this.enable) {
this.createNew();
@@ -159,9 +160,7 @@ export default {
this.localAttributes.push({ key: "", value: "" });
},
save() {
-
try {
-
let resultList = [];
if (!this.editMode) {
resultList = this.localAttributes.filter((item) => {
@@ -198,7 +197,7 @@ export default {
},
copyBro() {
copyBroCode(this.__rawVueInfo__);
- this.$emit('codeRefresh');
+ this.$store.commit('onDragEnd');
},
onShow() {
// 这种方式适用于常规模式下的初始化,因为这个实例初始化后不会被销毁,一直常驻内存。但又不能受到其它实例销毁时的影响,所以需要明确的再次初始化。
@@ -271,7 +270,7 @@ export default {
.half-width {
width: 0%;
- flex-grow: 1;
+ flex-grow: 2;
}
.center {
diff --git a/src/components/Code.vue b/src/components/Code.vue
index 531660e..3bab94d 100644
--- a/src/components/Code.vue
+++ b/src/components/Code.vue
@@ -1,36 +1,36 @@
<template>
- <el-dialog title="代码预览" :visible.sync="codeDialogVisible" width="70%" top="10vh" :before-close="handleClose"
- :center=true>
- <pre style="max-height: 60vh;">
- <code v-html="formatCode"></code>
- </pre>
- <div>
- <center style="color: #666; font-size: 12px;">使用代码前请确认相应的组件库已集成至项目</center>
- </div>
- <span slot="footer">
-
- <el-tooltip effect="dark" content="拷贝" placement="left">
- <img class="round-icon" :src="iconCopy" alt="" @click="copyCheck">
- </el-tooltip>
- <el-tooltip effect="dark" content="下载" placement="right">
- <img class="round-icon" :src="iconDownload" alt="" @click="download">
- </el-tooltip>
-
- </span>
+ <el-dialog title="代码预览" v-model="codeDialogVisible" width="70%" top="10vh" :before-close="handleClose" :center=true>
+ <!-- 这里加v-if是因为CodeEditor内部不支持watch数据监测 -->
+ <CodeEditor v-if="codeDialogVisible" style="max-height: 65vh;" ref="codeEditor" :initCode="prettyCode" mode="text/html"></CodeEditor>
+ <div style="color: #666; font-size: 12px; text-align:center; margin: 5px;">使用代码前请确认相应的组件库已集成至项目</div>
+ <template v-slot:footer>
+ <span>
+ <el-tooltip effect="dark" content="拷贝" placement="left">
+ <img class="round-icon" :src="iconCopy" alt="" @click="copyCheck">
+ </el-tooltip>
+ <el-tooltip effect="dark" content="下载" placement="right">
+ <img class="round-icon" :src="iconDownload" alt="" @click="download">
+ </el-tooltip>
+ </span>
+ </template>
</el-dialog>
</template>
<script>
import './prism.css'
-import Prism from "prismjs";
import prettier from "prettier/standalone";
import parserHtml from "prettier/parser-html";
import copy from 'copy-to-clipboard';
import { saveAs } from "file-saver";
+import CodeEditor from './CodeEditor.vue'
+
export default {
props: ['rawCode', 'codeDialogVisible'],
+ components: {
+ CodeEditor
+ },
data() {
return {
@@ -95,10 +95,6 @@ export default {
}
},
-
- formatCode() {
- return Prism.highlight(this.prettyCode, Prism.languages.markup, "html");
- }
},
fillter: {},
};
@@ -107,7 +103,7 @@ export default {
<style scoped>
/* 在此自动生成 */
-::v-deep .el-dialog__body {
+:v-deep(.el-dialog__body) {
padding: 0 30px !important;
}
diff --git a/src/components/CodeEditor.vue b/src/components/CodeEditor.vue
index 4fb487c..ed46553 100644
--- a/src/components/CodeEditor.vue
+++ b/src/components/CodeEditor.vue
@@ -1,12 +1,12 @@
<template>
<div class="codemirror">
- <codemirror v-model="code" :options="cmOption" @cursorActivity="onCmCursorActivity" @ready="onCmReady"
+ <codemirror v-model:value="code" :options="cmOption" @cursorActivity="onCmCursorActivity" @ready="onCmReady"
@focus="onCmFocus" @blur="onCmBlur" />
</div>
</template>
<script>
-import { codemirror } from 'vue-codemirror'
+import Codemirror from "codemirror-editor-vue3";
// base style
import 'codemirror/lib/codemirror.css'
@@ -50,20 +50,23 @@ import 'codemirror/addon/fold/indent-fold.js'
import 'codemirror/addon/fold/markdown-fold.js'
import 'codemirror/addon/fold/xml-fold.js'
-require(['axios'], axios => {
- self.axios = axios.create({
- baseURL: '',
- timeout: 1000,
- });
-});
+import axios from 'axios';
export default {
props: ['initCode', 'mode'],
name: 'code-editor',
title: 'Mode: text/x-vue & Theme: monokai',
components: {
- codemirror
+ Codemirror
},
+
+ created() {
+ self.axios = axios.create({
+ baseURL: '',
+ timeout: 1000,
+ });
+ },
+
computed: {
code: {
get() {
@@ -74,6 +77,12 @@ export default {
}
}
},
+ watch: {
+ initCode() {
+ this.codeStore = this.initCode;
+ }
+ },
+
data() {
return {
codeStore: this.initCode,
diff --git a/src/components/CodeStructure.vue b/src/components/CodeStructure.vue
index 61bd396..ee08c5f 100644
--- a/src/components/CodeStructure.vue
+++ b/src/components/CodeStructure.vue
@@ -1,37 +1,24 @@
<template>
- <el-drawer :visible.sync="drawer" :with-header="false" size="70%" direction="btt">
+ <el-drawer v-model="drawer" :with-header="false" size="70%" direction="btt">
<div class="container">
- <center>组件结构检视图
+ <div style="text-align: center;">组件结构检视图
<br>
<span style="font-size:12px;">Components
Structure</span>
- </center>
+ </div>
<el-row :gutter="20" style="height:0px;flex-grow:1;">
<el-col :span="16" style="height: 100%;">
<div style="overflow: scroll;height:100%; margin: 0 20px;padding: 10px;">
- <vue-nestable v-model="treeData" @change="onLevelChange">
- <template slot-scope="{ item }">
- <vue-nestable-handle :item="item">
- <i class="el-icon-rank icon-s"></i>
- </vue-nestable-handle>
-
- <span @click="onNodeClick(item)">{{ item.text }}</span>
- </template>
-
- <div slot="placeholder">
- <b>The editor is empty.</b>
- </div>
- </vue-nestable>
+ <nested-draggable :data="treeData" />
</div>
</el-col>
<el-col :span="8">
- <attribute-input ref="attributeInput" :enableRemoveButton="true" v-if="currentEditRawInfo && drawer"
- @save="onSaveAttr" shortcutInitMode="auto" @remove="onRemove" @codeRefresh="codeRefresh"
- :__rawVueInfo__="currentEditRawInfo">
+ <attribute-input ref="attributeInput" :enableRemoveButton="true" v-if="currentEditRawInfo" @save="onSaveAttr"
+ shortcutInitMode="auto" @remove="onRemove" :__rawVueInfo__="currentEditRawInfo">
</attribute-input>
</el-col>
</el-row>
@@ -41,80 +28,33 @@
</template>
<script>
-import "./halower-tree.min.css";
-import "@/assets/nestable.css"
import { isObject, getRawComponentKey, getRawComponentContent } from "@/utils/common";
-import { VueNestable, VueNestableHandle } from 'vue-nestable';
+import nestedDraggable from './nested.vue'
+import { defineAsyncComponent } from 'vue'
export default {
props: ['visible'],
+ emits: ['onLevelChange', 'remove', 'save', 'update:visible', 'reRender'],
components: {
- AttributeInput: resolve => { require(["./AttributeInput"], resolve) },
- VueNestable,
- VueNestableHandle
+ AttributeInput: defineAsyncComponent(() => import("@/components/AttributeInput.vue")),
+ nestedDraggable
},
data() {
return {
// 在此自动生成
treeData: [],
- currentEditRawInfo: null
};
},
beforeCreate() { },
created() { },
beforeMount() { },
- mounted() { },
+ mounted() {
+ },
beforeUpdate() { },
updated() { },
destoryed() { },
methods: {
- // 在此自动生成
- request() {
- // 网络请求,可选
- },
- codeRefresh() {
- this.$emit('codeRefresh');
- },
- onLevelChange(value, options) {
- this.$emit('onLevelChange', value.id, options.pathTo);
- },
-
- convertStructure(rawInfo) {
- const title = getRawComponentKey(rawInfo);
- const object = rawInfo[title];
- const children = [];
- if (isObject(object)) {
- for (const key in object) {
- if (object.hasOwnProperty(key)) {
- if (key === '__children') {
- const element = object[key];
-
- element.forEach(item => {
- const temp = this.convertStructure(item);
- temp && children.push(temp);
- })
- } else if (isObject(object[key])) {
- // 组成一个新的结构,适配只有一个子节点的数据结构
- const __obj = {};
- __obj[key] = object[key];
- const child = this.convertStructure(__obj);
- child && children.push(child);
- }
- }
- }
-
- return {
- text: title,
- expanded: true,
- children: children,
- rawInfo: rawInfo,
- id: getRawComponentContent(rawInfo).lc_id
- }
- } else {
- return null;
- }
- },
onNodeClick(nodeInfo) {
this.currentEditRawInfo = nodeInfo.rawInfo;
@@ -130,12 +70,17 @@ export default {
},
updateCode(codeRawInfo) {
- this.treeData = [this.convertStructure(codeRawInfo)];
+ this._codeRawInfo = codeRawInfo;
+ const content = getRawComponentContent(codeRawInfo);
+ const children = content.__children;
+ this.treeData = children;
},
},
watch: {
- canInitShortcut(newValue) {
+ renderCount(){
+ // 这里利用了vuedraggable v-model的特性,它会更改对象本身的引用
+ this.$emit('reRender', this._codeRawInfo);
}
},
computed: {
@@ -147,8 +92,21 @@ export default {
this.$emit('update:visible', false);
}
},
+
+ renderCount(){
+ return this.$store.state.renderCount;
+ },
+
canInitShortcut() {
return this.currentEditRawInfo !== null && this.drawer;
+ },
+ currentEditRawInfo() {
+ if (this.$store.state.currentEditComp) {
+ const vccData = this.$store.state.currentEditComp.vccData;
+ return window.tree[vccData.lc_id];
+ } else {
+ return null;
+ }
}
},
fillter: {},
@@ -162,7 +120,7 @@ center {
padding: 20px;
}
-::v-deep .el-drawer__body {
+:v-deep(.el-drawer__body) {
height: 100%;
}
diff --git a/src/components/JSCodeEditorDialog.vue b/src/components/JSCodeEditorDialog.vue
index a002f2e..19735d2 100644
--- a/src/components/JSCodeEditorDialog.vue
+++ b/src/components/JSCodeEditorDialog.vue
@@ -1,5 +1,5 @@
<template>
- <el-dialog title="JS逻辑编辑" :visible.sync="codeDialogVisible" width="70%" top="10vh" :before-close="handleClose"
+ <el-dialog title="JS逻辑编辑" v-model="codeDialogVisible" width="70%" top="10vh" :before-close="handleClose"
:center=true>
<CodeEditor style="max-height: 65vh;" ref="codeEditor" :initCode="code" mode="text/javascript"></CodeEditor>
@@ -18,6 +18,7 @@ import CodeEditor from './CodeEditor.vue'
export default {
props: ['codeDialogVisible'],
+ emits: ['saveJSCode', 'update:codeDialogVisible'],
components: {
CodeEditor
},
@@ -117,7 +118,7 @@ export default {
<style scoped>
/* 在此自动生成 */
-::v-deep .el-dialog__body {
+:v-deep(.el-dialog__body) {
padding: 0 30px !important;
}
</style>
\ No newline at end of file
diff --git a/src/components/RawComponents.vue b/src/components/RawComponents.vue
index d1410ee..deeb5d8 100644
--- a/src/components/RawComponents.vue
+++ b/src/components/RawComponents.vue
@@ -19,26 +19,28 @@
<div>
<el-dropdown @command="handleCommand">
<span class="el-dropdown-link">
- <i ref="help" class="el-icon-question" style="font-size:22px;color:#4dba87;"></i>
+ <el-icon style="font-size:22px;color:#4dba87;"><question-filled /></el-icon>
</span>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item icon="el-icon-circle-check">基础组件数: {{ componentUnitNum }}
- </el-dropdown-item>
- <el-dropdown-item icon="el-icon-document" command="lcg">LCG平台</el-dropdown-item>
- <el-dropdown-item icon="el-icon-document" command="help">说明文档</el-dropdown-item>
- <el-dropdown-item icon="el-icon-chat-line-round" command="chat">在线沟通</el-dropdown-item>
- </el-dropdown-menu>
+ <template #dropdown>
+ <el-dropdown-menu>
+ <el-dropdown-item icon="el-icon-circle-check">基础组件数: {{ componentUnitNum }}
+ </el-dropdown-item>
+ <el-dropdown-item icon="el-icon-document" command="lcg">LCG平台</el-dropdown-item>
+ <el-dropdown-item icon="el-icon-document" command="help">说明文档</el-dropdown-item>
+ <el-dropdown-item icon="el-icon-chat-line-round" command="chat">在线沟通</el-dropdown-item>
+ </el-dropdown-menu>
+ </template>
</el-dropdown>
</div>
</div>
</nav>
<nav v-if="currentSelectBrand.titleArray && currentSelectBrand.titleArray.length > 0">
- <center style="margin-bottom:10px;">
+ <div style="margin-bottom:10px;text-align:center;">
<div style="padding:5px;font-size:12px;color:grey;">快速查找需要的</div>
<el-autocomplete class="inline-input" v-model="componentSearch" :fetch-suggestions="querySearch" size="mini"
placeholder="请输入..." @select="handleSelect"></el-autocomplete>
- </center>
+ </div>
<div class="dismiss-scroll">
<div v-for="(item, index) in currentSelectBrand.titleArray" :key="item.title" class="second-nav"
:class="{'active':currentSelectBrand.selectIndex === index}" @click="selectSubnav(currentSelectBrand, index)">
@@ -60,8 +62,8 @@
// import vant from "../rawComponents/vant";
// import iview from "../rawComponents/iview";
// import quasar from "../rawComponents/quasar";
-import raw from "../rawComponents/raw";
-import ele from "../rawComponents/element";
+import raw from "../rawComponents/raw/index.vue";
+import ele from "../rawComponents/element/index.vue";
export default {
data() {
@@ -94,7 +96,7 @@ export default {
enable: false
},],
- currentIndex: 1
+ currentIndex: 0
};
},
methods: {
@@ -260,7 +262,7 @@ nav {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
-::v-deep .el-submenu__title {
+:v-deep(.el-submenu__title) {
padding: 0 15px !important;
}
diff --git a/src/components/VueCodeParseDialog.vue b/src/components/VueCodeParseDialog.vue
index 7c3f996..0636704 100644
--- a/src/components/VueCodeParseDialog.vue
+++ b/src/components/VueCodeParseDialog.vue
@@ -1,5 +1,5 @@
<template>
- <el-dialog title="Vue二次编辑" :visible.sync="vueDialogVisible" width="70%" top="10vh" :before-close="handleClose"
+ <el-dialog title="Vue二次编辑" v-model="vueDialogVisible" width="70%" top="10vh" :before-close="handleClose"
:center=true>
<CodeEditor style="max-height: 65vh;" ref="codeEditor" :initCode="code" mode="text/html"></CodeEditor>
@@ -20,6 +20,7 @@ import { ergodic, findAObject } from '../utils/common';
export default {
props: ['vueDialogVisible'],
+ emits: ['codeParseSucess', 'update:vueDialogVisible'],
components: {
CodeEditor
},
@@ -88,7 +89,7 @@ export default {
<style scoped>
/* 在此自动生成 */
-::v-deep .el-dialog__body {
+:v-deep(.el-dialog__body) {
padding: 0 30px !important;
}
</style>
\ No newline at end of file
diff --git a/src/components/nested.vue b/src/components/nested.vue
new file mode 100644
index 0000000..f256caf
--- /dev/null
+++ b/src/components/nested.vue
@@ -0,0 +1,89 @@
+<template>
+ <draggable class="dragArea" tag="ul" :list="data" @start="onStartDrag" @choose="onClick"
+ @end="onEndDrag">
+ <template #item="{ element }">
+ <li class="itemArea">
+ <p>{{ getRawComponentKey(element) }}</p>
+ <nested-draggable :data="getRawComponentContent(element).__children" />
+ </li>
+ </template>
+ </draggable>
+</template>
+<script>
+import draggable from "vuedraggable";
+import { getRawComponentKey, getRawComponentContent } from "@/utils/common";
+
+export default {
+ props: {
+ data: {
+ required: true,
+ type: Array
+ }
+ },
+ data() {
+ return {
+ }
+ },
+
+ computed: {
+ },
+ methods: {
+ getRawComponentKey,
+ getRawComponentContent,
+ onStartDrag(event) {
+ event.item.classList.add("is-dragging");
+ },
+ onClick(event) {
+ if(this.$store.state.currentEditComp){
+ this.$store.state.currentEditComp.item.classList.remove("is-dragging");
+ }
+
+ event.item.classList.add("is-dragging");
+
+ event.vccData = getRawComponentContent(this.data[event.oldIndex]);
+ this.$store.commit('storeCurrentEditComp', event);
+ },
+ onEndDrag(event) {
+ event.item.classList.remove("is-dragging");
+
+ this.$store.commit('onDragEnd');
+ }
+ },
+
+ components: {
+ draggable
+ },
+ name: "nested-draggable"
+};
+</script>
+<style scoped lang="scss">
+.dragArea {
+ min-height: 20px;
+ border: 1px dashed rgb(126, 126, 128);
+ border-radius: 5px;
+ padding-inline-start: 30px;
+ padding-right: 2px;
+ padding-bottom: 2px;
+}
+
+p {
+ margin: 10px 0;
+}
+
+.itemArea {
+ min-height: 20px;