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,14 +1,27 @@
1
1
  <template>
2
2
  <el-form-item
3
- class="widget-view "
3
+ class="widget-view"
4
4
  v-if="element && element.key"
5
5
  :class="{
6
6
  active: selectWidget.key == element.key,
7
- is_req: element.options.required
7
+ is_req: element.options.required,
8
+ 'widget-col': ['grid','tabs','table'].includes(element.type),
9
+ [element.model]: true
8
10
  }"
9
- :label="element.name"
11
+ :label="
12
+ data.type == 'table' || element.options.hideLabel ? '' : element.name
13
+ "
14
+ :label-width="
15
+ element.options.hideLabel
16
+ ? '0'
17
+ : element.options.isLabelWidth
18
+ ? `${element.options.labelWidth}px`
19
+ : ''
20
+ "
10
21
  @click.native.stop="handleSelectWidget(index)"
11
22
  >
23
+ <div v-if="data.type == 'table'">{{ element.name || "-" }}</div>
24
+
12
25
  <template v-if="element.type == 'input'">
13
26
  <el-input
14
27
  v-model="element.options.defaultValue"
@@ -41,7 +54,10 @@
41
54
  :maxlength="element.options.maxlength"
42
55
  :show-word-limit="element.options.showWordLimit"
43
56
  :clearable="element.options.clearable"
44
- :autosize="{ minRows: element.options.minRows, maxRows: element.options.maxRows }"
57
+ :autosize="{
58
+ minRows: element.options.minRows,
59
+ maxRows: element.options.maxRows
60
+ }"
45
61
  ></el-input>
46
62
  </template>
47
63
 
@@ -49,7 +65,7 @@
49
65
  <el-input-number
50
66
  v-model="element.options.defaultValue"
51
67
  :disabled="element.options.disabled"
52
- :controls-position="element.options.controlsPosition?'right':''"
68
+ :controls-position="element.options.controlsPosition ? 'right' : ''"
53
69
  :style="{ width: element.options.width }"
54
70
  :min="element.options.min"
55
71
  :max="element.options.max"
@@ -150,7 +166,11 @@
150
166
  <el-time-select
151
167
  v-model="element.options.selectStartTime"
152
168
  :is-range="element.options.isRange"
153
- :placeholder="element.options.selectRange?element.options.startPlaceholder:element.options.placeholder"
169
+ :placeholder="
170
+ element.options.selectRange
171
+ ? element.options.startPlaceholder
172
+ : element.options.placeholder
173
+ "
154
174
  :readonly="element.options.readonly"
155
175
  :disabled="element.options.disabled"
156
176
  :editable="element.options.editable"
@@ -223,7 +243,9 @@
223
243
  :clearable="element.options.clearable"
224
244
  :placeholder="element.options.placeholder"
225
245
  :style="{ width: element.options.width }"
226
- :filterable="element.options.allowCreate?true:element.options.filterable"
246
+ :filterable="
247
+ element.options.allowCreate ? true : element.options.filterable
248
+ "
227
249
  >
228
250
  <el-option
229
251
  v-for="item in element.options.options"
@@ -255,9 +277,14 @@
255
277
  :step="element.options.step"
256
278
  :show-input="element.options.showInput"
257
279
  :range="element.options.range"
258
- :style="{ width: element.options.width, height: element.options.height }"
280
+ :style="{
281
+ width: element.options.width,
282
+ height: element.options.height
283
+ }"
259
284
  :show-tooltip="element.options.showTooltip"
260
- :format-tooltip="(val) => formatTooltip(val,element.options.formatTooltip)"
285
+ :format-tooltip="
286
+ val => formatTooltip(val, element.options.formatTooltip)
287
+ "
261
288
  :show-stops="element.options.showStops"
262
289
  :vertical="element.options.vertical"
263
290
  ></el-slider>
@@ -278,7 +305,9 @@
278
305
  <el-upload
279
306
  class="upload-demo"
280
307
  :action="element.options.remoteFunc"
281
- :on-preview="(file) => handlePictureCardPreview(file, element.options.listType)"
308
+ :on-preview="
309
+ file => handlePictureCardPreview(file, element.options.listType)
310
+ "
282
311
  :on-remove="handleRemove"
283
312
  :multiple="element.options.multiple"
284
313
  :limit="element.options.length"
@@ -289,12 +318,34 @@
289
318
  :drag="element.options.drag"
290
319
  :on-change="handleAvatar"
291
320
  :on-error="handleAvatarError"
292
- :disabled="element.options.disabled">
293
- <el-button size="small" type="primary" :disabled="element.options.disabled" v-if="['default', 'picture'].includes(element.options.listType) && !element.options.drag">点击上传</el-button>
294
- <i slot="default" class="el-icon-plus" v-if="element.options.listType === 'picture-card' && !element.options.drag"></i>
321
+ :disabled="element.options.disabled"
322
+ >
323
+ <el-button
324
+ size="small"
325
+ type="primary"
326
+ :disabled="element.options.disabled"
327
+ v-if="
328
+ ['default', 'picture'].includes(element.options.listType) &&
329
+ !element.options.drag
330
+ "
331
+ >点击上传</el-button
332
+ >
333
+ <i
334
+ slot="default"
335
+ class="el-icon-plus"
336
+ v-if="
337
+ element.options.listType === 'picture-card' && !element.options.drag
338
+ "
339
+ ></i>
295
340
  <i class="el-icon-upload" v-if="element.options.drag"></i>
296
- <div class="el-upload__text" v-if="element.options.drag">将文件拖到此处,或<em>点击上传</em></div>
297
- <div slot="tip" class="el-upload__tip" v-html="element.options.elUploadTip"></div>
341
+ <div class="el-upload__text" v-if="element.options.drag">
342
+ 将文件拖到此处,或<em>点击上传</em>
343
+ </div>
344
+ <div
345
+ slot="tip"
346
+ class="el-upload__tip"
347
+ v-html="element.options.elUploadTip"
348
+ ></div>
298
349
  </el-upload>
299
350
  </template>
300
351
 
@@ -307,7 +358,7 @@
307
358
  :style="{ width: element.options.width }"
308
359
  :options="element.options.remoteOptions"
309
360
  :props="element.options.props"
310
- :show-all-levels="element.options.showAllLevels?false:true"
361
+ :show-all-levels="element.options.showAllLevels ? false : true"
311
362
  :collapse-tags="element.options.collapseTags"
312
363
  >
313
364
  <template slot-scope="{ data }">
@@ -321,7 +372,10 @@
321
372
  <template v-if="element.type == 'editor'">
322
373
  <vue-editor
323
374
  v-model="element.options.defaultValue"
324
- :style="{ width: element.options.width, height: element.options.height }"
375
+ :style="{
376
+ width: element.options.width,
377
+ height: element.options.height
378
+ }"
325
379
  :disabled="element.options.disabled"
326
380
  >
327
381
  </vue-editor>
@@ -339,6 +393,127 @@
339
393
  <span>{{ element.options.defaultValue }}</span>
340
394
  </template>
341
395
 
396
+ <template v-if="element.type == 'grid'">
397
+ <el-row
398
+ type="flex"
399
+ :class="{ active: selectWidget.key == element.key }"
400
+ :gutter="element.options.gutter ? element.options.gutter : 0"
401
+ :justify="element.options.justify"
402
+ :align="element.options.align"
403
+ @click.native="handleSelectWidget(index)"
404
+ >
405
+ <el-col
406
+ v-for="(col, colIndex) in element.columns"
407
+ :key="colIndex"
408
+ :span="col.span ? col.span : 0"
409
+ >
410
+ <draggable
411
+ v-model="col.list"
412
+ :no-transition-on-drag="true"
413
+ v-bind="{
414
+ group: 'people',
415
+ ghostClass: 'ghost',
416
+ animation: 200,
417
+ handle: '.drag-widget'
418
+ }"
419
+ @end="handleMoveEnd"
420
+ @add="handleWidgetColAdd($event, element, colIndex)"
421
+ >
422
+ <transition-group name="fade" tag="div" class="widget-col-list">
423
+ <template v-for="(el, i) in col.list">
424
+ <widget-form-item
425
+ :key="el.key"
426
+ v-if="el.key"
427
+ :element="el"
428
+ :select.sync="selectWidget"
429
+ :index="i"
430
+ :data="col"
431
+ >
432
+ </widget-form-item>
433
+ </template>
434
+ </transition-group>
435
+ </draggable>
436
+ </el-col>
437
+ </el-row>
438
+ </template>
439
+
440
+ <template v-if="element.type == 'table'">
441
+ <draggable
442
+ v-model="element.list"
443
+ :no-transition-on-drag="true"
444
+ v-bind="{
445
+ group: 'people',
446
+ ghostClass: 'ghost',
447
+ animation: 200,
448
+ handle: '.drag-widget'
449
+ }"
450
+ @end="handleMoveEnd"
451
+ @add="handleWidgetTableAdd($event, element)"
452
+ >
453
+ <transition-group name="fade" tag="div" class="widget-table-list">
454
+ <template v-for="(el, i) in element.list">
455
+ <widget-form-item
456
+ class="widget-table-list-item"
457
+ :key="el.key"
458
+ v-if="el.key"
459
+ :element="el"
460
+ :select.sync="selectWidget"
461
+ :index="i"
462
+ :data="element"
463
+ >
464
+ </widget-form-item>
465
+ </template>
466
+ </transition-group>
467
+ </draggable>
468
+ </template>
469
+
470
+ <template v-if="element.type == 'tabs'">
471
+ <el-tabs
472
+ v-model="element.options.defaultValue"
473
+ :type="element.options.type"
474
+ :tab-position="element.options.tabPosition"
475
+ >
476
+ <el-tab-pane
477
+ v-for="(tabItem, tabIndex) in element.tabs"
478
+ :key="tabItem.value"
479
+ :label="tabItem.label"
480
+ :name="tabItem.value"
481
+ >
482
+ <draggable
483
+ v-model="tabItem.list"
484
+ :no-transition-on-drag="true"
485
+ v-bind="{
486
+ group: 'people',
487
+ ghostClass: 'ghost',
488
+ animation: 200,
489
+ handle: '.drag-widget'
490
+ }"
491
+ @end="handleMoveEnd"
492
+ @add="handleWidgetTabAdd($event, element, tabIndex)"
493
+ >
494
+ <transition-group name="fade" tag="div" class="widget-col-list">
495
+ <template v-for="(el, i) in tabItem.list">
496
+ <widget-form-item
497
+ v-if="el && el.key"
498
+ :key="el.key"
499
+ :element="el"
500
+ :select.sync="selectWidget"
501
+ :index="i"
502
+ :data="tabItem"
503
+ ></widget-form-item>
504
+ </template>
505
+ </transition-group>
506
+ </draggable>
507
+ </el-tab-pane>
508
+ </el-tabs>
509
+ </template>
510
+
511
+ <template v-if="element.type == 'divider'">
512
+ <el-divider :content-position="element.options.contentPosition">
513
+ {{ element.name }}
514
+ </el-divider>
515
+ </template>
516
+
342
517
  <div class="widget-view-action" v-if="selectWidget.key == element.key">
343
518
  <i
344
519
  class="iconfont icon-icon_clone"
@@ -355,28 +530,32 @@
355
530
  </div>
356
531
 
357
532
  <el-dialog :visible.sync="dialogVisible">
358
- <img width="100%" :src="dialogImageUrl" alt="">
533
+ <img width="100%" :src="dialogImageUrl" alt="" />
359
534
  </el-dialog>
360
535
  </el-form-item>
361
536
  </template>
362
537
 
363
538
  <script>
539
+ import Draggable from "vuedraggable";
364
540
  import FmUpload from "./Upload";
365
- import { VueEditor} from "vue2-editor";
541
+ import { VueEditor } from "vue2-editor";
366
542
  export default {
543
+ name: "widget-form-item",
367
544
  props: ["element", "select", "index", "data"],
368
- components: {
369
- FmUpload,
370
- VueEditor
371
- },
545
+ components: { Draggable, FmUpload, VueEditor },
372
546
  data() {
373
547
  return {
374
548
  selectWidget: this.select,
375
549
  dialogVisible: false,
376
- dialogImageUrl: '',
550
+ dialogImageUrl: "",
551
+ config: {}
377
552
  };
378
553
  },
379
- mounted() {},
554
+ mounted() {
555
+ if (this.element.type == "tabs") {
556
+ this.config[this.element.model] = this.element.options.defaultValue;
557
+ }
558
+ },
380
559
  methods: {
381
560
  handleSelectWidget(index) {
382
561
  this.selectWidget = this.data.list[index];
@@ -435,21 +614,194 @@ export default {
435
614
  this.selectWidget = this.data.list[index + 1];
436
615
  });
437
616
  },
438
- handlePictureCardPreview(file, listType) {
439
- if(listType === "picture-card"){
617
+ handlePictureCardPreview(file, listType) {
618
+ if (listType === "picture-card") {
440
619
  this.dialogImageUrl = file.url;
441
620
  this.dialogVisible = true;
442
621
  }
443
622
  },
444
623
  handleRemove(file, fileList) {
445
- this.data.options.defaultValue = fileList
624
+ this.data.options.defaultValue = fileList;
446
625
  },
447
626
  handleAvatar(res, file) {
448
- this.data.options.defaultValue = file
627
+ this.data.options.defaultValue = file;
449
628
  },
450
629
  handleAvatarError() {
451
- console.log("上传失败!")
630
+ console.log("上传失败!");
452
631
  },
632
+ handleMoveEnd({ newIndex, oldIndex }) {},
633
+ handleWidgetColAdd($event, row, colIndex) {
634
+ const newIndex = $event.newIndex;
635
+ const oldIndex = $event.oldIndex;
636
+ const item = $event.item;
637
+
638
+ // 防止布局元素的嵌套拖拽
639
+ if (item.className.indexOf("data-grid") >= 0) {
640
+ // 如果是列表中拖拽的元素需要还原到原来位置
641
+ item.tagName === "DIV" &&
642
+ this.data.list.splice(
643
+ oldIndex,
644
+ 0,
645
+ row.columns[colIndex].list[newIndex]
646
+ );
647
+
648
+ row.columns[colIndex].list.splice(newIndex, 1);
649
+
650
+ return false;
651
+ }
652
+
653
+ const key =
654
+ Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
655
+
656
+ this.$set(row.columns[colIndex].list, newIndex, {
657
+ ...row.columns[colIndex].list[newIndex],
658
+ options: {
659
+ ...row.columns[colIndex].list[newIndex].options
660
+ // remoteFunc: "func_" + key
661
+ },
662
+ key,
663
+ // 绑定键值
664
+ model: row.columns[colIndex].list[newIndex].type + "_" + key,
665
+ rules: []
666
+ });
667
+
668
+ if (
669
+ row.columns[colIndex].list[newIndex].type === "radio" ||
670
+ row.columns[colIndex].list[newIndex].type === "checkbox" ||
671
+ row.columns[colIndex].list[newIndex].type === "select"
672
+ ) {
673
+ this.$set(row.columns[colIndex].list, newIndex, {
674
+ ...row.columns[colIndex].list[newIndex],
675
+ options: {
676
+ ...row.columns[colIndex].list[newIndex].options,
677
+ options: row.columns[colIndex].list[newIndex].options.options.map(
678
+ item => ({
679
+ ...item
680
+ })
681
+ )
682
+ }
683
+ });
684
+ }
685
+
686
+ this.selectWidget = row.columns[colIndex].list[newIndex];
687
+ },
688
+ handleWidgetTabAdd($event, row, colIndex) {
689
+ console.log(row, colIndex);
690
+ const newIndex = $event.newIndex;
691
+ const oldIndex = $event.oldIndex;
692
+ const item = $event.item;
693
+
694
+ // 防止布局元素的嵌套拖拽
695
+ if (item.className.indexOf("data-grid") >= 0) {
696
+ // 如果是列表中拖拽的元素需要还原到原来位置
697
+ item.tagName === "DIV" &&
698
+ this.data.list.splice(oldIndex, 0, row.tabs[colIndex].list[newIndex]);
699
+
700
+ row.tabs[colIndex].list.splice(newIndex, 1);
701
+
702
+ return false;
703
+ }
704
+
705
+ const key =
706
+ Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
707
+
708
+ this.$set(row.tabs[colIndex].list, newIndex, {
709
+ ...row.tabs[colIndex].list[newIndex],
710
+ options: {
711
+ ...row.tabs[colIndex].list[newIndex].options
712
+ // remoteFunc: "func_" + key
713
+ },
714
+ key,
715
+ // 绑定键值
716
+ model: row.tabs[colIndex].list[newIndex].type + "_" + key,
717
+ rules: []
718
+ });
719
+
720
+ if (
721
+ row.tabs[colIndex].list[newIndex].type === "radio" ||
722
+ row.tabs[colIndex].list[newIndex].type === "checkbox" ||
723
+ row.tabs[colIndex].list[newIndex].type === "select"
724
+ ) {
725
+ this.$set(row.tabs[colIndex].list, newIndex, {
726
+ ...row.tabs[colIndex].list[newIndex],
727
+ options: {
728
+ ...row.tabs[colIndex].list[newIndex].options,
729
+ options: row.tabs[colIndex].list[newIndex].options.options.map(
730
+ item => ({
731
+ ...item
732
+ })
733
+ )
734
+ }
735
+ });
736
+ }
737
+
738
+ if (row.tabs[colIndex].list[newIndex].type === "grid") {
739
+ this.$set(
740
+ row.tabs[colIndex].list,
741
+ newIndex,
742
+ JSON.parse(JSON.stringify(row.tabs[colIndex].list[newIndex]))
743
+ );
744
+ }
745
+
746
+ if (row.tabs[colIndex].list[newIndex].type === "table") {
747
+ this.$set(row.tabs[colIndex].list, newIndex, {
748
+ ...row.tabs[colIndex].list[newIndex],
749
+ list: row.tabs[colIndex].list[newIndex].list.map(item => ({
750
+ ...item
751
+ }))
752
+ });
753
+ }
754
+
755
+ this.selectWidget = row.tabs[colIndex].list[newIndex];
756
+ },
757
+ handleWidgetTableAdd($event, row) {
758
+ const newIndex = $event.newIndex;
759
+ const oldIndex = $event.oldIndex;
760
+ const item = $event.item;
761
+ // 防止布局元素的嵌套拖拽
762
+ if (item.className.indexOf("no-put") >= 0) {
763
+ // 如果是列表中拖拽的元素需要还原到原来位置
764
+ item.tagName === "DIV" &&
765
+ this.data.list.splice(oldIndex, 0, row.list[newIndex]);
766
+
767
+ row.list.splice(newIndex, 1);
768
+
769
+ return false;
770
+ }
771
+
772
+ const key =
773
+ Date.parse(new Date()) + "_" + Math.ceil(Math.random() * 99999);
774
+
775
+ this.$set(row.list, newIndex, {
776
+ ...row.list[newIndex],
777
+ options: {
778
+ ...row.list[newIndex].options
779
+ // remoteFunc: "func_" + key
780
+ },
781
+ key,
782
+ // 绑定键值
783
+ model: row.list[newIndex].type + "_" + key,
784
+ rules: []
785
+ });
786
+
787
+ if (
788
+ row.list[newIndex].type === "radio" ||
789
+ row.list[newIndex].type === "checkbox" ||
790
+ row.list[newIndex].type === "select"
791
+ ) {
792
+ this.$set(row.list, newIndex, {
793
+ ...row.list[newIndex],
794
+ options: {
795
+ ...row.list[newIndex].options,
796
+ options: row.list[newIndex].options.options.map(item => ({
797
+ ...item
798
+ }))
799
+ }
800
+ });
801
+ }
802
+
803
+ this.selectWidget = row.list[newIndex];
804
+ }
453
805
  },
454
806
  watch: {
455
807
  select(val) {