@sl-material/sl-import 1.0.0-beta10 → 1.0.0-beta12
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 +17 -103
- package/index.d.ts +14 -5
- package/package.json +1 -1
- package/sl-import.cjs.js +1 -1
- package/sl-import.es.js +80 -94
- package/sl-import.umd.umd.js +12 -12
package/sl-import.es.js
CHANGED
|
@@ -2886,12 +2886,12 @@ class ImportDialogRenderer {
|
|
|
2886
2886
|
<path d="M4 6C4 4.89543 4.89543 4 6 4H14L18 8H26C27.1046 8 28 8.89543 28 10V26C28 27.1046 27.1046 28 26 28H6C4.89543 28 4 27.1046 4 26V6Z" fill="${iconColor}"/>
|
|
2887
2887
|
</svg>
|
|
2888
2888
|
</div>
|
|
2889
|
-
<
|
|
2889
|
+
<div class="import-dialog-vanilla-file-remove-btn" data-file-index="${index}" title="删除">
|
|
2890
2890
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2891
2891
|
<circle cx="8" cy="8" r="8" fill="rgba(0,0,0)"/>
|
|
2892
2892
|
<path d="M5 5L11 11M11 5L5 11" stroke="white" stroke-width="1.5" stroke-linecap="round"/>
|
|
2893
2893
|
</svg>
|
|
2894
|
-
</
|
|
2894
|
+
</div>
|
|
2895
2895
|
<div class="import-dialog-vanilla-file-info">
|
|
2896
2896
|
<div class="import-dialog-vanilla-file-name" title="${fileItem.name}">${fileItem.name}</div>
|
|
2897
2897
|
<div class="import-dialog-vanilla-file-meta">
|
|
@@ -3120,50 +3120,6 @@ class ChunkedUploader {
|
|
|
3120
3120
|
this.cleanup();
|
|
3121
3121
|
}
|
|
3122
3122
|
}
|
|
3123
|
-
class SimpleUploader {
|
|
3124
|
-
constructor(options, callbacks = {}) {
|
|
3125
|
-
__publicField(this, "customUpload");
|
|
3126
|
-
__publicField(this, "callbacks");
|
|
3127
|
-
__publicField(this, "getFileList");
|
|
3128
|
-
__publicField(this, "removeFile");
|
|
3129
|
-
this.customUpload = options.customUpload;
|
|
3130
|
-
this.getFileList = options.getFileList;
|
|
3131
|
-
this.removeFile = options.removeFile;
|
|
3132
|
-
this.callbacks = callbacks;
|
|
3133
|
-
}
|
|
3134
|
-
/**
|
|
3135
|
-
* 更新自定义上传函数
|
|
3136
|
-
*/
|
|
3137
|
-
updateCustomUpload(customUpload) {
|
|
3138
|
-
this.customUpload = customUpload;
|
|
3139
|
-
}
|
|
3140
|
-
/**
|
|
3141
|
-
* 上传单个文件
|
|
3142
|
-
*/
|
|
3143
|
-
async upload(fileItem) {
|
|
3144
|
-
if (this.customUpload) {
|
|
3145
|
-
const context = {
|
|
3146
|
-
fileList: [...this.getFileList()],
|
|
3147
|
-
removeFile: (index) => {
|
|
3148
|
-
this.removeFile(index);
|
|
3149
|
-
}
|
|
3150
|
-
};
|
|
3151
|
-
const response = await this.customUpload(
|
|
3152
|
-
fileItem.file,
|
|
3153
|
-
context,
|
|
3154
|
-
(progress) => {
|
|
3155
|
-
var _a, _b, _c, _d;
|
|
3156
|
-
fileItem.progress = progress;
|
|
3157
|
-
(_b = (_a = this.callbacks).onProgress) == null ? void 0 : _b.call(_a, fileItem, progress);
|
|
3158
|
-
(_d = (_c = this.callbacks).onUpdate) == null ? void 0 : _d.call(_c);
|
|
3159
|
-
}
|
|
3160
|
-
);
|
|
3161
|
-
return response;
|
|
3162
|
-
} else {
|
|
3163
|
-
return fileItem.file;
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
3123
|
const generateId = () => {
|
|
3168
3124
|
return `file_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
3169
3125
|
};
|
|
@@ -3171,9 +3127,8 @@ class ImportDialogUploader {
|
|
|
3171
3127
|
constructor(config, callbacks = {}) {
|
|
3172
3128
|
__publicField(this, "config");
|
|
3173
3129
|
__publicField(this, "callbacks");
|
|
3174
|
-
//
|
|
3130
|
+
// 分片上传器实例
|
|
3175
3131
|
__publicField(this, "chunkedUploader", null);
|
|
3176
|
-
__publicField(this, "simpleUploader", null);
|
|
3177
3132
|
// 并发上传队列
|
|
3178
3133
|
__publicField(this, "uploadQueue", []);
|
|
3179
3134
|
__publicField(this, "activeUploads", 0);
|
|
@@ -3208,24 +3163,6 @@ class ImportDialogUploader {
|
|
|
3208
3163
|
}
|
|
3209
3164
|
});
|
|
3210
3165
|
}
|
|
3211
|
-
this.simpleUploader = new SimpleUploader(
|
|
3212
|
-
{
|
|
3213
|
-
customUpload: uploadConfig == null ? void 0 : uploadConfig.customUpload,
|
|
3214
|
-
getFileList: () => this.uploadFileList,
|
|
3215
|
-
removeFile: (index) => this.removeFile(index)
|
|
3216
|
-
},
|
|
3217
|
-
{
|
|
3218
|
-
onProgress: (fileItem, progress) => {
|
|
3219
|
-
var _a, _b, _c, _d;
|
|
3220
|
-
(_b = (_a = this.callbacks).onUploadProgress) == null ? void 0 : _b.call(_a, fileItem, progress);
|
|
3221
|
-
(_d = (_c = this.callbacks).onUpdate) == null ? void 0 : _d.call(_c);
|
|
3222
|
-
},
|
|
3223
|
-
onUpdate: () => {
|
|
3224
|
-
var _a, _b;
|
|
3225
|
-
return (_b = (_a = this.callbacks).onUpdate) == null ? void 0 : _b.call(_a);
|
|
3226
|
-
}
|
|
3227
|
-
}
|
|
3228
|
-
);
|
|
3229
3166
|
}
|
|
3230
3167
|
/**
|
|
3231
3168
|
* 获取并发限制数
|
|
@@ -3263,7 +3200,7 @@ class ImportDialogUploader {
|
|
|
3263
3200
|
* 文件上传之前的校验 选择文件时调用
|
|
3264
3201
|
*/
|
|
3265
3202
|
beforeUpload(files) {
|
|
3266
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j
|
|
3203
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
3267
3204
|
const fileArray = Array.isArray(files) ? files : [files];
|
|
3268
3205
|
if (!fileArray.length) {
|
|
3269
3206
|
(_b = (_a = this.callbacks).onMessage) == null ? void 0 : _b.call(_a, "请选择文件", "warning");
|
|
@@ -3309,12 +3246,69 @@ class ImportDialogUploader {
|
|
|
3309
3246
|
}
|
|
3310
3247
|
(_h = (_g = this.callbacks).onUpdate) == null ? void 0 : _h.call(_g);
|
|
3311
3248
|
(_j = (_i = this.callbacks).onFileChange) == null ? void 0 : _j.call(_i, this.uploadFileList);
|
|
3312
|
-
|
|
3313
|
-
if (autoUpload) {
|
|
3314
|
-
this.startUploadFiles();
|
|
3315
|
-
}
|
|
3249
|
+
this.processFilesWithCustomUpload();
|
|
3316
3250
|
return true;
|
|
3317
3251
|
}
|
|
3252
|
+
/**
|
|
3253
|
+
* 使用 customUpload 预处理文件
|
|
3254
|
+
* 在选择文件后立即调用,用于二次加工参数或自定义校验
|
|
3255
|
+
*/
|
|
3256
|
+
async processFilesWithCustomUpload() {
|
|
3257
|
+
const pendingFiles = this.uploadFileList.filter(
|
|
3258
|
+
(f) => f.status === "pending"
|
|
3259
|
+
);
|
|
3260
|
+
for (const fileItem of pendingFiles) {
|
|
3261
|
+
await this.processFileWithCustomUpload(fileItem);
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
/**
|
|
3265
|
+
* 单个文件的预处理
|
|
3266
|
+
*/
|
|
3267
|
+
async processFileWithCustomUpload(fileItem) {
|
|
3268
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3269
|
+
const customUpload = (_a = this.config.uploadConfig) == null ? void 0 : _a.customUpload;
|
|
3270
|
+
if (!customUpload) {
|
|
3271
|
+
fileItem.status = "success";
|
|
3272
|
+
fileItem.progress = 100;
|
|
3273
|
+
fileItem.response = fileItem.file;
|
|
3274
|
+
(_c = (_b = this.callbacks).onUpdate) == null ? void 0 : _c.call(_b);
|
|
3275
|
+
return;
|
|
3276
|
+
}
|
|
3277
|
+
fileItem.status = "uploading";
|
|
3278
|
+
fileItem.progress = 0;
|
|
3279
|
+
this.isUploading = true;
|
|
3280
|
+
(_e = (_d = this.callbacks).onUpdate) == null ? void 0 : _e.call(_d);
|
|
3281
|
+
try {
|
|
3282
|
+
const context = {
|
|
3283
|
+
fileList: [...this.uploadFileList],
|
|
3284
|
+
removeFile: (index) => {
|
|
3285
|
+
this.removeFile(index);
|
|
3286
|
+
}
|
|
3287
|
+
};
|
|
3288
|
+
fileItem.response = await customUpload(
|
|
3289
|
+
fileItem.file,
|
|
3290
|
+
context,
|
|
3291
|
+
(progress) => {
|
|
3292
|
+
var _a2, _b2, _c2, _d2;
|
|
3293
|
+
fileItem.progress = progress;
|
|
3294
|
+
(_b2 = (_a2 = this.callbacks).onUploadProgress) == null ? void 0 : _b2.call(_a2, fileItem, progress);
|
|
3295
|
+
(_d2 = (_c2 = this.callbacks).onUpdate) == null ? void 0 : _d2.call(_c2);
|
|
3296
|
+
}
|
|
3297
|
+
);
|
|
3298
|
+
fileItem.status = "success";
|
|
3299
|
+
fileItem.progress = 100;
|
|
3300
|
+
(_g = (_f = this.callbacks).onUploadSuccess) == null ? void 0 : _g.call(_f, fileItem, fileItem.response);
|
|
3301
|
+
} catch (error) {
|
|
3302
|
+
fileItem.status = "error";
|
|
3303
|
+
fileItem.errorMessage = error instanceof Error ? error.message : "处理失败";
|
|
3304
|
+
(_i = (_h = this.callbacks).onUploadError) == null ? void 0 : _i.call(_h, fileItem, error);
|
|
3305
|
+
}
|
|
3306
|
+
this.isUploading = this.uploadFileList.some(
|
|
3307
|
+
(f) => f.status === "uploading"
|
|
3308
|
+
);
|
|
3309
|
+
(_k = (_j = this.callbacks).onUpdate) == null ? void 0 : _k.call(_j);
|
|
3310
|
+
this.updateOverallProgress();
|
|
3311
|
+
}
|
|
3318
3312
|
/**
|
|
3319
3313
|
* 删除文件
|
|
3320
3314
|
*/
|
|
@@ -3366,14 +3360,8 @@ class ImportDialogUploader {
|
|
|
3366
3360
|
});
|
|
3367
3361
|
}
|
|
3368
3362
|
}
|
|
3369
|
-
async startUploadFiles() {
|
|
3370
|
-
const pendingFiles = this.uploadFileList.filter(
|
|
3371
|
-
(f) => f.status === "pending"
|
|
3372
|
-
);
|
|
3373
|
-
this.enqueueUpload(pendingFiles);
|
|
3374
|
-
}
|
|
3375
3363
|
/**
|
|
3376
|
-
*
|
|
3364
|
+
* 单个文件分片上传
|
|
3377
3365
|
* @param fileItem
|
|
3378
3366
|
*/
|
|
3379
3367
|
async uploadSingleFile(fileItem) {
|
|
@@ -3383,11 +3371,7 @@ class ImportDialogUploader {
|
|
|
3383
3371
|
this.isUploading = true;
|
|
3384
3372
|
(_b = (_a = this.callbacks).onUpdate) == null ? void 0 : _b.call(_a);
|
|
3385
3373
|
try {
|
|
3386
|
-
|
|
3387
|
-
fileItem.response = await this.uploadFileChunked(fileItem);
|
|
3388
|
-
} else {
|
|
3389
|
-
fileItem.response = await this.uploadFileSimple(fileItem);
|
|
3390
|
-
}
|
|
3374
|
+
fileItem.response = await this.uploadFileChunked(fileItem);
|
|
3391
3375
|
fileItem.status = "success";
|
|
3392
3376
|
fileItem.progress = 100;
|
|
3393
3377
|
(_d = (_c = this.callbacks).onUploadSuccess) == null ? void 0 : _d.call(_c, fileItem, fileItem.response);
|
|
@@ -3402,15 +3386,6 @@ class ImportDialogUploader {
|
|
|
3402
3386
|
(_h = (_g = this.callbacks).onUpdate) == null ? void 0 : _h.call(_g);
|
|
3403
3387
|
this.updateOverallProgress();
|
|
3404
3388
|
}
|
|
3405
|
-
/**
|
|
3406
|
-
* 普通上传(非分片)
|
|
3407
|
-
*/
|
|
3408
|
-
async uploadFileSimple(fileItem) {
|
|
3409
|
-
if (!this.simpleUploader) {
|
|
3410
|
-
throw new Error("SimpleUploader 未初始化");
|
|
3411
|
-
}
|
|
3412
|
-
return await this.simpleUploader.upload(fileItem);
|
|
3413
|
-
}
|
|
3414
3389
|
/**
|
|
3415
3390
|
* 分片上传
|
|
3416
3391
|
*/
|
|
@@ -3421,10 +3396,21 @@ class ImportDialogUploader {
|
|
|
3421
3396
|
return await this.chunkedUploader.upload(fileItem);
|
|
3422
3397
|
}
|
|
3423
3398
|
/**
|
|
3424
|
-
*
|
|
3399
|
+
* 手动触发分片上传(仅用于分片上传场景)
|
|
3425
3400
|
*/
|
|
3426
3401
|
async startUpload() {
|
|
3427
|
-
|
|
3402
|
+
if (this.shouldUseChunkedUpload()) {
|
|
3403
|
+
await this.startChunkedUploadFiles();
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
/**
|
|
3407
|
+
* 启动分片上传
|
|
3408
|
+
*/
|
|
3409
|
+
async startChunkedUploadFiles() {
|
|
3410
|
+
const pendingFiles = this.uploadFileList.filter(
|
|
3411
|
+
(f) => f.status === "pending"
|
|
3412
|
+
);
|
|
3413
|
+
this.enqueueUpload(pendingFiles);
|
|
3428
3414
|
}
|
|
3429
3415
|
/**
|
|
3430
3416
|
* 暂停上传(仅分片上传支持)
|