@sl-material/sl-import 1.0.0-beta19 → 1.0.0

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;
@@ -3176,9 +3192,14 @@ class ImportDialogUploader {
3176
3192
  }
3177
3193
  /**
3178
3194
  * 使用 customUpload 预处理文件
3179
- * 在选择文件后立即调用,用于二次加工参数或自定义校验
3195
+ * 仅在配置了 customUpload 时才调用
3180
3196
  */
3181
3197
  async processFilesWithCustomUpload() {
3198
+ var _a;
3199
+ const customUpload = (_a = this.config.uploadConfig) == null ? void 0 : _a.customUpload;
3200
+ if (!customUpload) {
3201
+ return;
3202
+ }
3182
3203
  const pendingFiles = this.uploadFileList.filter(
3183
3204
  (f) => f.status === "pending"
3184
3205
  );
@@ -3187,22 +3208,18 @@ class ImportDialogUploader {
3187
3208
  }
3188
3209
  }
3189
3210
  /**
3190
- * 单个文件的预处理
3211
+ * 单个文件的预处理(仅在有 customUpload 时调用)
3191
3212
  */
3192
3213
  async processFileWithCustomUpload(fileItem) {
3193
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3214
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
3194
3215
  const customUpload = (_a = this.config.uploadConfig) == null ? void 0 : _a.customUpload;
3195
3216
  if (!customUpload) {
3196
- fileItem.status = "success";
3197
- fileItem.progress = 100;
3198
- fileItem.response = fileItem.file;
3199
- (_c = (_b = this.callbacks).onUpdate) == null ? void 0 : _c.call(_b);
3200
3217
  return;
3201
3218
  }
3202
3219
  fileItem.status = "uploading";
3203
3220
  fileItem.progress = 0;
3204
3221
  this.isUploading = true;
3205
- (_e = (_d = this.callbacks).onUpdate) == null ? void 0 : _e.call(_d);
3222
+ (_c = (_b = this.callbacks).onUpdate) == null ? void 0 : _c.call(_b);
3206
3223
  try {
3207
3224
  const context = {
3208
3225
  fileList: [...this.uploadFileList],
@@ -3222,16 +3239,16 @@ class ImportDialogUploader {
3222
3239
  );
3223
3240
  fileItem.status = "success";
3224
3241
  fileItem.progress = 100;
3225
- (_g = (_f = this.callbacks).onUploadSuccess) == null ? void 0 : _g.call(_f, fileItem, fileItem.response);
3242
+ (_e = (_d = this.callbacks).onUploadSuccess) == null ? void 0 : _e.call(_d, fileItem, fileItem.response);
3226
3243
  } catch (error) {
3227
3244
  fileItem.status = "error";
3228
3245
  fileItem.errorMessage = error instanceof Error ? error.message : "处理失败";
3229
- (_i = (_h = this.callbacks).onUploadError) == null ? void 0 : _i.call(_h, fileItem, error);
3246
+ (_g = (_f = this.callbacks).onUploadError) == null ? void 0 : _g.call(_f, fileItem, error);
3230
3247
  }
3231
3248
  this.isUploading = this.uploadFileList.some(
3232
3249
  (f) => f.status === "uploading"
3233
3250
  );
3234
- (_k = (_j = this.callbacks).onUpdate) == null ? void 0 : _k.call(_j);
3251
+ (_i = (_h = this.callbacks).onUpdate) == null ? void 0 : _i.call(_h);
3235
3252
  this.updateOverallProgress();
3236
3253
  }
3237
3254
  /**
@@ -3239,16 +3256,16 @@ class ImportDialogUploader {
3239
3256
  * @param index 文件索引,不传则清空所有文件
3240
3257
  *
3241
3258
  * 删除权限:
3242
- * - pending 状态:可删除(还没开始上传)
3243
- * - uploading 状态:不可删除(正在上传/处理中)
3244
- * - success/error 状态:可删除(已完成)
3259
+ * - 实时分片上传场景:uploading 状态不可删除(真正的网络上传中)
3260
+ * - 其他场景(延迟分片、customUpload、无配置):任何状态都可删除
3245
3261
  */
3246
3262
  removeFile(index) {
3247
- var _a, _b, _c, _d, _e, _f, _g, _h;
3263
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
3264
+ const needCheckStatus = this.shouldUseChunkedUpload() && ((_a = this.config.uploadConfig) == null ? void 0 : _a.autoUpload) !== false;
3248
3265
  if (index !== void 0 && index >= 0 && index < this.uploadFileList.length) {
3249
3266
  const fileItem = this.uploadFileList[index];
3250
- if (fileItem.status === "uploading") {
3251
- (_b = (_a = this.callbacks).onMessage) == null ? void 0 : _b.call(_a, "文件正在处理中,无法删除", "warning");
3267
+ if (needCheckStatus && fileItem.status === "uploading") {
3268
+ (_c = (_b = this.callbacks).onMessage) == null ? void 0 : _c.call(_b, "文件正在上传中,无法删除", "warning");
3252
3269
  return false;
3253
3270
  }
3254
3271
  const queueIndex = this.uploadQueue.findIndex(
@@ -3260,12 +3277,14 @@ class ImportDialogUploader {
3260
3277
  this.uploadFileList.splice(index, 1);
3261
3278
  this.fileList.splice(index, 1);
3262
3279
  } else {
3263
- const hasUploading = this.uploadFileList.some(
3264
- (f) => f.status === "uploading"
3265
- );
3266
- if (hasUploading) {
3267
- (_d = (_c = this.callbacks).onMessage) == null ? void 0 : _d.call(_c, "有文件正在处理中,无法清空", "warning");
3268
- return false;
3280
+ if (needCheckStatus) {
3281
+ const hasUploading = this.uploadFileList.some(
3282
+ (f) => f.status === "uploading"
3283
+ );
3284
+ if (hasUploading) {
3285
+ (_e = (_d = this.callbacks).onMessage) == null ? void 0 : _e.call(_d, "有文件正在上传中,无法清空", "warning");
3286
+ return false;
3287
+ }
3269
3288
  }
3270
3289
  this.uploadQueue = [];
3271
3290
  this.uploadFileList = [];
@@ -3277,8 +3296,8 @@ class ImportDialogUploader {
3277
3296
  this.isUploading = this.uploadFileList.some(
3278
3297
  (f) => f.status === "uploading"
3279
3298
  );
3280
- (_f = (_e = this.callbacks).onFileChange) == null ? void 0 : _f.call(_e, this.uploadFileList);
3281
- (_h = (_g = this.callbacks).onUpdate) == null ? void 0 : _h.call(_g);
3299
+ (_g = (_f = this.callbacks).onFileChange) == null ? void 0 : _g.call(_f, this.uploadFileList);
3300
+ (_i = (_h = this.callbacks).onUpdate) == null ? void 0 : _i.call(_h);
3282
3301
  return true;
3283
3302
  }
3284
3303
  /**
@@ -3596,6 +3615,7 @@ const _ImportDialog = class _ImportDialog {
3596
3615
  var _a, _b;
3597
3616
  return {
3598
3617
  currentConfig: this.currentConfig,
3618
+ modalOptions: this.modalOptions,
3599
3619
  dialogTitle: this.dialogTitle,
3600
3620
  width: this.dialogWidth,
3601
3621
  activeTabIndex: this.activeTabIndex,
@@ -3779,6 +3799,13 @@ const _ImportDialog = class _ImportDialog {
3779
3799
  "#import-dialog-cancel-btn"
3780
3800
  );
3781
3801
  cancelBtn == null ? void 0 : cancelBtn.addEventListener("click", () => this.handleCancel());
3802
+ const downloadBtn = this.modalElement.querySelector(
3803
+ "#import-dialog-download-btn"
3804
+ );
3805
+ downloadBtn == null ? void 0 : downloadBtn.addEventListener("click", (e) => {
3806
+ e.preventDefault();
3807
+ this.handleDownloadTemplate();
3808
+ });
3782
3809
  }
3783
3810
  bindFormEvents() {
3784
3811
  if (!this.modalElement) return;
@@ -4039,6 +4066,25 @@ const _ImportDialog = class _ImportDialog {
4039
4066
  closeModal() {
4040
4067
  this.handleCancel();
4041
4068
  }
4069
+ /**
4070
+ * 处理下载模板
4071
+ */
4072
+ handleDownloadTemplate() {
4073
+ var _a;
4074
+ if (this.modalOptions.onDownloadTemplate) {
4075
+ this.modalOptions.onDownloadTemplate({
4076
+ url: this.currentConfig.templateUrl || "",
4077
+ activeTab: (_a = this.modalOptions.tabs) == null ? void 0 : _a[this.activeTabIndex]
4078
+ });
4079
+ } else if (this.currentConfig.templateUrl) {
4080
+ const link = document.createElement("a");
4081
+ link.href = this.currentConfig.templateUrl;
4082
+ link.download = "";
4083
+ document.body.appendChild(link);
4084
+ link.click();
4085
+ document.body.removeChild(link);
4086
+ }
4087
+ }
4042
4088
  setConfirmLoading(loading) {
4043
4089
  this.confirmLoading = loading;
4044
4090
  this.updateModal();