@sl-material/sl-import 1.0.0-beta20 → 1.1.0-beat0

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
@@ -2633,15 +2633,31 @@ class ImportDialogRenderer {
2633
2633
  `;
2634
2634
  }
2635
2635
  renderDownloadSection() {
2636
- return `
2637
- <div class="import-dialog-vanilla-section">
2638
- <div class="import-dialog-vanilla-section-title">${t("downloadTemplateTitle")}</div>
2639
- <a id="import-dialog-download-btn" class="import-dialog-vanilla-btn download-template-btn import-dialog-vanilla-btn-primary" href="${this.context.currentConfig.templateUrl}">
2640
- <i class="iconfont icon-xiazai"></i>
2641
- ${t("downloadTemplateText")}
2642
- </a>
2643
- </div>
2644
- `;
2636
+ const hasTemplateUrl = !!this.context.currentConfig.templateUrl;
2637
+ const hasDownloadCallback = !!this.context.modalOptions.onDownloadTemplate;
2638
+ if (hasDownloadCallback) {
2639
+ return `
2640
+ <div class="import-dialog-vanilla-section">
2641
+ <div class="import-dialog-vanilla-section-title">${t("downloadTemplateTitle")}</div>
2642
+ <button id="import-dialog-download-btn" class="import-dialog-vanilla-btn download-template-btn import-dialog-vanilla-btn-primary">
2643
+ <i class="iconfont icon-xiazai"></i>
2644
+ ${t("downloadTemplateText")}
2645
+ </button>
2646
+ </div>
2647
+ `;
2648
+ } else if (hasTemplateUrl) {
2649
+ return `
2650
+ <div class="import-dialog-vanilla-section">
2651
+ <div class="import-dialog-vanilla-section-title">${t("downloadTemplateTitle")}</div>
2652
+ <a id="import-dialog-download-btn" class="import-dialog-vanilla-btn download-template-btn import-dialog-vanilla-btn-primary" href="${this.context.currentConfig.templateUrl}">
2653
+ <i class="iconfont icon-xiazai"></i>
2654
+ ${t("downloadTemplateText")}
2655
+ </a>
2656
+ </div>
2657
+ `;
2658
+ } else {
2659
+ return "";
2660
+ }
2645
2661
  }
2646
2662
  renderSettingSection() {
2647
2663
  const config = this.context.currentConfig;
@@ -2902,7 +2918,7 @@ class ChunkedUploader {
2902
2918
  fileItem.file.name,
2903
2919
  fileItem.file.size
2904
2920
  );
2905
- fileItem.uploadSessionId = initResult.uploadSessionId;
2921
+ console.info("upload>>>分片结果", initResult);
2906
2922
  this.currentFileItem = fileItem;
2907
2923
  this.initResumable(initResult);
2908
2924
  this.resumable.addFile(fileItem.file);
@@ -2925,6 +2941,7 @@ class ChunkedUploader {
2925
2941
  * 初始化Resumable实例
2926
2942
  */
2927
2943
  initResumable(initResult) {
2944
+ console.log("[分片上传] 初始化分片上传...", initResult);
2928
2945
  if (this.resumable) {
2929
2946
  this.resumable.cancel();
2930
2947
  }
@@ -2943,6 +2960,7 @@ class ChunkedUploader {
2943
2960
  forceChunkSize: true
2944
2961
  };
2945
2962
  const finalConfig = { ...defaultConfig, ...customConfig };
2963
+ console.info("finalConfig>>>分片上传配置", finalConfig);
2946
2964
  this.resumable = new Resumable(finalConfig);
2947
2965
  this.bindResumableEvents();
2948
2966
  }
@@ -2953,6 +2971,7 @@ class ChunkedUploader {
2953
2971
  this.resumable.on("progress", () => {
2954
2972
  var _a, _b, _c, _d;
2955
2973
  const progress = Math.floor(this.resumable.progress() * 100);
2974
+ console.log(`[Resumable分片上传] 进度: ${progress}%`);
2956
2975
  if (this.currentFileItem) {
2957
2976
  this.currentFileItem.progress = Math.min(progress, 90);
2958
2977
  (_b = (_a = this.callbacks).onProgress) == null ? void 0 : _b.call(
@@ -2964,6 +2983,7 @@ class ChunkedUploader {
2964
2983
  (_d = (_c = this.callbacks).onUpdate) == null ? void 0 : _d.call(_c);
2965
2984
  });
2966
2985
  this.resumable.on("fileSuccess", () => {
2986
+ console.log("[Resumable分片上传] 文件上传成功");
2967
2987
  this.handleResumableComplete();
2968
2988
  });
2969
2989
  this.resumable.on("error", (message) => {
@@ -2971,6 +2991,7 @@ class ChunkedUploader {
2971
2991
  this.handleResumableError(message);
2972
2992
  });
2973
2993
  this.resumable.on("fileAdded", () => {
2994
+ console.info("fileAdded>>>开始上传");
2974
2995
  this.resumable.upload();
2975
2996
  });
2976
2997
  }
@@ -3054,9 +3075,6 @@ class ImportDialogUploader {
3054
3075
  __publicField(this, "callbacks");
3055
3076
  // 分片上传器实例
3056
3077
  __publicField(this, "chunkedUploader", null);
3057
- // 并发上传队列
3058
- __publicField(this, "uploadQueue", []);
3059
- __publicField(this, "activeUploads", 0);
3060
3078
  // 上传状态
3061
3079
  __publicField(this, "uploadFileList", []);
3062
3080
  //上传文件列表
@@ -3089,12 +3107,6 @@ class ImportDialogUploader {
3089
3107
  });
3090
3108
  }
3091
3109
  }
3092
- /**
3093
- * 获取并发限制数
3094
- */
3095
- get concurrentLimit() {
3096
- return this.config.concurrentLimit != null ? this.config.concurrentLimit : 3;
3097
- }
3098
3110
  /**
3099
3111
  * 判断是否应该使用分片上传
3100
3112
  * 条件:配置了chunkedUpload 且 是单文件模式
@@ -3118,8 +3130,6 @@ class ImportDialogUploader {
3118
3130
  this.isUploading = false;
3119
3131
  this.uploadMessage = "";
3120
3132
  this.uploadMessageType = "info";
3121
- this.uploadQueue = [];
3122
- this.activeUploads = 0;
3123
3133
  }
3124
3134
  /**
3125
3135
  * 文件上传之前的校验 选择文件时调用
@@ -3252,12 +3262,6 @@ class ImportDialogUploader {
3252
3262
  (_c = (_b = this.callbacks).onMessage) == null ? void 0 : _c.call(_b, "文件正在上传中,无法删除", "warning");
3253
3263
  return false;
3254
3264
  }
3255
- const queueIndex = this.uploadQueue.findIndex(
3256
- (q) => q.id === fileItem.id
3257
- );
3258
- if (queueIndex !== -1) {
3259
- this.uploadQueue.splice(queueIndex, 1);
3260
- }
3261
3265
  this.uploadFileList.splice(index, 1);
3262
3266
  this.fileList.splice(index, 1);
3263
3267
  } else {
@@ -3270,7 +3274,6 @@ class ImportDialogUploader {
3270
3274
  return false;
3271
3275
  }
3272
3276
  }
3273
- this.uploadQueue = [];
3274
3277
  this.uploadFileList = [];
3275
3278
  this.fileList = [];
3276
3279
  }
@@ -3284,32 +3287,6 @@ class ImportDialogUploader {
3284
3287
  (_i = (_h = this.callbacks).onUpdate) == null ? void 0 : _i.call(_h);
3285
3288
  return true;
3286
3289
  }
3287
- /**
3288
- * 将文件加入上传队列并启动处理
3289
- */
3290
- enqueueUpload(fileItems) {
3291
- const newItems = fileItems.filter(
3292
- (item) => !this.uploadQueue.some((q) => q.id === item.id)
3293
- );
3294
- this.uploadQueue.push(...newItems);
3295
- this.processUploadQueue();
3296
- }
3297
- /**
3298
- * 处理上传队列(支持并发)
3299
- */
3300
- processUploadQueue() {
3301
- while (this.uploadQueue.length > 0 && this.activeUploads < this.concurrentLimit) {
3302
- const fileItem = this.uploadQueue.shift();
3303
- if (fileItem.status !== "pending") {
3304
- continue;
3305
- }
3306
- this.activeUploads++;
3307
- this.uploadSingleFile(fileItem).finally(() => {
3308
- this.activeUploads--;
3309
- this.processUploadQueue();
3310
- });
3311
- }
3312
- }
3313
3290
  /**
3314
3291
  * 单个文件分片上传
3315
3292
  * @param fileItem
@@ -3346,21 +3323,23 @@ class ImportDialogUploader {
3346
3323
  return await this.chunkedUploader.upload(fileItem);
3347
3324
  }
3348
3325
  /**
3349
- * 手动触发分片上传(仅用于分片上传场景)
3326
+ * 手动触发上传(用于延迟上传场景)
3327
+ * 分片上传:直接调用 uploadSingleFile 并等待完成
3328
+ * 普通上传:已在选择文件时通过 customUpload 处理完成
3350
3329
  */
3351
3330
  async startUpload() {
3352
- if (this.shouldUseChunkedUpload()) {
3353
- await this.startChunkedUploadFiles();
3331
+ if (!this.shouldUseChunkedUpload()) {
3332
+ return;
3354
3333
  }
3355
- }
3356
- /**
3357
- * 启动分片上传
3358
- */
3359
- async startChunkedUploadFiles() {
3360
3334
  const pendingFiles = this.uploadFileList.filter(
3361
3335
  (f) => f.status === "pending"
3362
3336
  );
3363
- this.enqueueUpload(pendingFiles);
3337
+ if (pendingFiles.length === 0) {
3338
+ return;
3339
+ }
3340
+ for (const fileItem of pendingFiles) {
3341
+ await this.uploadSingleFile(fileItem);
3342
+ }
3364
3343
  }
3365
3344
  /**
3366
3345
  * 暂停上传(仅分片上传支持)
@@ -3382,8 +3361,6 @@ class ImportDialogUploader {
3382
3361
  cancelUpload() {
3383
3362
  var _a, _b, _c;
3384
3363
  (_a = this.chunkedUploader) == null ? void 0 : _a.cancel();
3385
- this.uploadQueue = [];
3386
- this.activeUploads = 0;
3387
3364
  this.isUploading = false;
3388
3365
  this.uploadMessage = "上传已取消";
3389
3366
  this.uploadMessageType = "info";
@@ -3599,6 +3576,7 @@ const _ImportDialog = class _ImportDialog {
3599
3576
  var _a, _b;
3600
3577
  return {
3601
3578
  currentConfig: this.currentConfig,
3579
+ modalOptions: this.modalOptions,
3602
3580
  dialogTitle: this.dialogTitle,
3603
3581
  width: this.dialogWidth,
3604
3582
  activeTabIndex: this.activeTabIndex,
@@ -3782,6 +3760,13 @@ const _ImportDialog = class _ImportDialog {
3782
3760
  "#import-dialog-cancel-btn"
3783
3761
  );
3784
3762
  cancelBtn == null ? void 0 : cancelBtn.addEventListener("click", () => this.handleCancel());
3763
+ const downloadBtn = this.modalElement.querySelector(
3764
+ "#import-dialog-download-btn"
3765
+ );
3766
+ downloadBtn == null ? void 0 : downloadBtn.addEventListener("click", (e) => {
3767
+ e.preventDefault();
3768
+ this.handleDownloadTemplate();
3769
+ });
3785
3770
  }
3786
3771
  bindFormEvents() {
3787
3772
  if (!this.modalElement) return;
@@ -4042,6 +4027,25 @@ const _ImportDialog = class _ImportDialog {
4042
4027
  closeModal() {
4043
4028
  this.handleCancel();
4044
4029
  }
4030
+ /**
4031
+ * 处理下载模板
4032
+ */
4033
+ handleDownloadTemplate() {
4034
+ var _a;
4035
+ if (this.modalOptions.onDownloadTemplate) {
4036
+ this.modalOptions.onDownloadTemplate({
4037
+ url: this.currentConfig.templateUrl || "",
4038
+ activeTab: (_a = this.modalOptions.tabs) == null ? void 0 : _a[this.activeTabIndex]
4039
+ });
4040
+ } else if (this.currentConfig.templateUrl) {
4041
+ const link = document.createElement("a");
4042
+ link.href = this.currentConfig.templateUrl;
4043
+ link.download = "";
4044
+ document.body.appendChild(link);
4045
+ link.click();
4046
+ document.body.removeChild(link);
4047
+ }
4048
+ }
4045
4049
  setConfirmLoading(loading) {
4046
4050
  this.confirmLoading = loading;
4047
4051
  this.updateModal();