@sl-material/sl-import 1.1.0-beta2 → 1.1.0-beta3

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/sl-import.es.js CHANGED
@@ -3042,15 +3042,17 @@ var __async$2 = (__this, __arguments, generator) => {
3042
3042
  });
3043
3043
  };
3044
3044
  class ChunkedUploader {
3045
- constructor(chunkedConfig, callbacks = {}) {
3045
+ constructor(chunkedConfig, callbacks = {}, autoUpload = false) {
3046
3046
  __publicField$2(this, "resumable");
3047
3047
  __publicField$2(this, "currentFileItem", null);
3048
3048
  __publicField$2(this, "chunkedConfig");
3049
3049
  __publicField$2(this, "callbacks");
3050
+ __publicField$2(this, "autoUpload");
3050
3051
  __publicField$2(this, "uploadCompleteResolve");
3051
3052
  __publicField$2(this, "uploadCompleteReject");
3052
3053
  this.chunkedConfig = chunkedConfig;
3053
3054
  this.callbacks = callbacks;
3055
+ this.autoUpload = autoUpload;
3054
3056
  }
3055
3057
  /**
3056
3058
  * 上传单个文件(分片方式)
@@ -3066,7 +3068,14 @@ class ChunkedUploader {
3066
3068
  this.currentFileItem = fileItem;
3067
3069
  this.initResumable(initResult);
3068
3070
  this.resumable.addFile(fileItem.file);
3069
- return yield this.waitForUploadComplete();
3071
+ if (this.autoUpload) {
3072
+ return yield this.waitForUploadComplete();
3073
+ } else {
3074
+ return {
3075
+ uploadSessionId: initResult.uploadSessionId,
3076
+ initialized: true
3077
+ };
3078
+ }
3070
3079
  } catch (error) {
3071
3080
  const err = error instanceof Error ? error : new Error(String(error));
3072
3081
  throw err;
@@ -3131,7 +3140,9 @@ class ChunkedUploader {
3131
3140
  this.handleResumableError(message);
3132
3141
  });
3133
3142
  this.resumable.on("fileAdded", () => {
3134
- this.resumable.upload();
3143
+ if (this.autoUpload) {
3144
+ this.resumable.upload();
3145
+ }
3135
3146
  });
3136
3147
  }
3137
3148
  /**
@@ -3268,17 +3279,22 @@ class ImportDialogUploader {
3268
3279
  initUploaders() {
3269
3280
  const uploadConfig = this.config.uploadConfig;
3270
3281
  if ((uploadConfig == null ? void 0 : uploadConfig.chunkedUpload) && !this.config.multiple) {
3271
- this.chunkedUploader = new ChunkedUploader(uploadConfig.chunkedUpload, {
3272
- onProgress: (fileItem, progress) => {
3273
- var _a, _b, _c, _d;
3274
- (_b = (_a = this.callbacks).onUploadProgress) == null ? void 0 : _b.call(_a, fileItem, progress);
3275
- (_d = (_c = this.callbacks).onUpdate) == null ? void 0 : _d.call(_c);
3282
+ this.chunkedUploader = new ChunkedUploader(
3283
+ uploadConfig.chunkedUpload,
3284
+ {
3285
+ onProgress: (fileItem, progress) => {
3286
+ var _a, _b, _c, _d;
3287
+ (_b = (_a = this.callbacks).onUploadProgress) == null ? void 0 : _b.call(_a, fileItem, progress);
3288
+ (_d = (_c = this.callbacks).onUpdate) == null ? void 0 : _d.call(_c);
3289
+ },
3290
+ onUpdate: () => {
3291
+ var _a, _b;
3292
+ (_b = (_a = this.callbacks).onUpdate) == null ? void 0 : _b.call(_a);
3293
+ }
3276
3294
  },
3277
- onUpdate: () => {
3278
- var _a, _b;
3279
- return (_b = (_a = this.callbacks).onUpdate) == null ? void 0 : _b.call(_a);
3280
- }
3281
- });
3295
+ uploadConfig.autoUpload === true
3296
+ // 只有明确设置为 true 时才自动上传
3297
+ );
3282
3298
  }
3283
3299
  }
3284
3300
  /**
@@ -3309,7 +3325,7 @@ class ImportDialogUploader {
3309
3325
  * 文件上传之前的校验 选择文件时调用
3310
3326
  */
3311
3327
  beforeUpload(files) {
3312
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3328
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3313
3329
  const fileArray = Array.isArray(files) ? files : [files];
3314
3330
  if (!fileArray.length) {
3315
3331
  (_b = (_a = this.callbacks).onMessage) == null ? void 0 : _b.call(_a, "请选择文件", "warning");
@@ -3356,9 +3372,7 @@ class ImportDialogUploader {
3356
3372
  (_h = (_g = this.callbacks).onUpdate) == null ? void 0 : _h.call(_g);
3357
3373
  (_j = (_i = this.callbacks).onFileChange) == null ? void 0 : _j.call(_i, this.uploadFileList);
3358
3374
  if (this.shouldUseChunkedUpload()) {
3359
- if (((_k = this.config.uploadConfig) == null ? void 0 : _k.autoUpload) !== false) {
3360
- this.processChunkedUpload();
3361
- }
3375
+ this.processChunkedUpload();
3362
3376
  } else {
3363
3377
  this.processFilesWithCustomUpload();
3364
3378
  }
@@ -3370,11 +3384,14 @@ class ImportDialogUploader {
3370
3384
  */
3371
3385
  processChunkedUpload() {
3372
3386
  return __async$1(this, null, function* () {
3373
- const pendingFiles = this.uploadFileList.filter(
3374
- (f) => f.status === "pending"
3375
- );
3376
- for (const fileItem of pendingFiles) {
3377
- yield this.uploadSingleFile(fileItem);
3387
+ var _a;
3388
+ if (((_a = this.config.uploadConfig) == null ? void 0 : _a.autoUpload) === true) {
3389
+ const pendingFiles = this.uploadFileList.filter(
3390
+ (f) => f.status === "pending"
3391
+ );
3392
+ for (const fileItem of pendingFiles) {
3393
+ yield this.uploadSingleFile(fileItem);
3394
+ }
3378
3395
  }
3379
3396
  });
3380
3397
  }