@sl-material/sl-import 1.1.0-beta3 → 1.1.0-beta5
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/README.md +236 -33
- package/index.d.ts +25 -7
- package/package.json +1 -1
- package/sl-import.cjs.js +1 -1
- package/sl-import.es.js +208 -85
- package/sl-import.umd.umd.js +52 -51
package/sl-import.es.js
CHANGED
|
@@ -16,14 +16,15 @@ var ExportTypeEnum = /* @__PURE__ */ ((ExportTypeEnum2) => {
|
|
|
16
16
|
return ExportTypeEnum2;
|
|
17
17
|
})(ExportTypeEnum || {});
|
|
18
18
|
var I18nLocaleEnum = /* @__PURE__ */ ((I18nLocaleEnum2) => {
|
|
19
|
-
I18nLocaleEnum2["ZH_CN"] = "
|
|
20
|
-
I18nLocaleEnum2["
|
|
21
|
-
I18nLocaleEnum2["
|
|
19
|
+
I18nLocaleEnum2["ZH_CN"] = "zh_CN";
|
|
20
|
+
I18nLocaleEnum2["EN_US"] = "en_US";
|
|
21
|
+
I18nLocaleEnum2["JA_JP"] = "ja_JP";
|
|
22
|
+
I18nLocaleEnum2["ZH_HK"] = "zh_HK";
|
|
23
|
+
I18nLocaleEnum2["ZH_TW"] = "zh_TW";
|
|
22
24
|
I18nLocaleEnum2["ID"] = "id";
|
|
23
|
-
I18nLocaleEnum2["EN_US"] = "en-US";
|
|
24
25
|
return I18nLocaleEnum2;
|
|
25
26
|
})(I18nLocaleEnum || {});
|
|
26
|
-
const DEFAULT_LOCALE = "
|
|
27
|
+
const DEFAULT_LOCALE = "zh_CN";
|
|
27
28
|
var __defProp$6 = Object.defineProperty;
|
|
28
29
|
var __defProps$2 = Object.defineProperties;
|
|
29
30
|
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
@@ -1512,8 +1513,6 @@ function getImportDialogStyles() {
|
|
|
1512
1513
|
align-items: center;
|
|
1513
1514
|
justify-content: center;
|
|
1514
1515
|
position: relative;
|
|
1515
|
-
opacity: 0;
|
|
1516
|
-
transition: opacity 0.3s ease;
|
|
1517
1516
|
}
|
|
1518
1517
|
|
|
1519
1518
|
.loading-spinner::before {
|
|
@@ -1525,10 +1524,6 @@ function getImportDialogStyles() {
|
|
|
1525
1524
|
position: absolute;
|
|
1526
1525
|
}
|
|
1527
1526
|
|
|
1528
|
-
.loading-spinner.active {
|
|
1529
|
-
opacity: 1;
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
1527
|
@keyframes spin {
|
|
1533
1528
|
0% { transform: rotate(0deg); }
|
|
1534
1529
|
100% { transform: rotate(360deg); }
|
|
@@ -1582,15 +1577,22 @@ function getImportDialogStyles() {
|
|
|
1582
1577
|
.import-dialog-vanilla-loading-spinner {
|
|
1583
1578
|
width: 32px;
|
|
1584
1579
|
height: 32px;
|
|
1585
|
-
border: 3px solid var(--sl-border-color);
|
|
1586
|
-
border-top: 3px solid var(--sl-color-primary);
|
|
1587
1580
|
border-radius: 50%;
|
|
1588
|
-
|
|
1581
|
+
background: conic-gradient(from 0deg at 50% 50%, rgba(24, 144, 255, 0.1) 0%, #1890ff 75%, rgba(24, 144, 255, 0) 100%);
|
|
1582
|
+
animation: spin 1s linear infinite;
|
|
1583
|
+
display: flex;
|
|
1584
|
+
align-items: center;
|
|
1585
|
+
justify-content: center;
|
|
1586
|
+
position: relative;
|
|
1589
1587
|
}
|
|
1590
1588
|
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1589
|
+
.import-dialog-vanilla-loading-spinner::before {
|
|
1590
|
+
content: '';
|
|
1591
|
+
width: 24px;
|
|
1592
|
+
height: 24px;
|
|
1593
|
+
border-radius: 50%;
|
|
1594
|
+
background-color: var(--sl-overlay-color-lighter);
|
|
1595
|
+
position: absolute;
|
|
1594
1596
|
}
|
|
1595
1597
|
|
|
1596
1598
|
`;
|
|
@@ -2195,12 +2197,24 @@ const zhCN = {
|
|
|
2195
2197
|
startDate: "开始日期",
|
|
2196
2198
|
endDate: "结束日期",
|
|
2197
2199
|
to: "至",
|
|
2198
|
-
//
|
|
2200
|
+
// 错误信息和提示
|
|
2201
|
+
pleaseSelectFile: "请选择文件",
|
|
2202
|
+
maxFilesLimit: "最多只能上传 {max} 个文件",
|
|
2203
|
+
fileFormatNotSupported: "文件 {name} 格式不支持,仅支持 {types}",
|
|
2204
|
+
fileSizeExceeded: "文件 {name} 超过最大限制 {size}{unit}",
|
|
2199
2205
|
fileTypeError: "请上传文件",
|
|
2200
2206
|
fileSizeError: "文件大小超出限制",
|
|
2201
2207
|
uploadFailed: "上传失败",
|
|
2208
|
+
uploadFailedRetry: "上传失败,请重试",
|
|
2202
2209
|
uploadSuccess: "上传成功",
|
|
2203
2210
|
uploading: "上传中...",
|
|
2211
|
+
processingFailed: "处理失败",
|
|
2212
|
+
fileUploadingCannotDelete: "文件正在上传中,无法删除",
|
|
2213
|
+
filesUploadingCannotClear: "有文件正在上传中,无法清空",
|
|
2214
|
+
filesUploading: "有文件正在上传中,请等待上传完成",
|
|
2215
|
+
filesUploadFailed: "有 {count} 个文件上传失败,请重新上传",
|
|
2216
|
+
waitForUploadComplete: "请等待所有文件上传完成",
|
|
2217
|
+
chunkedUploadConfigRequired: "分片上传需要配置 chunkedUpload",
|
|
2204
2218
|
// 模板配置 - 上传标题
|
|
2205
2219
|
uploadTitleBase: "上传文件",
|
|
2206
2220
|
uploadTitleTemplate1: "上传编辑好的文件",
|
|
@@ -2281,12 +2295,24 @@ const zhTW = {
|
|
|
2281
2295
|
startDate: "開始日期",
|
|
2282
2296
|
endDate: "結束日期",
|
|
2283
2297
|
to: "至",
|
|
2284
|
-
//
|
|
2285
|
-
|
|
2286
|
-
|
|
2298
|
+
// 錯誤信息和提示
|
|
2299
|
+
pleaseSelectFile: "請選擇文件",
|
|
2300
|
+
maxFilesLimit: "最多只能上傳 {max} 個文件",
|
|
2301
|
+
fileFormatNotSupported: "文件 {name} 格式不支持,僅支持 {types}",
|
|
2302
|
+
fileSizeExceeded: "文件 {name} 超過最大限制 {size}{unit}",
|
|
2303
|
+
fileTypeError: "請上傳文件",
|
|
2304
|
+
fileSizeError: "文件大小超出限制",
|
|
2287
2305
|
uploadFailed: "上傳失敗",
|
|
2306
|
+
uploadFailedRetry: "上傳失敗,請重試",
|
|
2288
2307
|
uploadSuccess: "上傳成功",
|
|
2289
2308
|
uploading: "上傳中...",
|
|
2309
|
+
processingFailed: "處理失敗",
|
|
2310
|
+
fileUploadingCannotDelete: "文件正在上傳中,無法刪除",
|
|
2311
|
+
filesUploadingCannotClear: "有文件正在上傳中,無法清空",
|
|
2312
|
+
filesUploading: "有文件正在上傳中,請等待上傳完成",
|
|
2313
|
+
filesUploadFailed: "有 {count} 個文件上傳失敗,請重新上傳",
|
|
2314
|
+
waitForUploadComplete: "請等待所有文件上傳完成",
|
|
2315
|
+
chunkedUploadConfigRequired: "分片上傳需要配置 chunkedUpload",
|
|
2290
2316
|
// 模板配置 - 上傳標題
|
|
2291
2317
|
uploadTitleBase: "上傳檔案",
|
|
2292
2318
|
uploadTitleTemplate1: "上傳編輯好的檔案",
|
|
@@ -2367,12 +2393,24 @@ const ja = {
|
|
|
2367
2393
|
startDate: "開始日",
|
|
2368
2394
|
endDate: "終了日",
|
|
2369
2395
|
to: "から",
|
|
2370
|
-
//
|
|
2396
|
+
// エラー情報と提示
|
|
2397
|
+
pleaseSelectFile: "ファイルを選択してください",
|
|
2398
|
+
maxFilesLimit: "最大 {max} ファイルまでアップロード可能",
|
|
2399
|
+
fileFormatNotSupported: "ファイル {name} の形式はサポートされていません。{types} のみ対応",
|
|
2400
|
+
fileSizeExceeded: "ファイル {name} が最大サイズ {size}{unit} を超えています",
|
|
2371
2401
|
fileTypeError: "ファイルをアップロードしてください",
|
|
2372
2402
|
fileSizeError: "ファイルサイズが制限を超えています",
|
|
2373
2403
|
uploadFailed: "アップロード失敗",
|
|
2404
|
+
uploadFailedRetry: "アップロードに失敗しました。再試行してください",
|
|
2374
2405
|
uploadSuccess: "アップロード成功",
|
|
2375
2406
|
uploading: "アップロード中...",
|
|
2407
|
+
processingFailed: "処理に失敗しました",
|
|
2408
|
+
fileUploadingCannotDelete: "ファイルをアップロード中のため削除できません",
|
|
2409
|
+
filesUploadingCannotClear: "ファイルをアップロード中のためクリアできません",
|
|
2410
|
+
filesUploading: "ファイルをアップロード中です。完了までお待ちください",
|
|
2411
|
+
filesUploadFailed: "{count} 個のファイルのアップロードに失敗しました。再アップロードしてください",
|
|
2412
|
+
waitForUploadComplete: "すべてのファイルのアップロードが完了するまでお待ちください",
|
|
2413
|
+
chunkedUploadConfigRequired: "チャンクアップロードには chunkedUpload の設定が必要です",
|
|
2376
2414
|
// テンプレート設定 - アップロードタイトル
|
|
2377
2415
|
uploadTitleBase: "ファイルをアップロード",
|
|
2378
2416
|
uploadTitleTemplate1: "編集済みファイルをアップロード",
|
|
@@ -2453,12 +2491,24 @@ const id = {
|
|
|
2453
2491
|
startDate: "Tanggal mulai",
|
|
2454
2492
|
endDate: "Tanggal akhir",
|
|
2455
2493
|
to: "hingga",
|
|
2456
|
-
// Informasi
|
|
2494
|
+
// Informasi kesalahan dan petunjuk
|
|
2495
|
+
pleaseSelectFile: "Silakan pilih file",
|
|
2496
|
+
maxFilesLimit: "Maksimal {max} file yang diizinkan",
|
|
2497
|
+
fileFormatNotSupported: "Format file {name} tidak didukung, hanya {types} yang diizinkan",
|
|
2498
|
+
fileSizeExceeded: "File {name} melebihi ukuran maksimal {size}{unit}",
|
|
2457
2499
|
fileTypeError: "Silakan unggah file",
|
|
2458
2500
|
fileSizeError: "Ukuran file melebihi batas",
|
|
2459
2501
|
uploadFailed: "Unggah gagal",
|
|
2502
|
+
uploadFailedRetry: "Unggah gagal, silakan coba lagi",
|
|
2460
2503
|
uploadSuccess: "Unggah berhasil",
|
|
2461
2504
|
uploading: "Mengunggah...",
|
|
2505
|
+
processingFailed: "Pemrosesan gagal",
|
|
2506
|
+
fileUploadingCannotDelete: "File sedang diunggah, tidak dapat dihapus",
|
|
2507
|
+
filesUploadingCannotClear: "File sedang diunggah, tidak dapat dikosongkan",
|
|
2508
|
+
filesUploading: "File sedang diunggah, harap tunggu hingga selesai",
|
|
2509
|
+
filesUploadFailed: "{count} file gagal diunggah, silakan unggah ulang",
|
|
2510
|
+
waitForUploadComplete: "Harap tunggu semua file selesai diunggah",
|
|
2511
|
+
chunkedUploadConfigRequired: "Unggah chunk memerlukan konfigurasi chunkedUpload",
|
|
2462
2512
|
// Konfigurasi template - Judul unggah
|
|
2463
2513
|
uploadTitleBase: "Unggah File",
|
|
2464
2514
|
uploadTitleTemplate1: "Unggah File yang Diedit",
|
|
@@ -2539,12 +2589,24 @@ const enUS = {
|
|
|
2539
2589
|
startDate: "Start date",
|
|
2540
2590
|
endDate: "End date",
|
|
2541
2591
|
to: "to",
|
|
2542
|
-
//
|
|
2592
|
+
// 错误信息和提示
|
|
2593
|
+
pleaseSelectFile: "Please select a file",
|
|
2594
|
+
maxFilesLimit: "Maximum {max} files allowed",
|
|
2595
|
+
fileFormatNotSupported: "File {name} format not supported, only {types} allowed",
|
|
2596
|
+
fileSizeExceeded: "File {name} exceeds maximum size {size}{unit}",
|
|
2543
2597
|
fileTypeError: "Please upload file",
|
|
2544
2598
|
fileSizeError: "File size exceeds limit",
|
|
2545
2599
|
uploadFailed: "Upload failed",
|
|
2600
|
+
uploadFailedRetry: "Upload failed, please retry",
|
|
2546
2601
|
uploadSuccess: "Upload successful",
|
|
2547
2602
|
uploading: "Uploading...",
|
|
2603
|
+
processingFailed: "Processing failed",
|
|
2604
|
+
fileUploadingCannotDelete: "File is uploading, cannot delete",
|
|
2605
|
+
filesUploadingCannotClear: "Files are uploading, cannot clear",
|
|
2606
|
+
filesUploading: "Files are uploading, please wait for completion",
|
|
2607
|
+
filesUploadFailed: "{count} file(s) failed to upload, please re-upload",
|
|
2608
|
+
waitForUploadComplete: "Please wait for all files to complete uploading",
|
|
2609
|
+
chunkedUploadConfigRequired: "Chunked upload requires chunkedUpload configuration",
|
|
2548
2610
|
// 模板配置 - 上传标题
|
|
2549
2611
|
uploadTitleBase: "Upload File",
|
|
2550
2612
|
uploadTitleTemplate1: "Upload Edited File",
|
|
@@ -2596,11 +2658,13 @@ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key,
|
|
|
2596
2658
|
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2597
2659
|
const defaultLocale = DEFAULT_LOCALE;
|
|
2598
2660
|
const locales = {
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
ja,
|
|
2602
|
-
|
|
2603
|
-
|
|
2661
|
+
zh_CN: zhCN,
|
|
2662
|
+
en_US: enUS,
|
|
2663
|
+
ja_JP: ja,
|
|
2664
|
+
zh_HK: zhTW,
|
|
2665
|
+
// 暂时使用繁体中文(台湾)的翻译
|
|
2666
|
+
zh_TW: zhTW,
|
|
2667
|
+
id
|
|
2604
2668
|
};
|
|
2605
2669
|
class I18n {
|
|
2606
2670
|
constructor() {
|
|
@@ -2857,7 +2921,7 @@ class ImportDialogRenderer {
|
|
|
2857
2921
|
const isAllUploading = this.context.uploadFileList.some(
|
|
2858
2922
|
(f) => f.status === "uploading"
|
|
2859
2923
|
);
|
|
2860
|
-
const reachedLimit = this.context.multiple && this.context.uploadFileList.length >= this.context.maxFiles;
|
|
2924
|
+
const reachedLimit = this.context.multiple && this.context.maxFiles != null && this.context.uploadFileList.length >= this.context.maxFiles;
|
|
2861
2925
|
return `
|
|
2862
2926
|
<div class="import-dialog-vanilla-section">
|
|
2863
2927
|
<div class="import-dialog-vanilla-section-title">${this.uploadSectionIndex}.${config.uploadTitle}</div>
|
|
@@ -2910,7 +2974,7 @@ class ImportDialogRenderer {
|
|
|
2910
2974
|
return `
|
|
2911
2975
|
<div class="import-dialog-vanilla-file-item ${statusClass} ${widthClass}" data-file-id="${fileItem.id}">
|
|
2912
2976
|
<div class="import-dialog-vanilla-file-loading-icon">
|
|
2913
|
-
<div class="loading-spinner
|
|
2977
|
+
<div class="loading-spinner"></div>
|
|
2914
2978
|
</div>
|
|
2915
2979
|
<div class="import-dialog-vanilla-file-remove-btn" data-file-index="${index}" title="删除">
|
|
2916
2980
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -3042,20 +3106,22 @@ var __async$2 = (__this, __arguments, generator) => {
|
|
|
3042
3106
|
});
|
|
3043
3107
|
};
|
|
3044
3108
|
class ChunkedUploader {
|
|
3045
|
-
constructor(chunkedConfig, callbacks = {}
|
|
3109
|
+
constructor(chunkedConfig, callbacks = {}) {
|
|
3046
3110
|
__publicField$2(this, "resumable");
|
|
3047
3111
|
__publicField$2(this, "currentFileItem", null);
|
|
3048
3112
|
__publicField$2(this, "chunkedConfig");
|
|
3049
3113
|
__publicField$2(this, "callbacks");
|
|
3050
|
-
__publicField$2(this, "autoUpload");
|
|
3051
3114
|
__publicField$2(this, "uploadCompleteResolve");
|
|
3052
3115
|
__publicField$2(this, "uploadCompleteReject");
|
|
3053
3116
|
this.chunkedConfig = chunkedConfig;
|
|
3054
3117
|
this.callbacks = callbacks;
|
|
3055
|
-
this.autoUpload = autoUpload;
|
|
3056
3118
|
}
|
|
3057
3119
|
/**
|
|
3058
3120
|
* 上传单个文件(分片方式)
|
|
3121
|
+
* 完整流程:初始化 → 分片上传 → 合并 → 返回结果
|
|
3122
|
+
*
|
|
3123
|
+
* @param fileItem 文件项
|
|
3124
|
+
* @returns 合并后的结果
|
|
3059
3125
|
*/
|
|
3060
3126
|
upload(fileItem) {
|
|
3061
3127
|
return __async$2(this, null, function* () {
|
|
@@ -3068,14 +3134,7 @@ class ChunkedUploader {
|
|
|
3068
3134
|
this.currentFileItem = fileItem;
|
|
3069
3135
|
this.initResumable(initResult);
|
|
3070
3136
|
this.resumable.addFile(fileItem.file);
|
|
3071
|
-
|
|
3072
|
-
return yield this.waitForUploadComplete();
|
|
3073
|
-
} else {
|
|
3074
|
-
return {
|
|
3075
|
-
uploadSessionId: initResult.uploadSessionId,
|
|
3076
|
-
initialized: true
|
|
3077
|
-
};
|
|
3078
|
-
}
|
|
3137
|
+
return yield this.waitForUploadComplete();
|
|
3079
3138
|
} catch (error) {
|
|
3080
3139
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
3081
3140
|
throw err;
|
|
@@ -3084,6 +3143,7 @@ class ChunkedUploader {
|
|
|
3084
3143
|
}
|
|
3085
3144
|
/**
|
|
3086
3145
|
* 等待上传完成
|
|
3146
|
+
* 返回一个 Promise,在 fileSuccess 事件触发并完成合并后 resolve
|
|
3087
3147
|
*/
|
|
3088
3148
|
waitForUploadComplete() {
|
|
3089
3149
|
return new Promise((resolve, reject) => {
|
|
@@ -3092,7 +3152,7 @@ class ChunkedUploader {
|
|
|
3092
3152
|
});
|
|
3093
3153
|
}
|
|
3094
3154
|
/**
|
|
3095
|
-
* 初始化Resumable实例
|
|
3155
|
+
* 初始化 Resumable 实例
|
|
3096
3156
|
*/
|
|
3097
3157
|
initResumable(initResult) {
|
|
3098
3158
|
if (this.resumable) {
|
|
@@ -3117,7 +3177,7 @@ class ChunkedUploader {
|
|
|
3117
3177
|
this.bindResumableEvents();
|
|
3118
3178
|
}
|
|
3119
3179
|
/**
|
|
3120
|
-
* 绑定Resumable事件监听器
|
|
3180
|
+
* 绑定 Resumable 事件监听器
|
|
3121
3181
|
*/
|
|
3122
3182
|
bindResumableEvents() {
|
|
3123
3183
|
this.resumable.on("progress", () => {
|
|
@@ -3140,9 +3200,7 @@ class ChunkedUploader {
|
|
|
3140
3200
|
this.handleResumableError(message);
|
|
3141
3201
|
});
|
|
3142
3202
|
this.resumable.on("fileAdded", () => {
|
|
3143
|
-
|
|
3144
|
-
this.resumable.upload();
|
|
3145
|
-
}
|
|
3203
|
+
this.resumable.upload();
|
|
3146
3204
|
});
|
|
3147
3205
|
}
|
|
3148
3206
|
/**
|
|
@@ -3279,22 +3337,17 @@ class ImportDialogUploader {
|
|
|
3279
3337
|
initUploaders() {
|
|
3280
3338
|
const uploadConfig = this.config.uploadConfig;
|
|
3281
3339
|
if ((uploadConfig == null ? void 0 : uploadConfig.chunkedUpload) && !this.config.multiple) {
|
|
3282
|
-
this.chunkedUploader = new ChunkedUploader(
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
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
|
-
}
|
|
3340
|
+
this.chunkedUploader = new ChunkedUploader(uploadConfig.chunkedUpload, {
|
|
3341
|
+
onProgress: (fileItem, progress) => {
|
|
3342
|
+
var _a, _b, _c, _d;
|
|
3343
|
+
(_b = (_a = this.callbacks).onUploadProgress) == null ? void 0 : _b.call(_a, fileItem, progress);
|
|
3344
|
+
(_d = (_c = this.callbacks).onUpdate) == null ? void 0 : _d.call(_c);
|
|
3294
3345
|
},
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3346
|
+
onUpdate: () => {
|
|
3347
|
+
var _a, _b;
|
|
3348
|
+
(_b = (_a = this.callbacks).onUpdate) == null ? void 0 : _b.call(_a);
|
|
3349
|
+
}
|
|
3350
|
+
});
|
|
3298
3351
|
}
|
|
3299
3352
|
}
|
|
3300
3353
|
/**
|
|
@@ -3321,37 +3374,98 @@ class ImportDialogUploader {
|
|
|
3321
3374
|
this.uploadMessage = "";
|
|
3322
3375
|
this.uploadMessageType = "info";
|
|
3323
3376
|
}
|
|
3377
|
+
/**
|
|
3378
|
+
* 将文件大小转换为字节
|
|
3379
|
+
* @param size 大小数值
|
|
3380
|
+
* @param unit 单位
|
|
3381
|
+
* @returns 字节数
|
|
3382
|
+
*/
|
|
3383
|
+
convertToBytes(size, unit = "MB") {
|
|
3384
|
+
const units = {
|
|
3385
|
+
KB: 1024,
|
|
3386
|
+
MB: 1024 * 1024,
|
|
3387
|
+
GB: 1024 * 1024 * 1024
|
|
3388
|
+
};
|
|
3389
|
+
return size * units[unit];
|
|
3390
|
+
}
|
|
3391
|
+
/**
|
|
3392
|
+
* 检查文件格式是否符合要求
|
|
3393
|
+
* @param file 文件
|
|
3394
|
+
* @param acceptTypes 接受的文件类型,如 ".xls,.xlsx,.csv"
|
|
3395
|
+
* @returns 是否符合要求
|
|
3396
|
+
*/
|
|
3397
|
+
isValidFileType(file, acceptTypes) {
|
|
3398
|
+
if (!acceptTypes) return true;
|
|
3399
|
+
const fileName = file.name.toLowerCase();
|
|
3400
|
+
const fileExt = fileName.substring(fileName.lastIndexOf("."));
|
|
3401
|
+
const acceptList = acceptTypes.toLowerCase().split(",").map((ext) => ext.trim());
|
|
3402
|
+
return acceptList.some((accept) => {
|
|
3403
|
+
if (accept.startsWith(".")) {
|
|
3404
|
+
return fileExt === accept;
|
|
3405
|
+
}
|
|
3406
|
+
if (accept.includes("/")) {
|
|
3407
|
+
const [type, subtype] = accept.split("/");
|
|
3408
|
+
if (subtype === "*") {
|
|
3409
|
+
return file.type.startsWith(type + "/");
|
|
3410
|
+
}
|
|
3411
|
+
return file.type === accept;
|
|
3412
|
+
}
|
|
3413
|
+
return false;
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3324
3416
|
/**
|
|
3325
3417
|
* 文件上传之前的校验 选择文件时调用
|
|
3326
3418
|
*/
|
|
3327
3419
|
beforeUpload(files) {
|
|
3328
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3420
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3329
3421
|
const fileArray = Array.isArray(files) ? files : [files];
|
|
3330
3422
|
if (!fileArray.length) {
|
|
3331
|
-
(_b = (_a = this.callbacks).onMessage) == null ? void 0 : _b.call(_a, "
|
|
3423
|
+
(_b = (_a = this.callbacks).onMessage) == null ? void 0 : _b.call(_a, t("pleaseSelectFile"), "warning");
|
|
3332
3424
|
return false;
|
|
3333
3425
|
}
|
|
3334
|
-
if (this.config.multiple) {
|
|
3426
|
+
if (this.config.multiple && this.config.maxFiles != null) {
|
|
3335
3427
|
const totalFiles = this.uploadFileList.length + fileArray.length;
|
|
3336
3428
|
if (totalFiles > this.config.maxFiles) {
|
|
3337
3429
|
(_d = (_c = this.callbacks).onMessage) == null ? void 0 : _d.call(
|
|
3338
3430
|
_c,
|
|
3339
|
-
|
|
3431
|
+
t("maxFilesLimit", { max: this.config.maxFiles }),
|
|
3340
3432
|
"warning"
|
|
3341
3433
|
);
|
|
3342
3434
|
return false;
|
|
3343
3435
|
}
|
|
3344
3436
|
}
|
|
3345
3437
|
for (const file of fileArray) {
|
|
3346
|
-
if (file
|
|
3438
|
+
if (!this.isValidFileType(file, this.config.acceptTypes)) {
|
|
3439
|
+
const acceptTypes = this.config.acceptTypes || "";
|
|
3347
3440
|
(_f = (_e = this.callbacks).onMessage) == null ? void 0 : _f.call(
|
|
3348
3441
|
_e,
|
|
3349
|
-
|
|
3442
|
+
t("fileFormatNotSupported", { name: file.name, types: acceptTypes }),
|
|
3350
3443
|
"warning"
|
|
3351
3444
|
);
|
|
3352
3445
|
return false;
|
|
3353
3446
|
}
|
|
3354
3447
|
}
|
|
3448
|
+
if (this.config.maxFileSize != null) {
|
|
3449
|
+
const maxFileSizeUnit = this.config.maxFileSizeUnit || "MB";
|
|
3450
|
+
const maxFileSizeBytes = this.convertToBytes(
|
|
3451
|
+
this.config.maxFileSize,
|
|
3452
|
+
maxFileSizeUnit
|
|
3453
|
+
);
|
|
3454
|
+
for (const file of fileArray) {
|
|
3455
|
+
if (file.size > maxFileSizeBytes) {
|
|
3456
|
+
(_h = (_g = this.callbacks).onMessage) == null ? void 0 : _h.call(
|
|
3457
|
+
_g,
|
|
3458
|
+
t("fileSizeExceeded", {
|
|
3459
|
+
name: file.name,
|
|
3460
|
+
size: this.config.maxFileSize,
|
|
3461
|
+
unit: maxFileSizeUnit
|
|
3462
|
+
}),
|
|
3463
|
+
"warning"
|
|
3464
|
+
);
|
|
3465
|
+
return false;
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3355
3469
|
for (const file of fileArray) {
|
|
3356
3470
|
const fileItem = {
|
|
3357
3471
|
id: generateId(),
|
|
@@ -3369,8 +3483,8 @@ class ImportDialogUploader {
|
|
|
3369
3483
|
this.fileList = [file];
|
|
3370
3484
|
}
|
|
3371
3485
|
}
|
|
3372
|
-
(
|
|
3373
|
-
(
|
|
3486
|
+
(_j = (_i = this.callbacks).onUpdate) == null ? void 0 : _j.call(_i);
|
|
3487
|
+
(_l = (_k = this.callbacks).onFileChange) == null ? void 0 : _l.call(_k, this.uploadFileList);
|
|
3374
3488
|
if (this.shouldUseChunkedUpload()) {
|
|
3375
3489
|
this.processChunkedUpload();
|
|
3376
3490
|
} else {
|
|
@@ -3380,7 +3494,9 @@ class ImportDialogUploader {
|
|
|
3380
3494
|
}
|
|
3381
3495
|
/**
|
|
3382
3496
|
* 处理分片上传
|
|
3383
|
-
*
|
|
3497
|
+
* 根据 autoUpload 配置决定是否立即上传
|
|
3498
|
+
* - autoUpload: true → 立即开始上传
|
|
3499
|
+
* - autoUpload: false/undefined → 等待用户点击确认后上传
|
|
3384
3500
|
*/
|
|
3385
3501
|
processChunkedUpload() {
|
|
3386
3502
|
return __async$1(this, null, function* () {
|
|
@@ -3450,7 +3566,7 @@ class ImportDialogUploader {
|
|
|
3450
3566
|
(_e = (_d = this.callbacks).onUploadSuccess) == null ? void 0 : _e.call(_d, fileItem, fileItem.response);
|
|
3451
3567
|
} catch (error) {
|
|
3452
3568
|
fileItem.status = "error";
|
|
3453
|
-
fileItem.errorMessage = error instanceof Error ? error.message : "
|
|
3569
|
+
fileItem.errorMessage = error instanceof Error ? error.message : t("processingFailed");
|
|
3454
3570
|
(_g = (_f = this.callbacks).onUploadError) == null ? void 0 : _g.call(_f, fileItem, error);
|
|
3455
3571
|
}
|
|
3456
3572
|
this.isUploading = this.uploadFileList.some(
|
|
@@ -3474,7 +3590,7 @@ class ImportDialogUploader {
|
|
|
3474
3590
|
if (index !== void 0 && index >= 0 && index < this.uploadFileList.length) {
|
|
3475
3591
|
const fileItem = this.uploadFileList[index];
|
|
3476
3592
|
if (needCheckStatus && fileItem.status === "uploading") {
|
|
3477
|
-
(_c = (_b = this.callbacks).onMessage) == null ? void 0 : _c.call(_b, "
|
|
3593
|
+
(_c = (_b = this.callbacks).onMessage) == null ? void 0 : _c.call(_b, t("fileUploadingCannotDelete"), "warning");
|
|
3478
3594
|
return false;
|
|
3479
3595
|
}
|
|
3480
3596
|
this.uploadFileList.splice(index, 1);
|
|
@@ -3485,7 +3601,7 @@ class ImportDialogUploader {
|
|
|
3485
3601
|
(f) => f.status === "uploading"
|
|
3486
3602
|
);
|
|
3487
3603
|
if (hasUploading) {
|
|
3488
|
-
(_e = (_d = this.callbacks).onMessage) == null ? void 0 : _e.call(_d, "
|
|
3604
|
+
(_e = (_d = this.callbacks).onMessage) == null ? void 0 : _e.call(_d, t("filesUploadingCannotClear"), "warning");
|
|
3489
3605
|
return false;
|
|
3490
3606
|
}
|
|
3491
3607
|
}
|
|
@@ -3508,7 +3624,7 @@ class ImportDialogUploader {
|
|
|
3508
3624
|
*/
|
|
3509
3625
|
uploadSingleFile(fileItem) {
|
|
3510
3626
|
return __async$1(this, null, function* () {
|
|
3511
|
-
var _a, _b, _c, _d, _e, _f;
|
|
3627
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3512
3628
|
fileItem.status = "uploading";
|
|
3513
3629
|
fileItem.progress = 0;
|
|
3514
3630
|
this.isUploading = true;
|
|
@@ -3521,9 +3637,15 @@ class ImportDialogUploader {
|
|
|
3521
3637
|
return fileItem.response;
|
|
3522
3638
|
} catch (error) {
|
|
3523
3639
|
fileItem.status = "error";
|
|
3524
|
-
fileItem.errorMessage = error instanceof Error ? error.message : "
|
|
3640
|
+
fileItem.errorMessage = error instanceof Error ? error.message : t("uploadFailed");
|
|
3525
3641
|
(_f = (_e = this.callbacks).onUploadError) == null ? void 0 : _f.call(_e, fileItem, error);
|
|
3526
3642
|
throw error;
|
|
3643
|
+
} finally {
|
|
3644
|
+
this.isUploading = this.uploadFileList.some(
|
|
3645
|
+
(f) => f.status === "uploading"
|
|
3646
|
+
);
|
|
3647
|
+
(_h = (_g = this.callbacks).onUpdate) == null ? void 0 : _h.call(_g);
|
|
3648
|
+
this.updateOverallProgress();
|
|
3527
3649
|
}
|
|
3528
3650
|
});
|
|
3529
3651
|
}
|
|
@@ -3533,7 +3655,7 @@ class ImportDialogUploader {
|
|
|
3533
3655
|
uploadFileChunked(fileItem) {
|
|
3534
3656
|
return __async$1(this, null, function* () {
|
|
3535
3657
|
if (!this.chunkedUploader) {
|
|
3536
|
-
throw new Error("
|
|
3658
|
+
throw new Error(t("chunkedUploadConfigRequired"));
|
|
3537
3659
|
}
|
|
3538
3660
|
return yield this.chunkedUploader.upload(fileItem);
|
|
3539
3661
|
});
|
|
@@ -3770,8 +3892,7 @@ const _ImportDialog = class _ImportDialog2 {
|
|
|
3770
3892
|
this.uploader = new ImportDialogUploader(
|
|
3771
3893
|
{
|
|
3772
3894
|
multiple: false,
|
|
3773
|
-
|
|
3774
|
-
maxFileSize: 100 * 1024 * 1024
|
|
3895
|
+
maxFileSizeUnit: "MB"
|
|
3775
3896
|
},
|
|
3776
3897
|
{
|
|
3777
3898
|
onUpdate: () => this.updateModal(),
|
|
@@ -3834,7 +3955,7 @@ const _ImportDialog = class _ImportDialog2 {
|
|
|
3834
3955
|
formData: this.formData,
|
|
3835
3956
|
uploadFileList: this.uploader.uploadFileList,
|
|
3836
3957
|
multiple: ((_a = this.modalOptions.uploadConfig) == null ? void 0 : _a.multiple) != null ? this.modalOptions.uploadConfig.multiple : false,
|
|
3837
|
-
maxFiles: (
|
|
3958
|
+
maxFiles: (_b = this.modalOptions.uploadConfig) == null ? void 0 : _b.maxFiles,
|
|
3838
3959
|
confirmLoading: this.confirmLoading,
|
|
3839
3960
|
isUploading: this.uploader.isUploading,
|
|
3840
3961
|
uploadProgress: this.uploader.uploadProgress,
|
|
@@ -4173,7 +4294,7 @@ const _ImportDialog = class _ImportDialog2 {
|
|
|
4173
4294
|
return;
|
|
4174
4295
|
}
|
|
4175
4296
|
if (this.uploader.hasUploadingFiles()) {
|
|
4176
|
-
this.showMessage("
|
|
4297
|
+
this.showMessage(t("filesUploading"), "warning");
|
|
4177
4298
|
return;
|
|
4178
4299
|
}
|
|
4179
4300
|
if (this.uploader.hasPendingFiles()) {
|
|
@@ -4185,7 +4306,7 @@ const _ImportDialog = class _ImportDialog2 {
|
|
|
4185
4306
|
try {
|
|
4186
4307
|
const chunkResult = yield this.uploader.startUpload();
|
|
4187
4308
|
} catch (error) {
|
|
4188
|
-
this.showMessage("
|
|
4309
|
+
this.showMessage(t("uploadFailedRetry"), "error");
|
|
4189
4310
|
if (confirmLoadingEnabled2) {
|
|
4190
4311
|
this.confirmLoading = false;
|
|
4191
4312
|
this.updateModal();
|
|
@@ -4196,7 +4317,7 @@ const _ImportDialog = class _ImportDialog2 {
|
|
|
4196
4317
|
const failedFiles = this.uploader.getFailedFiles();
|
|
4197
4318
|
if (failedFiles.length > 0) {
|
|
4198
4319
|
this.showMessage(
|
|
4199
|
-
|
|
4320
|
+
t("filesUploadFailed", { count: failedFiles.length }),
|
|
4200
4321
|
"warning"
|
|
4201
4322
|
);
|
|
4202
4323
|
const confirmLoadingEnabled2 = ((_b = this.modalOptions.uploadConfig) == null ? void 0 : _b.confirmLoading) != null ? this.modalOptions.uploadConfig.confirmLoading : true;
|
|
@@ -4264,8 +4385,10 @@ const _ImportDialog = class _ImportDialog2 {
|
|
|
4264
4385
|
const uploadConfig = options == null ? void 0 : options.uploadConfig;
|
|
4265
4386
|
this.uploader.updateConfig({
|
|
4266
4387
|
multiple: (uploadConfig == null ? void 0 : uploadConfig.multiple) != null ? uploadConfig.multiple : false,
|
|
4267
|
-
maxFiles:
|
|
4268
|
-
maxFileSize:
|
|
4388
|
+
maxFiles: uploadConfig == null ? void 0 : uploadConfig.maxFiles,
|
|
4389
|
+
maxFileSize: uploadConfig == null ? void 0 : uploadConfig.maxFileSize,
|
|
4390
|
+
maxFileSizeUnit: (uploadConfig == null ? void 0 : uploadConfig.maxFileSizeUnit) != null ? uploadConfig.maxFileSizeUnit : "MB",
|
|
4391
|
+
acceptTypes: this.currentConfig.acceptTypes,
|
|
4269
4392
|
uploadConfig
|
|
4270
4393
|
});
|
|
4271
4394
|
this.activeTabIndex = (options == null ? void 0 : options.defaultActiveTab) || 0;
|