@sl-material/sl-import 1.0.0 → 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/package.json +1 -1
- package/sl-import.cjs.js +1 -1
- package/sl-import.es.js +17 -56
- package/sl-import.umd.umd.js +19 -19
package/sl-import.es.js
CHANGED
|
@@ -2918,7 +2918,7 @@ class ChunkedUploader {
|
|
|
2918
2918
|
fileItem.file.name,
|
|
2919
2919
|
fileItem.file.size
|
|
2920
2920
|
);
|
|
2921
|
-
|
|
2921
|
+
console.info("upload>>>分片结果", initResult);
|
|
2922
2922
|
this.currentFileItem = fileItem;
|
|
2923
2923
|
this.initResumable(initResult);
|
|
2924
2924
|
this.resumable.addFile(fileItem.file);
|
|
@@ -2941,6 +2941,7 @@ class ChunkedUploader {
|
|
|
2941
2941
|
* 初始化Resumable实例
|
|
2942
2942
|
*/
|
|
2943
2943
|
initResumable(initResult) {
|
|
2944
|
+
console.log("[分片上传] 初始化分片上传...", initResult);
|
|
2944
2945
|
if (this.resumable) {
|
|
2945
2946
|
this.resumable.cancel();
|
|
2946
2947
|
}
|
|
@@ -2959,6 +2960,7 @@ class ChunkedUploader {
|
|
|
2959
2960
|
forceChunkSize: true
|
|
2960
2961
|
};
|
|
2961
2962
|
const finalConfig = { ...defaultConfig, ...customConfig };
|
|
2963
|
+
console.info("finalConfig>>>分片上传配置", finalConfig);
|
|
2962
2964
|
this.resumable = new Resumable(finalConfig);
|
|
2963
2965
|
this.bindResumableEvents();
|
|
2964
2966
|
}
|
|
@@ -2969,6 +2971,7 @@ class ChunkedUploader {
|
|
|
2969
2971
|
this.resumable.on("progress", () => {
|
|
2970
2972
|
var _a, _b, _c, _d;
|
|
2971
2973
|
const progress = Math.floor(this.resumable.progress() * 100);
|
|
2974
|
+
console.log(`[Resumable分片上传] 进度: ${progress}%`);
|
|
2972
2975
|
if (this.currentFileItem) {
|
|
2973
2976
|
this.currentFileItem.progress = Math.min(progress, 90);
|
|
2974
2977
|
(_b = (_a = this.callbacks).onProgress) == null ? void 0 : _b.call(
|
|
@@ -2980,6 +2983,7 @@ class ChunkedUploader {
|
|
|
2980
2983
|
(_d = (_c = this.callbacks).onUpdate) == null ? void 0 : _d.call(_c);
|
|
2981
2984
|
});
|
|
2982
2985
|
this.resumable.on("fileSuccess", () => {
|
|
2986
|
+
console.log("[Resumable分片上传] 文件上传成功");
|
|
2983
2987
|
this.handleResumableComplete();
|
|
2984
2988
|
});
|
|
2985
2989
|
this.resumable.on("error", (message) => {
|
|
@@ -2987,6 +2991,7 @@ class ChunkedUploader {
|
|
|
2987
2991
|
this.handleResumableError(message);
|
|
2988
2992
|
});
|
|
2989
2993
|
this.resumable.on("fileAdded", () => {
|
|
2994
|
+
console.info("fileAdded>>>开始上传");
|
|
2990
2995
|
this.resumable.upload();
|
|
2991
2996
|
});
|
|
2992
2997
|
}
|
|
@@ -3070,9 +3075,6 @@ class ImportDialogUploader {
|
|
|
3070
3075
|
__publicField(this, "callbacks");
|
|
3071
3076
|
// 分片上传器实例
|
|
3072
3077
|
__publicField(this, "chunkedUploader", null);
|
|
3073
|
-
// 并发上传队列
|
|
3074
|
-
__publicField(this, "uploadQueue", []);
|
|
3075
|
-
__publicField(this, "activeUploads", 0);
|
|
3076
3078
|
// 上传状态
|
|
3077
3079
|
__publicField(this, "uploadFileList", []);
|
|
3078
3080
|
//上传文件列表
|
|
@@ -3105,12 +3107,6 @@ class ImportDialogUploader {
|
|
|
3105
3107
|
});
|
|
3106
3108
|
}
|
|
3107
3109
|
}
|
|
3108
|
-
/**
|
|
3109
|
-
* 获取并发限制数
|
|
3110
|
-
*/
|
|
3111
|
-
get concurrentLimit() {
|
|
3112
|
-
return this.config.concurrentLimit != null ? this.config.concurrentLimit : 3;
|
|
3113
|
-
}
|
|
3114
3110
|
/**
|
|
3115
3111
|
* 判断是否应该使用分片上传
|
|
3116
3112
|
* 条件:配置了chunkedUpload 且 是单文件模式
|
|
@@ -3134,8 +3130,6 @@ class ImportDialogUploader {
|
|
|
3134
3130
|
this.isUploading = false;
|
|
3135
3131
|
this.uploadMessage = "";
|
|
3136
3132
|
this.uploadMessageType = "info";
|
|
3137
|
-
this.uploadQueue = [];
|
|
3138
|
-
this.activeUploads = 0;
|
|
3139
3133
|
}
|
|
3140
3134
|
/**
|
|
3141
3135
|
* 文件上传之前的校验 选择文件时调用
|
|
@@ -3268,12 +3262,6 @@ class ImportDialogUploader {
|
|
|
3268
3262
|
(_c = (_b = this.callbacks).onMessage) == null ? void 0 : _c.call(_b, "文件正在上传中,无法删除", "warning");
|
|
3269
3263
|
return false;
|
|
3270
3264
|
}
|
|
3271
|
-
const queueIndex = this.uploadQueue.findIndex(
|
|
3272
|
-
(q) => q.id === fileItem.id
|
|
3273
|
-
);
|
|
3274
|
-
if (queueIndex !== -1) {
|
|
3275
|
-
this.uploadQueue.splice(queueIndex, 1);
|
|
3276
|
-
}
|
|
3277
3265
|
this.uploadFileList.splice(index, 1);
|
|
3278
3266
|
this.fileList.splice(index, 1);
|
|
3279
3267
|
} else {
|
|
@@ -3286,7 +3274,6 @@ class ImportDialogUploader {
|
|
|
3286
3274
|
return false;
|
|
3287
3275
|
}
|
|
3288
3276
|
}
|
|
3289
|
-
this.uploadQueue = [];
|
|
3290
3277
|
this.uploadFileList = [];
|
|
3291
3278
|
this.fileList = [];
|
|
3292
3279
|
}
|
|
@@ -3300,32 +3287,6 @@ class ImportDialogUploader {
|
|
|
3300
3287
|
(_i = (_h = this.callbacks).onUpdate) == null ? void 0 : _i.call(_h);
|
|
3301
3288
|
return true;
|
|
3302
3289
|
}
|
|
3303
|
-
/**
|
|
3304
|
-
* 将文件加入上传队列并启动处理
|
|
3305
|
-
*/
|
|
3306
|
-
enqueueUpload(fileItems) {
|
|
3307
|
-
const newItems = fileItems.filter(
|
|
3308
|
-
(item) => !this.uploadQueue.some((q) => q.id === item.id)
|
|
3309
|
-
);
|
|
3310
|
-
this.uploadQueue.push(...newItems);
|
|
3311
|
-
this.processUploadQueue();
|
|
3312
|
-
}
|
|
3313
|
-
/**
|
|
3314
|
-
* 处理上传队列(支持并发)
|
|
3315
|
-
*/
|
|
3316
|
-
processUploadQueue() {
|
|
3317
|
-
while (this.uploadQueue.length > 0 && this.activeUploads < this.concurrentLimit) {
|
|
3318
|
-
const fileItem = this.uploadQueue.shift();
|
|
3319
|
-
if (fileItem.status !== "pending") {
|
|
3320
|
-
continue;
|
|
3321
|
-
}
|
|
3322
|
-
this.activeUploads++;
|
|
3323
|
-
this.uploadSingleFile(fileItem).finally(() => {
|
|
3324
|
-
this.activeUploads--;
|
|
3325
|
-
this.processUploadQueue();
|
|
3326
|
-
});
|
|
3327
|
-
}
|
|
3328
|
-
}
|
|
3329
3290
|
/**
|
|
3330
3291
|
* 单个文件分片上传
|
|
3331
3292
|
* @param fileItem
|
|
@@ -3362,21 +3323,23 @@ class ImportDialogUploader {
|
|
|
3362
3323
|
return await this.chunkedUploader.upload(fileItem);
|
|
3363
3324
|
}
|
|
3364
3325
|
/**
|
|
3365
|
-
*
|
|
3326
|
+
* 手动触发上传(用于延迟上传场景)
|
|
3327
|
+
* 分片上传:直接调用 uploadSingleFile 并等待完成
|
|
3328
|
+
* 普通上传:已在选择文件时通过 customUpload 处理完成
|
|
3366
3329
|
*/
|
|
3367
3330
|
async startUpload() {
|
|
3368
|
-
if (this.shouldUseChunkedUpload()) {
|
|
3369
|
-
|
|
3331
|
+
if (!this.shouldUseChunkedUpload()) {
|
|
3332
|
+
return;
|
|
3370
3333
|
}
|
|
3371
|
-
}
|
|
3372
|
-
/**
|
|
3373
|
-
* 启动分片上传
|
|
3374
|
-
*/
|
|
3375
|
-
async startChunkedUploadFiles() {
|
|
3376
3334
|
const pendingFiles = this.uploadFileList.filter(
|
|
3377
3335
|
(f) => f.status === "pending"
|
|
3378
3336
|
);
|
|
3379
|
-
|
|
3337
|
+
if (pendingFiles.length === 0) {
|
|
3338
|
+
return;
|
|
3339
|
+
}
|
|
3340
|
+
for (const fileItem of pendingFiles) {
|
|
3341
|
+
await this.uploadSingleFile(fileItem);
|
|
3342
|
+
}
|
|
3380
3343
|
}
|
|
3381
3344
|
/**
|
|
3382
3345
|
* 暂停上传(仅分片上传支持)
|
|
@@ -3398,8 +3361,6 @@ class ImportDialogUploader {
|
|
|
3398
3361
|
cancelUpload() {
|
|
3399
3362
|
var _a, _b, _c;
|
|
3400
3363
|
(_a = this.chunkedUploader) == null ? void 0 : _a.cancel();
|
|
3401
|
-
this.uploadQueue = [];
|
|
3402
|
-
this.activeUploads = 0;
|
|
3403
3364
|
this.isUploading = false;
|
|
3404
3365
|
this.uploadMessage = "上传已取消";
|
|
3405
3366
|
this.uploadMessageType = "info";
|