cloud-web-corejs 1.1.0-dev.69 → 1.1.0-dev.70

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloud-web-corejs",
3
3
  "private": false,
4
- "version": "1.1.0-dev.69",
4
+ "version": "1.1.0-dev.70",
5
5
  "scripts": {
6
6
  "build:ace-resources": "node build/build-ace-resources.js",
7
7
  "build:tinymce-resources": "node build/build-tinymce-resources.js",
@@ -93,7 +93,7 @@
93
93
  </div>
94
94
  </div>
95
95
  <div
96
- v-if="!field.options.disabled"
96
+ v-if="!field.options.disabled && showUploadBtn"
97
97
  class="el-upload el-upload--picture"
98
98
  style="vertical-align: middle; display: inline-block; float: left"
99
99
  >
@@ -102,7 +102,9 @@
102
102
  class="upload-demo"
103
103
  action="https://jsonplaceholder.typicode.com/posts/"
104
104
  :http-request="uploadSectionFile"
105
- :limit="1"
105
+ :multiple="isMulti"
106
+ :limit="pickLimit"
107
+ :on-exceed="handleUploadExceed"
106
108
  >
107
109
  <button type="button" class="avatar-uploader">
108
110
  <i class="el-icon-plus avatar-uploader-icon"></i>
@@ -201,6 +203,7 @@ export default {
201
203
  showViewer: false,
202
204
  ownedBlobUrls: [],
203
205
  componentDestroyed: false,
206
+ uploadingCount: 0,
204
207
  };
205
208
  },
206
209
  watch: {
@@ -213,6 +216,33 @@ export default {
213
216
  let formRef = this.getFormRef();
214
217
  return formRef.dataId;
215
218
  },
219
+ /* 与 baseUpload 一致:空 / 0 不限制,1 为单文件,大于 1 为上限 */
220
+ uploadLimit() {
221
+ let limit = this.field.options.limit;
222
+ if (limit === null || limit === undefined || limit === "") return null;
223
+ let num = Number(limit);
224
+ return num > 0 ? num : null;
225
+ },
226
+ isMulti() {
227
+ return this.uploadLimit !== 1;
228
+ },
229
+ attachmentCount() {
230
+ return Array.isArray(this.fieldModel) ? this.fieldModel.length : 0;
231
+ },
232
+ showUploadBtn() {
233
+ let size = this.attachmentCount + this.uploadingCount;
234
+ if (!this.isMulti) {
235
+ return size === 0;
236
+ }
237
+ return this.uploadLimit ? this.uploadLimit > size : true;
238
+ },
239
+ /* 单文件限 1;有上限时限剩余名额;不限制时不传 limit,文件框可多选 */
240
+ pickLimit() {
241
+ if (!this.isMulti) return 1;
242
+ if (!this.uploadLimit) return undefined;
243
+ let remain = this.uploadLimit - this.attachmentCount - this.uploadingCount;
244
+ return remain > 0 ? remain : 1;
245
+ },
216
246
  },
217
247
  beforeCreate() {
218
248
  /* 这里不能访问方法和属性!! */
@@ -530,8 +560,15 @@ export default {
530
560
 
531
561
  let isLoading = uploadConfig?.isLoading === true;
532
562
  var uploadUrl = this.uploadUrl;
563
+ if (!isCustom && !this.showUploadBtn) {
564
+ target && target.clearFiles();
565
+ return;
566
+ }
533
567
  target.clearFiles();
534
568
  if (uploadUrl) {
569
+ if (!isCustom) {
570
+ this.uploadingCount++;
571
+ }
535
572
  var abort;
536
573
 
537
574
  let config = {
@@ -578,7 +615,7 @@ export default {
578
615
  ...adaptedResponse.data,
579
616
  showUrl: null,
580
617
  };
581
- this.fieldModel.push(fileInfo);
618
+ this.appendUploadedFile(fileInfo);
582
619
  // this.initShowUrl();
583
620
  }
584
621
  } else {
@@ -586,9 +623,42 @@ export default {
586
623
  this.$baseAlert(adaptedResponse.message);
587
624
  }
588
625
  }
626
+ })
627
+ .finally(() => {
628
+ if (!isCustom) {
629
+ this.uploadingCount = Math.max(0, this.uploadingCount - 1);
630
+ }
589
631
  });
590
632
  }
591
633
  },
634
+ handleUploadExceed(files) {
635
+ let limit = this.pickLimit || this.uploadLimit;
636
+ let errorMsg = `当前限制选择 ${limit} 个文件,本次选择了 ${files.length} 个文件`;
637
+ this.$message({
638
+ message: this.$t2(errorMsg, "components.VabUpload.warnMsg2", {
639
+ limit,
640
+ size: files.length,
641
+ }),
642
+ type: "error",
643
+ duration: 5 * 1000,
644
+ });
645
+ },
646
+ appendUploadedFile(fileInfo) {
647
+ if (!Array.isArray(this.fieldModel)) {
648
+ this.fieldModel = [];
649
+ }
650
+ if (!this.isMulti) {
651
+ this.fieldModel.forEach((item) => {
652
+ this.revokeBlobUrl(item && (item.showUrl || item.url));
653
+ });
654
+ this.fieldModel = [fileInfo];
655
+ return;
656
+ }
657
+ if (this.uploadLimit && this.fieldModel.length >= this.uploadLimit) {
658
+ return;
659
+ }
660
+ this.fieldModel.push(fileInfo);
661
+ },
592
662
  initShowImageUrl(attachment, callback) {
593
663
  let filename = attachment.filename;
594
664
  if (!filename || !this.viewApiUrl) return;