zartui 2.1.20 → 2.1.21

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.
@@ -37,6 +37,7 @@ var _Img = require("./image/Img64");
37
37
  var _mediaUtil = require("./media-util");
38
38
  var _device = require("../utils/device");
39
39
  var _wxUtil = require("./wx-util");
40
+ var _sortablejs = _interopRequireDefault(require("sortablejs"));
40
41
  // Utils
41
42
 
42
43
  // Types
@@ -188,6 +189,10 @@ var _default2 = exports.default = createComponent({
188
189
  default: function _default() {
189
190
  return {};
190
191
  }
192
+ },
193
+ sortable: {
194
+ type: Boolean,
195
+ default: false
191
196
  }
192
197
  },
193
198
  model: {
@@ -201,7 +206,8 @@ var _default2 = exports.default = createComponent({
201
206
  actionVisible: false,
202
207
  mediaPlayerVisible: false,
203
208
  mediaTypeToPlay: '',
204
- mediaUrlToPlay: ''
209
+ mediaUrlToPlay: '',
210
+ sort: undefined
205
211
  };
206
212
  },
207
213
  computed: {
@@ -249,11 +255,36 @@ var _default2 = exports.default = createComponent({
249
255
  }
250
256
  }];
251
257
  }
258
+ },
259
+ showPreview: function showPreview() {
260
+ return this.mediaList.length > 0 && this.pickerMode !== "certificate";
261
+ }
262
+ },
263
+ watch: {
264
+ showPreview: function showPreview() {
265
+ var _this$$refs$grid,
266
+ _this2 = this;
267
+ if (this.sort || !this.sortable) return;
268
+ this.sort = _sortablejs.default.create((_this$$refs$grid = this.$refs.grid) == null ? void 0 : _this$$refs$grid.$el, {
269
+ animation: 200,
270
+ handle: ".zt2-grid-item",
271
+ onEnd: function onEnd(evt) {
272
+ var raws = _this2.exchangeArrayIndex(_this2.mediaList, evt.oldIndex, evt.newIndex);
273
+ _this2.$emit('input', raws);
274
+ }
275
+ });
252
276
  }
253
277
  },
254
278
  methods: {
279
+ exchangeArrayIndex: function exchangeArrayIndex(list, index, newIndex) {
280
+ var raws = [].concat(list);
281
+ var raw = raws[index];
282
+ raws.splice(index, 1);
283
+ raws.splice(newIndex, 0, raw);
284
+ return [].concat(raws);
285
+ },
255
286
  mediaPick: function mediaPick(mediaType, mediaAddType) {
256
- var _this2 = this;
287
+ var _this3 = this;
257
288
  if (this.disabled) {
258
289
  return;
259
290
  }
@@ -275,7 +306,7 @@ var _default2 = exports.default = createComponent({
275
306
  if (this.useWx && (0, _device.isWeixin)() && window.wx) {
276
307
  var type = mediaAddType === _type.MediaAddType.TAKE ? 'camera' : 'album';
277
308
  (0, _wxUtil.wxUploadImage)(type).then(function (newMedias) {
278
- _this2.$emit('input', [].concat(_this2.mediaList, newMedias));
309
+ _this3.$emit('input', [].concat(_this3.mediaList, newMedias));
279
310
  });
280
311
  } else {
281
312
  if (mediaAddType === _type.MediaAddType.TAKE) {
@@ -350,7 +381,7 @@ var _default2 = exports.default = createComponent({
350
381
  }
351
382
  },
352
383
  handleInputFiles: function handleInputFiles(event) {
353
- var _this3 = this;
384
+ var _this4 = this;
354
385
  return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
355
386
  var files, response, data;
356
387
  return _regenerator.default.wrap(function _callee$(_context) {
@@ -363,29 +394,29 @@ var _default2 = exports.default = createComponent({
363
394
  }
364
395
  return _context.abrupt("return");
365
396
  case 3:
366
- if (_this3.pickerMode === "certificate") {
397
+ if (_this4.pickerMode === "certificate") {
367
398
  files = [files[0]];
368
399
  }
369
- files = _this3.filterValidFiles(files);
400
+ files = _this4.filterValidFiles(files);
370
401
  if (!(files.length === 0)) {
371
402
  _context.next = 7;
372
403
  break;
373
404
  }
374
405
  return _context.abrupt("return");
375
406
  case 7:
376
- if (_this3.checkFileCountAfterAdd(files)) {
407
+ if (_this4.checkFileCountAfterAdd(files)) {
377
408
  _context.next = 9;
378
409
  break;
379
410
  }
380
411
  return _context.abrupt("return");
381
412
  case 9:
382
- if (!_this3.beforeRead) {
413
+ if (!_this4.beforeRead) {
383
414
  _context.next = 24;
384
415
  break;
385
416
  }
386
417
  _context.prev = 10;
387
418
  _context.next = 13;
388
- return _this3.beforeRead(files);
419
+ return _this4.beforeRead(files);
389
420
  case 13:
390
421
  response = _context.sent;
391
422
  if (response) {
@@ -398,9 +429,9 @@ var _default2 = exports.default = createComponent({
398
429
  data = response.filter(function (item) {
399
430
  return !!item;
400
431
  });
401
- _this3.readFiles(data);
432
+ _this4.readFiles(data);
402
433
  } else {
403
- _this3.readFiles(files);
434
+ _this4.readFiles(files);
404
435
  }
405
436
  _context.next = 22;
406
437
  break;
@@ -412,7 +443,7 @@ var _default2 = exports.default = createComponent({
412
443
  _context.next = 25;
413
444
  break;
414
445
  case 24:
415
- _this3.readFiles(files);
446
+ _this4.readFiles(files);
416
447
  case 25:
417
448
  case "end":
418
449
  return _context.stop();
@@ -421,12 +452,12 @@ var _default2 = exports.default = createComponent({
421
452
  }))();
422
453
  },
423
454
  readFiles: function readFiles(files) {
424
- var _this4 = this;
455
+ var _this5 = this;
425
456
  // 处理非图片
426
457
  var notImages = files.filter(function (f) {
427
458
  return !(0, _mediaUtil.isImageType)(f);
428
459
  }).map(function (f) {
429
- return _this4.transformNotImageFile(f);
460
+ return _this5.transformNotImageFile(f);
430
461
  });
431
462
  var newMedias = [];
432
463
  if (notImages.length > 0) {
@@ -447,13 +478,13 @@ var _default2 = exports.default = createComponent({
447
478
  newMedias = newMedias.concat(medias);
448
479
  }
449
480
  }).finally(function () {
450
- if (_this4.pickerMode === "certificate") {
451
- _this4.$emit('input', [].concat(newMedias));
481
+ if (_this5.pickerMode === "certificate") {
482
+ _this5.$emit('input', [].concat(newMedias));
452
483
  } else {
453
- _this4.$emit('input', [].concat(_this4.mediaList, newMedias));
484
+ _this5.$emit('input', [].concat(_this5.mediaList, newMedias));
454
485
  }
455
- if (_this4.afterRead) {
456
- _this4.afterRead(newMedias);
486
+ if (_this5.afterRead) {
487
+ _this5.afterRead(newMedias);
457
488
  }
458
489
  });
459
490
  },
@@ -541,24 +572,24 @@ var _default2 = exports.default = createComponent({
541
572
  * @return {Promise<[Media]>}
542
573
  */
543
574
  transformImageFiles: function transformImageFiles(files) {
544
- var _this5 = this;
575
+ var _this6 = this;
545
576
  var promisesTodo = [];
546
577
  var resizeOptions = new _appMediaUtils.ResizeOptions(this.maxImageSideLength);
547
578
  var compressOptions = new _appMediaUtils.CompressOptions(this.maxImageFileSize);
548
579
  var _loop = function _loop() {
549
580
  var inputFile = files[i];
550
- var watermarkEnabled = _this5.watermarkOptions && _this5.watermarkOptions.watermarkConfigString && (0, _appMediaUtils.checkWatermarkConfigSupported)(_this5.watermarkOptions.watermarkConfigString);
581
+ var watermarkEnabled = _this6.watermarkOptions && _this6.watermarkOptions.watermarkConfigString && (0, _appMediaUtils.checkWatermarkConfigSupported)(_this6.watermarkOptions.watermarkConfigString);
551
582
  var watermarkOpt;
552
583
  if (watermarkEnabled) {
553
584
  watermarkOpt = new _appMediaUtils.WatermarkOptions({
554
585
  enabled: true,
555
- watermarkConfigString: watermarkEnabled ? _this5.watermarkOptions.watermarkConfigString : '',
586
+ watermarkConfigString: watermarkEnabled ? _this6.watermarkOptions.watermarkConfigString : '',
556
587
  context: {
557
- address: _this5.watermarkOptions.address || "",
558
- humanName: _this5.watermarkOptions.humanName || _this5.watermarkOptions.humanname || "",
559
- projectName: _this5.watermarkOptions.projectName || "",
560
- logo: _this5.watermarkOptions.logo || "",
561
- applicationName: _this5.watermarkOptions.applicationName || "",
588
+ address: _this6.watermarkOptions.address || "",
589
+ humanName: _this6.watermarkOptions.humanName || _this6.watermarkOptions.humanname || "",
590
+ projectName: _this6.watermarkOptions.projectName || "",
591
+ logo: _this6.watermarkOptions.logo || "",
592
+ applicationName: _this6.watermarkOptions.applicationName || "",
562
593
  watermarkTime: new Date()
563
594
  }
564
595
  });
@@ -698,18 +729,18 @@ var _default2 = exports.default = createComponent({
698
729
  }
699
730
  },
700
731
  onDelete: function onDelete(media, index) {
701
- var _this6 = this;
732
+ var _this7 = this;
702
733
  return (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
703
734
  var response;
704
735
  return _regenerator.default.wrap(function _callee2$(_context2) {
705
736
  while (1) switch (_context2.prev = _context2.next) {
706
737
  case 0:
707
- if (!_this6.beforeDelete) {
738
+ if (!_this7.beforeDelete) {
708
739
  _context2.next = 6;
709
740
  break;
710
741
  }
711
742
  _context2.next = 3;
712
- return _this6.beforeDelete(media);
743
+ return _this7.beforeDelete(media);
713
744
  case 3:
714
745
  response = _context2.sent;
715
746
  if (response) {
@@ -718,7 +749,7 @@ var _default2 = exports.default = createComponent({
718
749
  }
719
750
  return _context2.abrupt("return");
720
751
  case 6:
721
- _this6.deleteMedia(media, index);
752
+ _this7.deleteMedia(media, index);
722
753
  case 7:
723
754
  case "end":
724
755
  return _context2.stop();
@@ -733,7 +764,7 @@ var _default2 = exports.default = createComponent({
733
764
  this.$emit('delete', media, index);
734
765
  },
735
766
  hiddenInput: function hiddenInput() {
736
- var _this7 = this;
767
+ var _this8 = this;
737
768
  var h = this.$createElement;
738
769
  return [h("input", {
739
770
  "attrs": {
@@ -746,7 +777,7 @@ var _default2 = exports.default = createComponent({
746
777
  "on": {
747
778
  "change": this.handleInputFiles,
748
779
  "click": function click() {
749
- return _this7.resetInput(_type.MediaType.PHOTO, _type.MediaAddType.TAKE);
780
+ return _this8.resetInput(_type.MediaType.PHOTO, _type.MediaAddType.TAKE);
750
781
  }
751
782
  },
752
783
  "class": bem('hidden')
@@ -760,7 +791,7 @@ var _default2 = exports.default = createComponent({
760
791
  "on": {
761
792
  "change": this.handleInputFiles,
762
793
  "click": function click() {
763
- return _this7.resetInput(_type.MediaType.PHOTO, _type.MediaAddType.PICK);
794
+ return _this8.resetInput(_type.MediaType.PHOTO, _type.MediaAddType.PICK);
764
795
  }
765
796
  },
766
797
  "class": bem('hidden')
@@ -774,7 +805,7 @@ var _default2 = exports.default = createComponent({
774
805
  "on": {
775
806
  "change": this.handleInputFiles,
776
807
  "click": function click() {
777
- return _this7.resetInput(_type.MediaType.VIDEO, _type.MediaAddType.TAKE);
808
+ return _this8.resetInput(_type.MediaType.VIDEO, _type.MediaAddType.TAKE);
778
809
  }
779
810
  },
780
811
  "class": bem('hidden')
@@ -787,7 +818,7 @@ var _default2 = exports.default = createComponent({
787
818
  "on": {
788
819
  "change": this.handleInputFiles,
789
820
  "click": function click() {
790
- return _this7.resetInput(_type.MediaType.VIDEO, _type.MediaAddType.PICK);
821
+ return _this8.resetInput(_type.MediaType.VIDEO, _type.MediaAddType.PICK);
791
822
  }
792
823
  },
793
824
  "class": bem('hidden')
@@ -801,7 +832,7 @@ var _default2 = exports.default = createComponent({
801
832
  "on": {
802
833
  "change": this.handleInputFiles,
803
834
  "click": function click() {
804
- return _this7.resetInput(_type.MediaType.AUDIO, _type.MediaAddType.TAKE);
835
+ return _this8.resetInput(_type.MediaType.AUDIO, _type.MediaAddType.TAKE);
805
836
  }
806
837
  },
807
838
  "class": bem('hidden')
@@ -814,7 +845,7 @@ var _default2 = exports.default = createComponent({
814
845
  "on": {
815
846
  "change": this.handleInputFiles,
816
847
  "click": function click() {
817
- return _this7.resetInput(_type.MediaType.AUDIO, _type.MediaAddType.PICK);
848
+ return _this8.resetInput(_type.MediaType.AUDIO, _type.MediaAddType.PICK);
818
849
  }
819
850
  },
820
851
  "class": bem('hidden')
@@ -827,14 +858,14 @@ var _default2 = exports.default = createComponent({
827
858
  "on": {
828
859
  "change": this.handleInputFiles,
829
860
  "click": function click() {
830
- return _this7.resetInput(_type.MediaType.FILE, _type.MediaAddType.PICK);
861
+ return _this8.resetInput(_type.MediaType.FILE, _type.MediaAddType.PICK);
831
862
  }
832
863
  },
833
864
  "class": bem('hidden')
834
865
  })];
835
866
  },
836
867
  renderIcon: function renderIcon(mediaType, mediaAddType) {
837
- var _this8 = this;
868
+ var _this9 = this;
838
869
  var h = this.$createElement;
839
870
  if (mediaType === _type.MediaType.PHOTO) {
840
871
  if (mediaAddType === _type.MediaAddType.TAKE) {
@@ -842,7 +873,7 @@ var _default2 = exports.default = createComponent({
842
873
  "class": bem('button'),
843
874
  "on": {
844
875
  "click": function click() {
845
- return _this8.mediaPick(mediaType, mediaAddType);
876
+ return _this9.mediaPick(mediaType, mediaAddType);
846
877
  }
847
878
  }
848
879
  });
@@ -851,7 +882,7 @@ var _default2 = exports.default = createComponent({
851
882
  "class": bem('button'),
852
883
  "on": {
853
884
  "click": function click() {
854
- return _this8.mediaPick(mediaType, mediaAddType);
885
+ return _this9.mediaPick(mediaType, mediaAddType);
855
886
  }
856
887
  }
857
888
  });
@@ -861,7 +892,7 @@ var _default2 = exports.default = createComponent({
861
892
  "class": bem('button'),
862
893
  "on": {
863
894
  "click": function click() {
864
- return _this8.mediaPick(mediaType, mediaAddType);
895
+ return _this9.mediaPick(mediaType, mediaAddType);
865
896
  }
866
897
  }
867
898
  });
@@ -870,7 +901,7 @@ var _default2 = exports.default = createComponent({
870
901
  "class": bem('button'),
871
902
  "on": {
872
903
  "click": function click() {
873
- return _this8.mediaPick(mediaType, mediaAddType);
904
+ return _this9.mediaPick(mediaType, mediaAddType);
874
905
  }
875
906
  }
876
907
  });
@@ -879,7 +910,7 @@ var _default2 = exports.default = createComponent({
879
910
  "class": bem('button'),
880
911
  "on": {
881
912
  "click": function click() {
882
- return _this8.mediaPick(mediaType, mediaAddType);
913
+ return _this9.mediaPick(mediaType, mediaAddType);
883
914
  }
884
915
  }
885
916
  });
@@ -920,7 +951,7 @@ var _default2 = exports.default = createComponent({
920
951
  }
921
952
  },
922
953
  renderCertificates: function renderCertificates() {
923
- var _this9 = this;
954
+ var _this10 = this;
924
955
  var h = this.$createElement;
925
956
  if (this.mediaList && this.mediaList.length) {
926
957
  var media = this.mediaList[0];
@@ -930,8 +961,8 @@ var _default2 = exports.default = createComponent({
930
961
  "on": {
931
962
  "click": function click(event) {
932
963
  event.stopPropagation();
933
- _this9.onDelete(media, 0);
934
- _this9.mediaPick(_type.MediaType.PHOTO, _type.MediaAddType.PICK);
964
+ _this10.onDelete(media, 0);
965
+ _this10.mediaPick(_type.MediaType.PHOTO, _type.MediaAddType.PICK);
935
966
  }
936
967
  }
937
968
  }, [h(_ReUpload.default, {
@@ -949,7 +980,7 @@ var _default2 = exports.default = createComponent({
949
980
  "click": function click(event) {
950
981
  event.stopPropagation();
951
982
  // 证件照模式只有一张图片
952
- _this9.previewMedia(media, 0);
983
+ _this10.previewMedia(media, 0);
953
984
  }
954
985
  }
955
986
  }, [reUpload]);
@@ -1084,7 +1115,7 @@ var _default2 = exports.default = createComponent({
1084
1115
  }
1085
1116
  },
1086
1117
  renderMediaList: function renderMediaList() {
1087
- var _this10 = this;
1118
+ var _this11 = this;
1088
1119
  var h = this.$createElement;
1089
1120
  return this.mediaList.map(function (media, index) {
1090
1121
  var showDelete = media.deletable && media.status !== _type.MediaUploadStatus.UPLOADING;
@@ -1093,7 +1124,7 @@ var _default2 = exports.default = createComponent({
1093
1124
  "on": {
1094
1125
  "click": function click(event) {
1095
1126
  event.stopPropagation();
1096
- _this10.onDelete(media, index);
1127
+ _this11.onDelete(media, index);
1097
1128
  }
1098
1129
  }
1099
1130
  });
@@ -1102,10 +1133,10 @@ var _default2 = exports.default = createComponent({
1102
1133
  "on": {
1103
1134
  "click": function click(event) {
1104
1135
  event.stopPropagation();
1105
- _this10.previewMedia(media, index);
1136
+ _this11.previewMedia(media, index);
1106
1137
  }
1107
1138
  }
1108
- }, [_this10.renderMediaBox(media), _this10.genThumbnailMask(media), deleteIcon]);
1139
+ }, [_this11.renderMediaBox(media), _this11.genThumbnailMask(media), deleteIcon]);
1109
1140
  });
1110
1141
  },
1111
1142
  selectAction: function selectAction(action) {
@@ -1114,7 +1145,7 @@ var _default2 = exports.default = createComponent({
1114
1145
  }
1115
1146
  },
1116
1147
  render: function render() {
1117
- var _this11 = this;
1148
+ var _this12 = this;
1118
1149
  var h = arguments[0];
1119
1150
  var title = this.showTitle && h("div", {
1120
1151
  "class": bem('title')
@@ -1127,9 +1158,9 @@ var _default2 = exports.default = createComponent({
1127
1158
  "mediaUrl": this.mediaUrlToPlay
1128
1159
  }, this.mediaPlayerProps),
1129
1160
  "model": {
1130
- value: _this11.mediaPlayerVisible,
1161
+ value: _this12.mediaPlayerVisible,
1131
1162
  callback: function callback($$v) {
1132
- _this11.mediaPlayerVisible = $$v;
1163
+ _this12.mediaPlayerVisible = $$v;
1133
1164
  }
1134
1165
  }
1135
1166
  }), h(_actionSheet.default, {
@@ -1143,9 +1174,9 @@ var _default2 = exports.default = createComponent({
1143
1174
  "select": this.selectAction
1144
1175
  },
1145
1176
  "model": {
1146
- value: _this11.actionVisible,
1177
+ value: _this12.actionVisible,
1147
1178
  callback: function callback($$v) {
1148
- _this11.actionVisible = $$v;
1179
+ _this12.actionVisible = $$v;
1149
1180
  }
1150
1181
  }
1151
1182
  }), this.pickerMode === "certificate" ? h("div", {
@@ -1156,9 +1187,10 @@ var _default2 = exports.default = createComponent({
1156
1187
  }, [this.renderCertificates()]) : h("div", {
1157
1188
  "class": bem('line')
1158
1189
  }, [this.renderButtons(), this.slots('extend')]), h(_grid.default, {
1190
+ "ref": "grid",
1159
1191
  "directives": [{
1160
1192
  name: "show",
1161
- value: this.mediaList.length && this.pickerMode !== "certificate"
1193
+ value: this.showPreview
1162
1194
  }],
1163
1195
  "attrs": {
1164
1196
  "column-num": '3',