@sl-material/sl-import 1.1.0-beat0 → 1.1.0-beta1

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
@@ -1388,7 +1388,6 @@ function getImportDialogStyles() {
1388
1388
  overflow-y: hidden;
1389
1389
  padding: 0px 0px 12px 0px;
1390
1390
  scrollbar-width: thin;
1391
- // scrollbar-color: #d9d9d9 transparent;
1392
1391
  }
1393
1392
 
1394
1393
  .import-dialog-vanilla-file-list::-webkit-scrollbar {
@@ -1428,22 +1427,10 @@ function getImportDialogStyles() {
1428
1427
  width:100%;
1429
1428
  }
1430
1429
 
1431
- // .import-dialog-vanilla-file-item:hover {
1432
- // background: #FFF7E6;
1433
- // }
1434
-
1435
- // .import-dialog-vanilla-file-item.status-success {
1436
- // background: #FFFBF0;
1437
- // }
1438
-
1439
1430
  .import-dialog-vanilla-file-item.status-error {
1440
- background: #FFF2F0;
1431
+ background: var(--sl-color-danger-light-9);
1432
+ border:1px solid var(--sl-color-error);
1441
1433
  }
1442
-
1443
- .import-dialog-vanilla-file-item.status-uploading {
1444
- background: #FFFBF0;
1445
- }
1446
-
1447
1434
  .import-dialog-vanilla-file-icon {
1448
1435
  width: 18px;
1449
1436
  height: 18px;
@@ -1479,19 +1466,64 @@ function getImportDialogStyles() {
1479
1466
  align-items: center;
1480
1467
  gap: 4px;
1481
1468
  font-size: 12px;
1482
- color: var(--sl-text-color-secondary);
1469
+ color: var(--sl-text-color-thridary);
1483
1470
  }
1484
1471
 
1485
- .import-dialog-vanilla-file-progress-text {
1486
- font-size: 12px;
1487
- color: #1890FF;
1488
- }
1489
1472
 
1490
1473
  .import-dialog-vanilla-file-error-text {
1491
1474
  font-size: 12px;
1492
1475
  color: var(--sl-color-error);
1493
1476
  }
1494
1477
 
1478
+ /* 上传中状态的 loading 图标 */
1479
+ .import-dialog-vanilla-file-loading-icon {
1480
+ position: absolute;
1481
+ top: 8px;
1482
+ left: 8px;
1483
+ width: 32px;
1484
+ height: 32px;
1485
+ display: flex;
1486
+ align-items: center;
1487
+ justify-content: center;
1488
+ }
1489
+
1490
+ .loading-spinner {
1491
+ width: 24px;
1492
+ height: 24px;
1493
+ border-radius: 50%;
1494
+ background: conic-gradient(from 0deg at 50% 50%, rgba(24, 144, 255, 0.1) 0%, #1890ff 75%, rgba(24, 144, 255, 0) 100%);
1495
+ animation: spin 1s linear infinite;
1496
+ display: flex;
1497
+ align-items: center;
1498
+ justify-content: center;
1499
+ position: relative;
1500
+ opacity: 0;
1501
+ transition: opacity 0.3s ease;
1502
+ }
1503
+
1504
+ .loading-spinner::before {
1505
+ content: '';
1506
+ width: 18px;
1507
+ height: 18px;
1508
+ border-radius: 50%;
1509
+ background-color: #fff;
1510
+ position: absolute;
1511
+ }
1512
+
1513
+ .loading-spinner.active {
1514
+ opacity: 1;
1515
+ }
1516
+
1517
+ @keyframes spin {
1518
+ 0% { transform: rotate(0deg); }
1519
+ 100% { transform: rotate(360deg); }
1520
+ }
1521
+
1522
+ /* 上传中状态的文件信息向右偏移 */
1523
+ .import-dialog-vanilla-file-item.status-uploading .import-dialog-vanilla-file-info {
1524
+ margin-left: 32px;
1525
+ }
1526
+
1495
1527
  /* 删除按钮 - 默认隐藏,hover时显示 */
1496
1528
  .import-dialog-vanilla-file-remove-btn {
1497
1529
  position: absolute;
@@ -2816,10 +2848,31 @@ class ImportDialogRenderer {
2816
2848
  if (isError) {
2817
2849
  metaContent = `<span class="import-dialog-vanilla-file-error-text">${t("uploadFailed")}</span>`;
2818
2850
  } else if (isUploading) {
2819
- metaContent = `<span class="import-dialog-vanilla-file-progress-text">${t("uploading")}...</span><span>·</span><span>${fileSize}</span>`;
2851
+ metaContent = `<span>${t("uploading")}...</span><span>·</span><span>${fileSize}</span>`;
2820
2852
  } else {
2821
2853
  metaContent = `<span>${fileExt}</span><span>·</span><span>${fileSize}</span>`;
2822
2854
  }
2855
+ if (isUploading) {
2856
+ return `
2857
+ <div class="import-dialog-vanilla-file-item ${statusClass} ${widthClass}" data-file-id="${fileItem.id}">
2858
+ <div class="import-dialog-vanilla-file-loading-icon">
2859
+ <div class="loading-spinner active"></div>
2860
+ </div>
2861
+ <div class="import-dialog-vanilla-file-remove-btn" data-file-index="${index}" title="删除">
2862
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
2863
+ <circle cx="8" cy="8" r="8" fill="rgba(0,0,0)"/>
2864
+ <path d="M5 5L11 11M11 5L5 11" stroke="white" stroke-width="1.5" stroke-linecap="round"/>
2865
+ </svg>
2866
+ </div>
2867
+ <div class="import-dialog-vanilla-file-info">
2868
+ <div class="import-dialog-vanilla-file-name" title="${fileItem.name}">${fileItem.name}</div>
2869
+ <div class="import-dialog-vanilla-file-meta">
2870
+ ${metaContent}
2871
+ </div>
2872
+ </div>
2873
+ </div>
2874
+ `;
2875
+ }
2823
2876
  return `
2824
2877
  <div class="import-dialog-vanilla-file-item ${statusClass} ${widthClass}" data-file-id="${fileItem.id}">
2825
2878
  <div class="import-dialog-vanilla-file-icon">
@@ -2919,6 +2972,7 @@ class ChunkedUploader {
2919
2972
  fileItem.file.size
2920
2973
  );
2921
2974
  console.info("upload>>>分片结果", initResult);
2975
+ fileItem.uploadSessionId = initResult.uploadSessionId;
2922
2976
  this.currentFileItem = fileItem;
2923
2977
  this.initResumable(initResult);
2924
2978
  this.resumable.addFile(fileItem.file);
@@ -3010,6 +3064,7 @@ class ChunkedUploader {
3010
3064
  this.currentFileItem.progress = 100;
3011
3065
  }
3012
3066
  this.uploadCompleteResolve(mergeResult);
3067
+ console.log("合并分片成功>>>uploadCompleteResolve", mergeResult);
3013
3068
  this.cleanup();
3014
3069
  } catch (error) {
3015
3070
  const err = error instanceof Error ? error : new Error(String(error));
@@ -3135,7 +3190,7 @@ class ImportDialogUploader {
3135
3190
  * 文件上传之前的校验 选择文件时调用
3136
3191
  */
3137
3192
  beforeUpload(files) {
3138
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3193
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3139
3194
  const fileArray = Array.isArray(files) ? files : [files];
3140
3195
  if (!fileArray.length) {
3141
3196
  (_b = (_a = this.callbacks).onMessage) == null ? void 0 : _b.call(_a, "请选择文件", "warning");
@@ -3181,9 +3236,27 @@ class ImportDialogUploader {
3181
3236
  }
3182
3237
  (_h = (_g = this.callbacks).onUpdate) == null ? void 0 : _h.call(_g);
3183
3238
  (_j = (_i = this.callbacks).onFileChange) == null ? void 0 : _j.call(_i, this.uploadFileList);
3184
- this.processFilesWithCustomUpload();
3239
+ if (this.shouldUseChunkedUpload()) {
3240
+ if (((_k = this.config.uploadConfig) == null ? void 0 : _k.autoUpload) !== false) {
3241
+ this.processChunkedUpload();
3242
+ }
3243
+ } else {
3244
+ this.processFilesWithCustomUpload();
3245
+ }
3185
3246
  return true;
3186
3247
  }
3248
+ /**
3249
+ * 处理分片上传
3250
+ * 仅在配置了 chunkedUpload 时调用
3251
+ */
3252
+ async processChunkedUpload() {
3253
+ const pendingFiles = this.uploadFileList.filter(
3254
+ (f) => f.status === "pending"
3255
+ );
3256
+ for (const fileItem of pendingFiles) {
3257
+ await this.uploadSingleFile(fileItem);
3258
+ }
3259
+ }
3187
3260
  /**
3188
3261
  * 使用 customUpload 预处理文件
3189
3262
  * 仅在配置了 customUpload 时才调用
@@ -3292,7 +3365,7 @@ class ImportDialogUploader {
3292
3365
  * @param fileItem
3293
3366
  */
3294
3367
  async uploadSingleFile(fileItem) {
3295
- var _a, _b, _c, _d, _e, _f, _g, _h;
3368
+ var _a, _b, _c, _d, _e, _f;
3296
3369
  fileItem.status = "uploading";
3297
3370
  fileItem.progress = 0;
3298
3371
  this.isUploading = true;
@@ -3302,16 +3375,13 @@ class ImportDialogUploader {
3302
3375
  fileItem.status = "success";
3303
3376
  fileItem.progress = 100;
3304
3377
  (_d = (_c = this.callbacks).onUploadSuccess) == null ? void 0 : _d.call(_c, fileItem, fileItem.response);
3378
+ return fileItem.response;
3305
3379
  } catch (error) {
3306
3380
  fileItem.status = "error";
3307
3381
  fileItem.errorMessage = error instanceof Error ? error.message : "上传失败";
3308
3382
  (_f = (_e = this.callbacks).onUploadError) == null ? void 0 : _f.call(_e, fileItem, error);
3383
+ throw error;
3309
3384
  }
3310
- this.isUploading = this.uploadFileList.some(
3311
- (f) => f.status === "uploading"
3312
- );
3313
- (_h = (_g = this.callbacks).onUpdate) == null ? void 0 : _h.call(_g);
3314
- this.updateOverallProgress();
3315
3385
  }
3316
3386
  /**
3317
3387
  * 分片上传
@@ -3337,9 +3407,18 @@ class ImportDialogUploader {
3337
3407
  if (pendingFiles.length === 0) {
3338
3408
  return;
3339
3409
  }
3410
+ const results = [];
3340
3411
  for (const fileItem of pendingFiles) {
3341
- await this.uploadSingleFile(fileItem);
3412
+ try {
3413
+ const result = await this.uploadSingleFile(fileItem);
3414
+ if (result) {
3415
+ results.push(result);
3416
+ }
3417
+ } catch (error) {
3418
+ console.error(`文件 ${fileItem.file.name} 上传失败:`, error);
3419
+ }
3342
3420
  }
3421
+ return results;
3343
3422
  }
3344
3423
  /**
3345
3424
  * 暂停上传(仅分片上传支持)
@@ -3930,7 +4009,8 @@ const _ImportDialog = class _ImportDialog {
3930
4009
  this.updateModal();
3931
4010
  }
3932
4011
  try {
3933
- await this.uploader.startUpload();
4012
+ const chunkResult = await this.uploader.startUpload();
4013
+ console.log("[分片上传] 分片上传结果:", chunkResult);
3934
4014
  } catch (error) {
3935
4015
  console.error("[ImportDialog] 上传失败:", error);
3936
4016
  this.showMessage("上传失败,请重试", "error");