tianheng-ui 0.0.44 → 0.0.47

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,588 +1,601 @@
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
- ></widget-config>
180
- <form-config
181
- v-show="configTab == 'form'"
182
- :data="widgetForm.config"
183
- ></form-config>
184
- </el-main>
185
- </el-container>
186
- </el-aside>
187
-
188
- <cus-dialog
189
- :visible="previewVisible"
190
- @on-close="previewVisible = false"
191
- ref="widgetPreview"
192
- width="1000px"
193
- form
194
- >
195
- <generate-form
196
- insite="true"
197
- @on-change="handleDataChange"
198
- v-if="previewVisible"
199
- :data="widgetForm"
200
- :value="widgetModels"
201
- :remote="remoteFuncs"
202
- ref="generateForm"
203
- >
204
- <template v-slot:blank="scope">
205
- Width
206
- <el-input
207
- v-model="scope.model.blank.width"
208
- style="width: 100px"
209
- ></el-input>
210
- Height
211
- <el-input
212
- v-model="scope.model.blank.height"
213
- style="width: 100px"
214
- ></el-input>
215
- </template>
216
- </generate-form>
217
-
218
- <template slot="action">
219
- <el-button type="primary" @click="handleTest">获取数据</el-button>
220
- <el-button @click="handleReset">重置</el-button>
221
- </template>
222
- </cus-dialog>
223
-
224
- <cus-dialog
225
- :visible="uploadVisible"
226
- @on-close="uploadVisible = false"
227
- @on-submit="handleUploadJson"
228
- ref="uploadJson"
229
- width="800px"
230
- form
231
- >
232
- <el-alert
233
- type="info"
234
- title="JSON格式如下,直接复制生成的json覆盖此处代码点击确定即可"
235
- ></el-alert>
236
- <div id="uploadeditor" style="height: 400px;width: 100%;">
237
- {{ jsonEg }}
238
- </div>
239
- </cus-dialog>
240
-
241
- <cus-dialog
242
- :visible="jsonVisible"
243
- @on-close="jsonVisible = false"
244
- ref="jsonPreview"
245
- width="800px"
246
- form
247
- >
248
- <div id="jsoneditor" style="height: 400px;width: 100%;">
249
- {{ jsonTemplate }}
250
- </div>
251
-
252
- <template slot="action">
253
- <el-button
254
- type="primary"
255
- class="json-btn"
256
- :data-clipboard-text="jsonCopyValue"
257
- >复制数据</el-button
258
- >
259
- </template>
260
- </cus-dialog>
261
-
262
- <cus-dialog
263
- :visible="codeVisible"
264
- @on-close="codeVisible = false"
265
- ref="codePreview"
266
- width="800px"
267
- form
268
- :action="false"
269
- >
270
- <!-- <div id="codeeditor" style="height: 500px; width: 100%;">{{htmlTemplate}}</div> -->
271
- <el-tabs
272
- type="border-card"
273
- style="box-shadow: none;"
274
- v-model="codeActiveName"
275
- >
276
- <el-tab-pane label="Vue Component" name="vue">
277
- <div id="vuecodeeditor" style="height: 500px; width: 100%;">
278
- {{ vueTemplate }}
279
- </div>
280
- </el-tab-pane>
281
- <el-tab-pane label="HTML" name="html">
282
- <div id="codeeditor" style="height: 500px; width: 100%;">
283
- {{ htmlTemplate }}
284
- </div>
285
- </el-tab-pane>
286
- </el-tabs>
287
- </cus-dialog>
288
- </el-container>
289
- </el-main>
290
- <!-- <el-footer height="30px" style="font-weight: 600;"
291
- >Powered by
292
- <a target="_blank" href="https://github.com/GavinZhuLei/vue-form-making"
293
- >vue-form-making</a
294
- ></el-footer
295
- > -->
296
- </el-container>
297
- </div>
298
- </template>
299
-
300
- <script>
301
- import Draggable from "vuedraggable";
302
- import Clipboard from "clipboard";
303
- import WidgetConfig from "./WidgetConfig";
304
- import FormConfig from "./FormConfig";
305
- import WidgetForm from "./WidgetForm";
306
- import CusDialog from "./CusDialog";
307
- import GenerateForm from "./GenerateForm";
308
- import {
309
- basicComponents,
310
- layoutComponents,
311
- advanceComponents
312
- } from "./componentsConfig.js";
313
- // import {loadJs, loadCss} from '../util/index.js'
314
- import request from "./util/request";
315
- import generateCode from "./generateCode.js";
316
-
317
- export default {
318
- name: "fm-making-form",
319
- components: {
320
- Draggable,
321
- WidgetConfig,
322
- FormConfig,
323
- WidgetForm,
324
- CusDialog,
325
- GenerateForm
326
- },
327
- props: {
328
- preview: {
329
- type: Boolean,
330
- default: false
331
- },
332
- generateCode: {
333
- type: Boolean,
334
- default: false
335
- },
336
- generateJson: {
337
- type: Boolean,
338
- default: false
339
- },
340
- upload: {
341
- type: Boolean,
342
- default: false
343
- },
344
- clearable: {
345
- type: Boolean,
346
- default: false
347
- },
348
- basicFields: {
349
- type: Array,
350
- default: () => [
351
- "input",
352
- "textarea",
353
- "number",
354
- "radio",
355
- "checkbox",
356
- "time",
357
- "date",
358
- "rate",
359
- "color",
360
- "select",
361
- "switch",
362
- "slider",
363
- "text"
364
- ]
365
- },
366
- advanceFields: {
367
- type: Array,
368
- default: () => ["blank", "imgupload", "editor", "cascader"]
369
- },
370
- layoutFields: {
371
- type: Array,
372
- default: () => ["grid"]
373
- }
374
- },
375
- data() {
376
- return {
377
- basicComponents,
378
- layoutComponents,
379
- advanceComponents,
380
- resetJson: false,
381
- widgetForm: {
382
- list: [],
383
- config: {
384
- labelWidth: 100,
385
- labelPosition: "right",
386
- size: "small"
387
- }
388
- },
389
- configTab: "widget",
390
- widgetFormSelect: null,
391
- previewVisible: false,
392
- jsonVisible: false,
393
- codeVisible: false,
394
- uploadVisible: false,
395
- remoteFuncs: {
396
- func_test(resolve) {
397
- setTimeout(() => {
398
- const options = [
399
- { id: "1", name: "1111" },
400
- { id: "2", name: "2222" },
401
- { id: "3", name: "3333" }
402
- ];
403
-
404
- resolve(options);
405
- }, 2000);
406
- },
407
- funcGetToken(resolve) {
408
- request
409
- .get("http://tools-server.making.link/api/uptoken")
410
- .then(res => {
411
- resolve(res.uptoken);
412
- });
413
- },
414
- upload_callback(response, file, fileList) {
415
- console.log("callback", response, file, fileList);
416
- }
417
- },
418
- widgetModels: {},
419
- blank: "",
420
- htmlTemplate: "",
421
- vueTemplate: "",
422
- jsonTemplate: "",
423
- uploadEditor: null,
424
- jsonCopyValue: "",
425
- jsonClipboard: null,
426
- jsonEg: `{
427
- "list": [],
428
- "config": {
429
- "labelWidth": 100,
430
- "labelPosition": "top",
431
- "size": "small"
432
- }
433
- }`,
434
- codeActiveName: "vue"
435
- };
436
- },
437
- mounted() {
438
- // this._loadComponents();
439
- },
440
- methods: {
441
- // _loadComponents() {
442
- // this.basicComponents = this.basicComponents.map(item => {
443
- // return {
444
- // ...item,
445
- // name: this.$t(`fm.components.fields.${item.type}`)
446
- // };
447
- // });
448
- // this.advanceComponents = this.advanceComponents.map(item => {
449
- // return {
450
- // ...item,
451
- // name: this.$t(`fm.components.fields.${item.type}`)
452
- // };
453
- // });
454
- // this.layoutComponents = this.layoutComponents.map(item => {
455
- // return {
456
- // ...item,
457
- // name: this.$t(`fm.components.fields.${item.type}`)
458
- // };
459
- // });
460
- // },
461
- handleGoGithub() {
462
- window.location.href = "https://github.com/GavinZhuLei/vue-form-making";
463
- },
464
- handleConfigSelect(value) {
465
- this.configTab = value;
466
- },
467
- handleMoveEnd(evt) {
468
- // console.log("end", evt);
469
- },
470
- handleMoveStart({ oldIndex }) {
471
- // console.log("start", oldIndex, this.basicComponents);
472
- },
473
- handleMove() {
474
- return true;
475
- },
476
- handlePreview() {
477
- // console.log(this.widgetForm);
478
- this.previewVisible = true;
479
- },
480
- handleTest() {
481
- this.$refs.generateForm
482
- .getData()
483
- .then(data => {
484
- this.$alert(data, "").catch(e => {});
485
- this.$refs.widgetPreview.end();
486
- })
487
- .catch(e => {
488
- this.$refs.widgetPreview.end();
489
- });
490
- },
491
- handleReset() {
492
- this.$refs.generateForm.reset();
493
- },
494
- handleGenerateJson() {
495
- this.jsonVisible = true;
496
- this.jsonTemplate = this.widgetForm;
497
- console.log(JSON.stringify(this.widgetForm));
498
- this.$nextTick(() => {
499
- const editor = ace.edit("jsoneditor");
500
- editor.session.setMode("ace/mode/json");
501
-
502
- if (!this.jsonClipboard) {
503
- this.jsonClipboard = new Clipboard(".json-btn");
504
- this.jsonClipboard.on("success", e => {
505
- this.$message.success("复制成功");
506
- });
507
- }
508
- this.jsonCopyValue = JSON.stringify(this.widgetForm);
509
- });
510
- },
511
- handleGenerateCode() {
512
- this.codeVisible = true;
513
- this.htmlTemplate = generateCode(JSON.stringify(this.widgetForm), "html");
514
- this.vueTemplate = generateCode(JSON.stringify(this.widgetForm), "vue");
515
- this.$nextTick(() => {
516
- const editor = ace.edit("codeeditor");
517
- editor.session.setMode("ace/mode/html");
518
-
519
- const vueeditor = ace.edit("vuecodeeditor");
520
- vueeditor.session.setMode("ace/mode/html");
521
- });
522
- },
523
- handleUpload() {
524
- this.uploadVisible = true;
525
- this.$nextTick(() => {
526
- this.uploadEditor = ace.edit("uploadeditor");
527
- this.uploadEditor.session.setMode("ace/mode/json");
528
- });
529
- },
530
- handleUploadJson() {
531
- try {
532
- this.setJSON(JSON.parse(this.uploadEditor.getValue()));
533
- this.uploadVisible = false;
534
- } catch (e) {
535
- this.$message.error(e.message);
536
- this.$refs.uploadJson.end();
537
- }
538
- },
539
- handleClear() {
540
- this.widgetForm = {
541
- list: [],
542
- config: {
543
- labelWidth: 100,
544
- labelPosition: "right",
545
- size: "small",
546
- customClass: ""
547
- }
548
- };
549
-
550
- this.widgetFormSelect = {};
551
- },
552
- clear() {
553
- this.handleClear();
554
- },
555
- getJSON() {
556
- return this.widgetForm;
557
- },
558
- getHtml() {
559
- return generateCode(JSON.stringify(this.widgetForm));
560
- },
561
- setJSON(json) {
562
- this.widgetForm = json;
563
-
564
- if (json.list.length > 0) {
565
- this.widgetFormSelect = json.list[0];
566
- }
567
- },
568
- handleInput(val) {
569
- // console.log(val);
570
- this.blank = val;
571
- },
572
- handleDataChange(field, value, data) {
573
- // console.log(field, value, data);
574
- }
575
- },
576
- watch: {
577
- widgetForm: {
578
- deep: true,
579
- handler: function(val) {
580
- // console.log(this.$refs.widgetForm);
581
- }
582
- },
583
- $lang: function(val) {
584
- this._loadComponents();
585
- }
586
- }
587
- };
588
- </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
+ @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>