tianheng-ui 0.0.45 → 0.0.48

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