tianheng-ui 0.0.47 → 0.0.50

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,601 +1,591 @@
1
- <template>
2
- <div class="fm-style">
3
- <el-container class="fm2-container">
4
- <el-main class="fm2-main">
5
- <el-container>
6
- <el-aside width="250px">
7
- <div class="components-list">
8
- <template v-if="basicFields.length">
9
- <div class="widget-cate">
10
- 基础字段
11
- </div>
12
- <draggable
13
- tag="ul"
14
- :list="basicComponents"
15
- v-bind="{
16
- group: { name: 'people', pull: 'clone', put: false },
17
- sort: false,
18
- ghostClass: 'ghost'
19
- }"
20
- @end="handleMoveEnd"
21
- @start="handleMoveStart"
22
- :move="handleMove"
23
- >
24
- <template v-for="(item, index) in basicComponents">
25
- <li
26
- v-if="basicFields.indexOf(item.type) >= 0"
27
- class="form-edit-widget-label"
28
- :class="{ 'no-put': item.type == 'divider' }"
29
- :key="index"
30
- >
31
- <a>
32
- <i class="icon iconfont" :class="item.icon"></i>
33
- <span>{{ item.name }}</span>
34
- </a>
35
- </li>
36
- </template>
37
- </draggable>
38
- </template>
39
- <template v-if="advanceFields.length">
40
- <div class="widget-cate">
41
- 高级字段
42
- </div>
43
- <draggable
44
- tag="ul"
45
- :list="advanceComponents"
46
- v-bind="{
47
- group: { name: 'people', pull: 'clone', put: false },
48
- sort: false,
49
- ghostClass: 'ghost'
50
- }"
51
- @end="handleMoveEnd"
52
- @start="handleMoveStart"
53
- :move="handleMove"
54
- >
55
- <template v-for="(item, index) in advanceComponents">
56
- <li
57
- v-if="advanceFields.indexOf(item.type) >= 0"
58
- class="form-edit-widget-label"
59
- :class="{ 'no-put': item.type == 'table' }"
60
- :key="index"
61
- >
62
- <a>
63
- <i class="icon iconfont" :class="item.icon"></i>
64
- <span>{{ item.name }}</span>
65
- </a>
66
- </li>
67
- </template>
68
- </draggable>
69
- </template>
70
-
71
- <template v-if="layoutFields.length">
72
- <div class="widget-cate">
73
- 布局字段
74
- </div>
75
- <draggable
76
- tag="ul"
77
- :list="layoutComponents"
78
- v-bind="{
79
- group: { name: 'people', pull: 'clone', put: false },
80
- sort: false,
81
- ghostClass: 'ghost'
82
- }"
83
- @end="handleMoveEnd"
84
- @start="handleMoveStart"
85
- :move="handleMove"
86
- >
87
- <template v-for="(item, index) in layoutComponents">
88
- <li
89
- v-if="layoutFields.indexOf(item.type) >= 0"
90
- class="form-edit-widget-label no-put"
91
- :key="index"
92
- >
93
- <a>
94
- <i class="icon iconfont" :class="item.icon"></i>
95
- <span>{{ item.name }}</span>
96
- </a>
97
- </li>
98
- </template>
99
- </draggable>
100
- </template>
101
- </div>
102
- </el-aside>
103
- <el-container class="center-container" direction="vertical">
104
- <el-header class="btn-bar" style="height: 45px;">
105
- <slot name="action"> </slot>
106
- <el-button
107
- v-if="upload"
108
- type="text"
109
- size="medium"
110
- icon="el-icon-upload2"
111
- @click="handleUpload"
112
- >导入JSON</el-button
113
- >
114
- <el-button
115
- v-if="clearable"
116
- type="text"
117
- size="medium"
118
- icon="el-icon-delete"
119
- @click="handleClear"
120
- >清空</el-button
121
- >
122
- <el-button
123
- v-if="preview"
124
- type="text"
125
- size="medium"
126
- icon="el-icon-view"
127
- @click="handlePreview"
128
- >预览</el-button
129
- >
130
- <el-button
131
- v-if="generateJson"
132
- type="text"
133
- size="medium"
134
- icon="el-icon-tickets"
135
- @click="handleGenerateJson"
136
- >生成JSON</el-button
137
- >
138
- <el-button
139
- v-if="generateCode"
140
- type="text"
141
- size="medium"
142
- icon="el-icon-document"
143
- @click="handleGenerateCode"
144
- >生成代码</el-button
145
- >
146
- </el-header>
147
- <el-main :class="{ 'widget-empty': widgetForm.list.length == 0 }">
148
- <widget-form
149
- v-if="!resetJson"
150
- ref="widgetForm"
151
- :data="widgetForm"
152
- :select.sync="widgetFormSelect"
153
- ></widget-form>
154
- </el-main>
155
- </el-container>
156
-
157
- <el-aside class="widget-config-container">
158
- <el-container>
159
- <el-header height="45px">
160
- <div
161
- class="config-tab"
162
- :class="{ active: configTab == 'widget' }"
163
- @click="handleConfigSelect('widget')"
164
- >
165
- 字段属性
166
- </div>
167
- <div
168
- class="config-tab"
169
- :class="{ active: configTab == 'form' }"
170
- @click="handleConfigSelect('form')"
171
- >
172
- 表单属性
173
- </div>
174
- </el-header>
175
- <el-main class="config-content">
176
- <widget-config
177
- v-show="configTab == 'widget'"
178
- :data="widgetFormSelect"
179
- :remoteApis="remoteApis"
180
- ></widget-config>
181
- <form-config
182
- v-show="configTab == 'form'"
183
- :data="widgetForm.config"
184
- ></form-config>
185
- </el-main>
186
- </el-container>
187
- </el-aside>
188
-
189
- <cus-dialog
190
- :visible="previewVisible"
191
- @on-close="previewVisible = false"
192
- ref="widgetPreview"
193
- width="1000px"
194
- form
195
- >
196
- <generate-form
197
- insite="true"
198
- @on-change="handleDataChange"
199
- v-if="previewVisible"
200
- :data="widgetForm"
201
- :value="widgetModels"
202
- :remote="remoteFuncs"
203
- ref="generateForm"
204
- >
205
- <template v-slot:blank="scope">
206
- Width
207
- <el-input
208
- v-model="scope.model.blank.width"
209
- style="width: 100px"
210
- ></el-input>
211
- Height
212
- <el-input
213
- v-model="scope.model.blank.height"
214
- style="width: 100px"
215
- ></el-input>
216
- </template>
217
- </generate-form>
218
-
219
- <template slot="action">
220
- <el-button type="primary" @click="handleTest">获取数据</el-button>
221
- <el-button @click="handleReset">重置</el-button>
222
- </template>
223
- </cus-dialog>
224
-
225
- <cus-dialog
226
- :visible="uploadVisible"
227
- @on-close="uploadVisible = false"
228
- @on-submit="handleUploadJson"
229
- ref="uploadJson"
230
- width="800px"
231
- form
232
- >
233
- <el-alert
234
- type="info"
235
- title="JSON格式如下,直接复制生成的json覆盖此处代码点击确定即可"
236
- ></el-alert>
237
- <div id="uploadeditor" style="height: 400px;width: 100%;">
238
- {{ jsonEg }}
239
- </div>
240
- </cus-dialog>
241
-
242
- <cus-dialog
243
- :visible="jsonVisible"
244
- @on-close="jsonVisible = false"
245
- ref="jsonPreview"
246
- width="800px"
247
- form
248
- >
249
- <div id="jsoneditor" style="height: 400px;width: 100%;">
250
- {{ jsonTemplate }}
251
- </div>
252
-
253
- <template slot="action">
254
- <el-button
255
- type="primary"
256
- class="json-btn"
257
- :data-clipboard-text="jsonCopyValue"
258
- >复制数据</el-button
259
- >
260
- </template>
261
- </cus-dialog>
262
-
263
- <cus-dialog
264
- :visible="codeVisible"
265
- @on-close="codeVisible = false"
266
- ref="codePreview"
267
- width="800px"
268
- form
269
- :action="false"
270
- >
271
- <!-- <div id="codeeditor" style="height: 500px; width: 100%;">{{htmlTemplate}}</div> -->
272
- <el-tabs
273
- type="border-card"
274
- style="box-shadow: none;"
275
- v-model="codeActiveName"
276
- >
277
- <el-tab-pane label="Vue Component" name="vue">
278
- <div id="vuecodeeditor" style="height: 500px; width: 100%;">
279
- {{ vueTemplate }}
280
- </div>
281
- </el-tab-pane>
282
- <el-tab-pane label="HTML" name="html">
283
- <div id="codeeditor" style="height: 500px; width: 100%;">
284
- {{ htmlTemplate }}
285
- </div>
286
- </el-tab-pane>
287
- </el-tabs>
288
- </cus-dialog>
289
- </el-container>
290
- </el-main>
291
- <!-- <el-footer height="30px" style="font-weight: 600;"
292
- >Powered by
293
- <a target="_blank" href="https://github.com/GavinZhuLei/vue-form-making"
294
- >vue-form-making</a
295
- ></el-footer
296
- > -->
297
- </el-container>
298
- </div>
299
- </template>
300
-
301
- <script>
302
- import ace from "ace-builds";
303
- import "ace-builds/src-min-noconflict/mode-json";
304
- import "ace-builds/src-min-noconflict/mode-html";
305
- import htmlWorkerUrl from "file-loader!ace-builds/src-min-noconflict/worker-html";
306
- ace.config.setModuleUrl("ace/mode/html_worker", htmlWorkerUrl);
307
- import jsonWorkerUrl from "file-loader!ace-builds/src-noconflict/worker-json";
308
- ace.config.setModuleUrl("ace/mode/json_worker", jsonWorkerUrl);
309
-
310
- import Draggable from "vuedraggable";
311
- import Clipboard from "clipboard";
312
- import WidgetConfig from "./WidgetConfig";
313
- import FormConfig from "./FormConfig";
314
- import WidgetForm from "./WidgetForm";
315
- import CusDialog from "./CusDialog";
316
- import GenerateForm from "./GenerateForm";
317
- import {
318
- basicComponents,
319
- layoutComponents,
320
- advanceComponents
321
- } from "./componentsConfig.js";
322
- // import {loadJs, loadCss} from '../util/index.js'
323
- import request from "./util/request";
324
- import generateCode from "./generateCode.js";
325
-
326
- export default {
327
- name: "fm-making-form",
328
- components: {
329
- Draggable,
330
- WidgetConfig,
331
- FormConfig,
332
- WidgetForm,
333
- CusDialog,
334
- GenerateForm
335
- },
336
- props: {
337
- preview: {
338
- type: Boolean,
339
- default: false
340
- },
341
- generateCode: {
342
- type: Boolean,
343
- default: false
344
- },
345
- generateJson: {
346
- type: Boolean,
347
- default: false
348
- },
349
- upload: {
350
- type: Boolean,
351
- default: false
352
- },
353
- clearable: {
354
- type: Boolean,
355
- default: false
356
- },
357
- basicFields: {
358
- type: Array,
359
- default: () => [
360
- "input",
361
- "textarea",
362
- "number",
363
- "radio",
364
- "checkbox",
365
- "time",
366
- "date",
367
- "rate",
368
- "color",
369
- "select",
370
- "switch",
371
- "slider",
372
- "text"
373
- ]
374
- },
375
- advanceFields: {
376
- type: Array,
377
- default: () => ["blank", "imgupload", "editor", "cascader"]
378
- },
379
- layoutFields: {
380
- type: Array,
381
- default: () => ["grid"]
382
- },
383
- remoteApis: {
384
- type: Array,
385
- default: () => []
386
- }
387
- },
388
- data() {
389
- return {
390
- basicComponents,
391
- layoutComponents,
392
- advanceComponents,
393
- resetJson: false,
394
- widgetForm: {
395
- list: [],
396
- config: {
397
- labelWidth: 100,
398
- labelPosition: "right",
399
- size: "small"
400
- }
401
- },
402
- configTab: "widget",
403
- widgetFormSelect: null,
404
- previewVisible: false,
405
- jsonVisible: false,
406
- codeVisible: false,
407
- uploadVisible: false,
408
- remoteFuncs: {
409
- func_test(resolve) {
410
- setTimeout(() => {
411
- const options = [
412
- { id: "1", name: "1111" },
413
- { id: "2", name: "2222" },
414
- { id: "3", name: "3333" }
415
- ];
416
-
417
- resolve(options);
418
- }, 2000);
419
- },
420
- funcGetToken(resolve) {
421
- request
422
- .get("http://tools-server.making.link/api/uptoken")
423
- .then(res => {
424
- resolve(res.uptoken);
425
- });
426
- },
427
- upload_callback(response, file, fileList) {
428
- console.log("callback", response, file, fileList);
429
- }
430
- },
431
- widgetModels: {},
432
- blank: "",
433
- htmlTemplate: "",
434
- vueTemplate: "",
435
- jsonTemplate: "",
436
- uploadEditor: null,
437
- jsonCopyValue: "",
438
- jsonClipboard: null,
439
- jsonEg: `
440
- {
441
- "list": [],
442
- "config": {
443
- "labelWidth": 100,
444
- "labelPosition": "top",
445
- "size": "small"
446
- }
447
- }`,
448
- codeActiveName: "vue"
449
- };
450
- },
451
- mounted() {
452
- // this._loadComponents();
453
- },
454
- methods: {
455
- // _loadComponents() {
456
- // this.basicComponents = this.basicComponents.map(item => {
457
- // return {
458
- // ...item,
459
- // name: this.$t(`fm.components.fields.${item.type}`)
460
- // };
461
- // });
462
- // this.advanceComponents = this.advanceComponents.map(item => {
463
- // return {
464
- // ...item,
465
- // name: this.$t(`fm.components.fields.${item.type}`)
466
- // };
467
- // });
468
- // this.layoutComponents = this.layoutComponents.map(item => {
469
- // return {
470
- // ...item,
471
- // name: this.$t(`fm.components.fields.${item.type}`)
472
- // };
473
- // });
474
- // },
475
- handleGoGithub() {
476
- window.location.href = "https://github.com/GavinZhuLei/vue-form-making";
477
- },
478
- handleConfigSelect(value) {
479
- this.configTab = value;
480
- },
481
- handleMoveEnd(evt) {
482
- // console.log("end", evt);
483
- },
484
- handleMoveStart({ oldIndex }) {
485
- // console.log("start", oldIndex, this.basicComponents);
486
- },
487
- handleMove() {
488
- return true;
489
- },
490
- handlePreview() {
491
- // console.log(this.widgetForm);
492
- this.previewVisible = true;
493
- },
494
- handleTest() {
495
- this.$refs.generateForm
496
- .getData()
497
- .then(data => {
498
- this.$alert(data, "").catch(e => {});
499
- this.$refs.widgetPreview.end();
500
- })
501
- .catch(e => {
502
- this.$refs.widgetPreview.end();
503
- });
504
- },
505
- handleReset() {
506
- this.$refs.generateForm.reset();
507
- },
508
- handleGenerateJson() {
509
- this.jsonVisible = true;
510
- this.jsonTemplate = this.widgetForm;
511
- this.$nextTick(() => {
512
- const editor = ace.edit("jsoneditor");
513
- editor.session.setMode("ace/mode/json");
514
-
515
- if (!this.jsonClipboard) {
516
- this.jsonClipboard = new Clipboard(".json-btn");
517
- this.jsonClipboard.on("success", e => {
518
- this.$message.success("复制成功");
519
- });
520
- }
521
- this.jsonCopyValue = JSON.stringify(this.widgetForm);
522
- });
523
- },
524
- handleGenerateCode() {
525
- this.codeVisible = true;
526
- this.htmlTemplate = generateCode(JSON.stringify(this.widgetForm), "html");
527
- this.vueTemplate = generateCode(JSON.stringify(this.widgetForm), "vue");
528
- this.$nextTick(() => {
529
- const editor = ace.edit("codeeditor");
530
- editor.session.setMode("ace/mode/html");
531
-
532
- const vueeditor = ace.edit("vuecodeeditor");
533
- vueeditor.session.setMode("ace/mode/html");
534
- });
535
- },
536
- handleUpload() {
537
- this.uploadVisible = true;
538
- this.$nextTick(() => {
539
- this.uploadEditor = ace.edit("uploadeditor");
540
- this.uploadEditor.session.setMode("ace/mode/json");
541
- });
542
- },
543
- handleUploadJson() {
544
- try {
545
- this.setJSON(JSON.parse(this.uploadEditor.getValue()));
546
- this.uploadVisible = false;
547
- } catch (e) {
548
- this.$message.error(e.message);
549
- this.$refs.uploadJson.end();
550
- }
551
- },
552
- handleClear() {
553
- this.widgetForm = {
554
- list: [],
555
- config: {
556
- labelWidth: 100,
557
- labelPosition: "right",
558
- size: "small",
559
- customClass: ""
560
- }
561
- };
562
-
563
- this.widgetFormSelect = {};
564
- },
565
- clear() {
566
- this.handleClear();
567
- },
568
- getJSON() {
569
- return this.widgetForm;
570
- },
571
- getHtml() {
572
- return generateCode(JSON.stringify(this.widgetForm));
573
- },
574
- setJSON(json) {
575
- this.widgetForm = json;
576
-
577
- if (json.list.length > 0) {
578
- this.widgetFormSelect = json.list[0];
579
- }
580
- },
581
- handleInput(val) {
582
- // console.log(val);
583
- this.blank = val;
584
- },
585
- handleDataChange(field, value, data) {
586
- // console.log(field, value, data);
587
- }
588
- },
589
- watch: {
590
- widgetForm: {
591
- deep: true,
592
- handler: function(val) {
593
- // console.log(this.$refs.widgetForm);
594
- }
595
- },
596
- $lang: function(val) {
597
- this._loadComponents();
598
- }
599
- }
600
- };
601
- </script>
1
+ <template>
2
+ <div class="fm-style">
3
+ <el-container class="fm2-container">
4
+ <el-main class="fm2-main">
5
+ <el-container>
6
+ <el-aside width="250px">
7
+ <div class="components-list">
8
+ <template v-if="basicFields.length">
9
+ <div class="widget-cate">
10
+ 基础字段
11
+ </div>
12
+ <draggable
13
+ tag="ul"
14
+ :list="basicComponents"
15
+ v-bind="{
16
+ group: { name: 'people', pull: 'clone', put: false },
17
+ sort: false,
18
+ ghostClass: 'ghost'
19
+ }"
20
+ @end="handleMoveEnd"
21
+ @start="handleMoveStart"
22
+ :move="handleMove"
23
+ >
24
+ <template v-for="(item, index) in basicComponents">
25
+ <li
26
+ v-if="basicFields.indexOf(item.type) >= 0"
27
+ class="form-edit-widget-label"
28
+ :class="{ 'no-put': item.type == 'divider' }"
29
+ :key="index"
30
+ >
31
+ <a>
32
+ <i class="icon iconfont" :class="item.icon"></i>
33
+ <span>{{ item.name }}</span>
34
+ </a>
35
+ </li>
36
+ </template>
37
+ </draggable>
38
+ </template>
39
+ <template v-if="advanceFields.length">
40
+ <div class="widget-cate">
41
+ 高级字段
42
+ </div>
43
+ <draggable
44
+ tag="ul"
45
+ :list="advanceComponents"
46
+ v-bind="{
47
+ group: { name: 'people', pull: 'clone', put: false },
48
+ sort: false,
49
+ ghostClass: 'ghost'
50
+ }"
51
+ @end="handleMoveEnd"
52
+ @start="handleMoveStart"
53
+ :move="handleMove"
54
+ >
55
+ <template v-for="(item, index) in advanceComponents">
56
+ <li
57
+ v-if="advanceFields.indexOf(item.type) >= 0"
58
+ class="form-edit-widget-label"
59
+ :class="{ 'no-put': item.type == 'table' }"
60
+ :key="index"
61
+ >
62
+ <a>
63
+ <i class="icon iconfont" :class="item.icon"></i>
64
+ <span>{{ item.name }}</span>
65
+ </a>
66
+ </li>
67
+ </template>
68
+ </draggable>
69
+ </template>
70
+
71
+ <template v-if="layoutFields.length">
72
+ <div class="widget-cate">
73
+ 布局字段
74
+ </div>
75
+ <draggable
76
+ tag="ul"
77
+ :list="layoutComponents"
78
+ v-bind="{
79
+ group: { name: 'people', pull: 'clone', put: false },
80
+ sort: false,
81
+ ghostClass: 'ghost'
82
+ }"
83
+ >
84
+ <template v-for="(item, index) in layoutComponents">
85
+ <li
86
+ v-if="layoutFields.indexOf(item.type) >= 0"
87
+ class="form-edit-widget-label no-put"
88
+ :key="index"
89
+ >
90
+ <a>
91
+ <i class="icon iconfont" :class="item.icon"></i>
92
+ <span>{{ item.name }}</span>
93
+ </a>
94
+ </li>
95
+ </template>
96
+ </draggable>
97
+ </template>
98
+ </div>
99
+ </el-aside>
100
+ <el-container class="center-container" direction="vertical">
101
+ <el-header class="btn-bar" style="height: 45px;">
102
+ <slot name="action"> </slot>
103
+ <el-button
104
+ v-if="upload"
105
+ type="text"
106
+ size="medium"
107
+ icon="el-icon-upload2"
108
+ @click="handleUpload"
109
+ >导入JSON</el-button
110
+ >
111
+ <el-button
112
+ v-if="clearable"
113
+ type="text"
114
+ size="medium"
115
+ icon="el-icon-delete"
116
+ @click="handleClear"
117
+ >清空</el-button
118
+ >
119
+ <el-button
120
+ v-if="preview"
121
+ type="text"
122
+ size="medium"
123
+ icon="el-icon-view"
124
+ @click="handlePreview"
125
+ >预览</el-button
126
+ >
127
+ <el-button
128
+ v-if="generateJson"
129
+ type="text"
130
+ size="medium"
131
+ icon="el-icon-tickets"
132
+ @click="handleGenerateJson"
133
+ >生成JSON</el-button
134
+ >
135
+ <el-button
136
+ v-if="generateCode"
137
+ type="text"
138
+ size="medium"
139
+ icon="el-icon-document"
140
+ @click="handleGenerateCode"
141
+ >生成代码</el-button
142
+ >
143
+ </el-header>
144
+ <el-main :class="{ 'widget-empty': widgetForm.list.length == 0 }">
145
+ <widget-form
146
+ v-if="!resetJson"
147
+ ref="widgetForm"
148
+ :data="widgetForm"
149
+ :select.sync="widgetFormSelect"
150
+ >
151
+ </widget-form>
152
+ </el-main>
153
+ </el-container>
154
+
155
+ <el-aside class="widget-config-container">
156
+ <el-container>
157
+ <el-header height="45px">
158
+ <div
159
+ class="config-tab"
160
+ :class="{ active: configTab == 'widget' }"
161
+ @click="handleConfigSelect('widget')"
162
+ >
163
+ 字段属性
164
+ </div>
165
+ <div
166
+ class="config-tab"
167
+ :class="{ active: configTab == 'form' }"
168
+ @click="handleConfigSelect('form')"
169
+ >
170
+ 表单属性
171
+ </div>
172
+ </el-header>
173
+ <el-main class="config-content">
174
+ <widget-config
175
+ v-show="configTab == 'widget'"
176
+ :data="widgetFormSelect"
177
+ :remoteApis="remoteApis"
178
+ ></widget-config>
179
+ <form-config
180
+ v-show="configTab == 'form'"
181
+ :data="widgetForm.config"
182
+ ></form-config>
183
+ </el-main>
184
+ </el-container>
185
+ </el-aside>
186
+
187
+ <cus-dialog
188
+ :visible="previewVisible"
189
+ @on-close="previewVisible = false"
190
+ ref="widgetPreview"
191
+ width="1000px"
192
+ form
193
+ >
194
+ <generate-form
195
+ insite="true"
196
+ @on-change="handleDataChange"
197
+ v-if="previewVisible"
198
+ :data="widgetForm"
199
+ :value="widgetModels"
200
+ :remote="remoteFuncs"
201
+ :slotKeys="slotKeys"
202
+ ref="generateForm"
203
+ >
204
+ <template v-for="name in slotKeys" :slot="name">
205
+ <slot :name="name" />
206
+ </template>
207
+ </generate-form>
208
+
209
+ <template slot="action">
210
+ <el-button type="primary" @click="handleTest">获取数据</el-button>
211
+ <el-button @click="handleReset">重置</el-button>
212
+ </template>
213
+ </cus-dialog>
214
+
215
+ <cus-dialog
216
+ :visible="uploadVisible"
217
+ @on-close="uploadVisible = false"
218
+ @on-submit="handleUploadJson"
219
+ ref="uploadJson"
220
+ width="800px"
221
+ form
222
+ >
223
+ <el-alert
224
+ type="info"
225
+ title="JSON格式如下,直接复制生成的json覆盖此处代码点击确定即可"
226
+ ></el-alert>
227
+ <div id="uploadeditor" style="height: 400px;width: 100%;">
228
+ {{ jsonEg }}
229
+ </div>
230
+ </cus-dialog>
231
+
232
+ <cus-dialog
233
+ :visible="jsonVisible"
234
+ @on-close="jsonVisible = false"
235
+ ref="jsonPreview"
236
+ width="800px"
237
+ form
238
+ >
239
+ <div id="jsoneditor" style="height: 400px;width: 100%;">
240
+ {{ jsonTemplate }}
241
+ </div>
242
+
243
+ <template slot="action">
244
+ <el-button
245
+ type="primary"
246
+ class="json-btn"
247
+ :data-clipboard-text="jsonCopyValue"
248
+ >复制数据</el-button
249
+ >
250
+ </template>
251
+ </cus-dialog>
252
+
253
+ <cus-dialog
254
+ :visible="codeVisible"
255
+ @on-close="codeVisible = false"
256
+ ref="codePreview"
257
+ width="800px"
258
+ form
259
+ :action="false"
260
+ >
261
+ <!-- <div id="codeeditor" style="height: 500px; width: 100%;">{{htmlTemplate}}</div> -->
262
+ <el-tabs
263
+ type="border-card"
264
+ style="box-shadow: none;"
265
+ v-model="codeActiveName"
266
+ >
267
+ <el-tab-pane label="Vue Component" name="vue">
268
+ <div id="vuecodeeditor" style="height: 500px; width: 100%;">
269
+ {{ vueTemplate }}
270
+ </div>
271
+ </el-tab-pane>
272
+ <el-tab-pane label="HTML" name="html">
273
+ <div id="codeeditor" style="height: 500px; width: 100%;">
274
+ {{ htmlTemplate }}
275
+ </div>
276
+ </el-tab-pane>
277
+ </el-tabs>
278
+ </cus-dialog>
279
+ </el-container>
280
+ </el-main>
281
+ <!-- <el-footer height="30px" style="font-weight: 600;"
282
+ >Powered by
283
+ <a target="_blank" href="https://github.com/GavinZhuLei/vue-form-making"
284
+ >vue-form-making</a
285
+ ></el-footer
286
+ > -->
287
+ </el-container>
288
+ </div>
289
+ </template>
290
+
291
+ <script>
292
+ import ace from "ace-builds";
293
+ import "ace-builds/src-min-noconflict/mode-json";
294
+ import "ace-builds/src-min-noconflict/mode-html";
295
+ import htmlWorkerUrl from "file-loader!ace-builds/src-min-noconflict/worker-html";
296
+ ace.config.setModuleUrl("ace/mode/html_worker", htmlWorkerUrl);
297
+ import jsonWorkerUrl from "file-loader!ace-builds/src-noconflict/worker-json";
298
+ ace.config.setModuleUrl("ace/mode/json_worker", jsonWorkerUrl);
299
+
300
+ import Draggable from "vuedraggable";
301
+ import Clipboard from "clipboard";
302
+ import WidgetConfig from "./WidgetConfig";
303
+ import FormConfig from "./FormConfig";
304
+ import WidgetForm from "./WidgetForm";
305
+ import CusDialog from "./CusDialog";
306
+ import GenerateForm from "./GenerateForm";
307
+ import {
308
+ basicComponents,
309
+ advanceComponents,
310
+ layoutComponents
311
+ } from "./componentsConfig.js";
312
+ // import {loadJs, loadCss} from '../util/index.js'
313
+ import request from "./util/request";
314
+ import generateCode from "./generateCode.js";
315
+
316
+ export default {
317
+ name: "fm-making-form",
318
+ components: {
319
+ Draggable,
320
+ WidgetConfig,
321
+ FormConfig,
322
+ WidgetForm,
323
+ CusDialog,
324
+ GenerateForm
325
+ },
326
+ props: {
327
+ preview: {
328
+ type: Boolean,
329
+ default: false
330
+ },
331
+ generateCode: {
332
+ type: Boolean,
333
+ default: false
334
+ },
335
+ generateJson: {
336
+ type: Boolean,
337
+ default: false
338
+ },
339
+ upload: {
340
+ type: Boolean,
341
+ default: false
342
+ },
343
+ clearable: {
344
+ type: Boolean,
345
+ default: false
346
+ },
347
+ basicFields: {
348
+ type: Array,
349
+ default: () => [
350
+ "input",
351
+ "textarea",
352
+ "number",
353
+ "radio",
354
+ "checkbox",
355
+ "time",
356
+ "date",
357
+ "rate",
358
+ "color",
359
+ "select",
360
+ "switch",
361
+ "slider",
362
+ "text",
363
+ "button"
364
+ ]
365
+ },
366
+ advanceFields: {
367
+ type: Array,
368
+ default: () => ["blank", "imgupload", "editor", "cascader", "table"]
369
+ },
370
+ layoutFields: {
371
+ type: Array,
372
+ default: () => ["grid", "tabs", "divider"]
373
+ },
374
+ remoteApis: {
375
+ type: Array,
376
+ default: () => []
377
+ }
378
+ },
379
+ data() {
380
+ return {
381
+ basicComponents,
382
+ layoutComponents,
383
+ advanceComponents,
384
+ resetJson: false,
385
+ widgetForm: {
386
+ list: [],
387
+ config: {
388
+ labelWidth: 100,
389
+ labelPosition: "right",
390
+ size: "small"
391
+ }
392
+ },
393
+ configTab: "widget",
394
+ widgetFormSelect: null,
395
+ previewVisible: false,
396
+ jsonVisible: false,
397
+ codeVisible: false,
398
+ uploadVisible: false,
399
+ remoteFuncs: {
400
+ func_test(resolve) {
401
+ setTimeout(() => {
402
+ const options = [
403
+ { id: "1", name: "1111" },
404
+ { id: "2", name: "2222" },
405
+ { id: "3", name: "3333" }
406
+ ];
407
+
408
+ resolve(options);
409
+ }, 2000);
410
+ },
411
+ funcGetToken(resolve) {
412
+ request
413
+ .get("http://tools-server.making.link/api/uptoken")
414
+ .then(res => {
415
+ resolve(res.uptoken);
416
+ });
417
+ },
418
+ upload_callback(response, file, fileList) {
419
+ console.log("callback", response, file, fileList);
420
+ }
421
+ },
422
+ widgetModels: { table: [{ name: "这是" }] },
423
+ blank: "",
424
+ htmlTemplate: "",
425
+ vueTemplate: "",
426
+ jsonTemplate: "",
427
+ uploadEditor: null,
428
+ jsonCopyValue: "",
429
+ jsonClipboard: null,
430
+ jsonEg: `
431
+ {
432
+ "list": [],
433
+ "config": {
434
+ "labelWidth": 100,
435
+ "labelPosition": "top",
436
+ "size": "small"
437
+ }
438
+ }`,
439
+ codeActiveName: "vue",
440
+ slotKeys: []
441
+ };
442
+ },
443
+ mounted() {
444
+ // this._loadComponents();
445
+ },
446
+ methods: {
447
+ // _loadComponents() {
448
+ // this.basicComponents = this.basicComponents.map(item => {
449
+ // return {
450
+ // ...item,
451
+ // name: this.$t(`fm.components.fields.${item.type}`)
452
+ // };
453
+ // });
454
+ // this.advanceComponents = this.advanceComponents.map(item => {
455
+ // return {
456
+ // ...item,
457
+ // name: this.$t(`fm.components.fields.${item.type}`)
458
+ // };
459
+ // });
460
+ // this.layoutComponents = this.layoutComponents.map(item => {
461
+ // return {
462
+ // ...item,
463
+ // name: this.$t(`fm.components.fields.${item.type}`)
464
+ // };
465
+ // });
466
+ // },
467
+ handleConfigSelect(value) {
468
+ this.configTab = value;
469
+ },
470
+ handleMoveEnd(evt) {
471
+ // console.log("end", evt);
472
+ },
473
+ handleMoveStart({ oldIndex }) {
474
+ // console.log("start", oldIndex, this.basicComponents);
475
+ },
476
+ handleMove() {
477
+ return true;
478
+ },
479
+ handlePreview() {
480
+ // console.log(this.widgetForm);
481
+ this.slotKeys = Object.keys(this.$slots);
482
+ this.previewVisible = true;
483
+ },
484
+ handleTest() {
485
+ this.$refs.generateForm
486
+ .getData()
487
+ .then(data => {
488
+ this.$alert(data, "").catch(e => {});
489
+ this.$refs.widgetPreview.end();
490
+ })
491
+ .catch(e => {
492
+ this.$refs.widgetPreview.end();
493
+ });
494
+ },
495
+ handleReset() {
496
+ this.$refs.generateForm.reset();
497
+ },
498
+ handleGenerateJson() {
499
+ this.jsonVisible = true;
500
+ this.jsonTemplate = this.widgetForm;
501
+ this.$nextTick(() => {
502
+ const editor = ace.edit("jsoneditor");
503
+ editor.session.setMode("ace/mode/json");
504
+
505
+ if (!this.jsonClipboard) {
506
+ this.jsonClipboard = new Clipboard(".json-btn");
507
+ this.jsonClipboard.on("success", e => {
508
+ this.$message.success("复制成功");
509
+ });
510
+ }
511
+ this.jsonCopyValue = JSON.stringify(this.widgetForm);
512
+ });
513
+ },
514
+ handleGenerateCode() {
515
+ this.codeVisible = true;
516
+ this.htmlTemplate = generateCode(JSON.stringify(this.widgetForm), "html");
517
+ this.vueTemplate = generateCode(JSON.stringify(this.widgetForm), "vue");
518
+ this.$nextTick(() => {
519
+ const editor = ace.edit("codeeditor");
520
+ editor.session.setMode("ace/mode/html");
521
+
522
+ const vueeditor = ace.edit("vuecodeeditor");
523
+ vueeditor.session.setMode("ace/mode/html");
524
+ });
525
+ },
526
+ handleUpload() {
527
+ this.uploadVisible = true;
528
+ this.$nextTick(() => {
529
+ this.uploadEditor = ace.edit("uploadeditor");
530
+ this.uploadEditor.session.setMode("ace/mode/json");
531
+ });
532
+ },
533
+ handleUploadJson() {
534
+ try {
535
+ this.setJSON(JSON.parse(this.uploadEditor.getValue()));
536
+ this.uploadVisible = false;
537
+ } catch (e) {
538
+ this.$message.error(e.message);
539
+ this.$refs.uploadJson.end();
540
+ }
541
+ },
542
+ handleClear() {
543
+ this.widgetForm = {
544
+ list: [],
545
+ config: {
546
+ labelWidth: 100,
547
+ labelPosition: "right",
548
+ size: "small",
549
+ customClass: ""
550
+ }
551
+ };
552
+
553
+ this.widgetFormSelect = {};
554
+ },
555
+ clear() {
556
+ this.handleClear();
557
+ },
558
+ getJSON() {
559
+ return this.widgetForm;
560
+ },
561
+ getHtml() {
562
+ return generateCode(JSON.stringify(this.widgetForm));
563
+ },
564
+ setJSON(json) {
565
+ this.widgetForm = json;
566
+
567
+ if (json.list.length > 0) {
568
+ this.widgetFormSelect = json.list[0];
569
+ }
570
+ },
571
+ handleInput(val) {
572
+ // console.log(val);
573
+ this.blank = val;
574
+ },
575
+ handleDataChange(field, value, data) {
576
+ // console.log(field, value, data);
577
+ }
578
+ },
579
+ watch: {
580
+ widgetForm: {
581
+ deep: true,
582
+ handler: function(val) {
583
+ // console.log(this.$refs.widgetForm);
584
+ }
585
+ },
586
+ $lang: function(val) {
587
+ this._loadComponents();
588
+ }
589
+ }
590
+ };
591
+ </script>