@sl-material/sl-import 1.0.0-beta10 → 1.0.0-beta11
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 +78 -92
- package/sl-import.umd.umd.js +10 -10
package/README.md
CHANGED
|
@@ -329,74 +329,41 @@ ImportDialog.open({
|
|
|
329
329
|
autoUpload: false,
|
|
330
330
|
customUpload: async (file, context) => {
|
|
331
331
|
// 如果文件数量超过限制,删除第一个文件
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// 正常上传逻辑(可选择是否使用进度回调)
|
|
338
|
-
const formData = new FormData();
|
|
339
|
-
formData.append("file", file);
|
|
340
|
-
|
|
341
|
-
const response = await fetch("/api/upload", {
|
|
342
|
-
method: "POST",
|
|
343
|
-
body: formData,
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
return response.json();
|
|
332
|
+
console.info("file", file, "context", context);
|
|
333
|
+
return {
|
|
334
|
+
file,
|
|
335
|
+
};
|
|
347
336
|
},
|
|
348
337
|
},
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
```typescript
|
|
355
|
-
ImportDialog.open({
|
|
356
|
-
title: "导入数据",
|
|
357
|
-
templateType: TemplateTypeEnum.BASE,
|
|
358
|
-
uploadConfig: {
|
|
359
|
-
autoUpload: false,
|
|
360
|
-
customUpload: async (file, context, _onProgress) => {
|
|
361
|
-
// 检查当前文件列表
|
|
362
|
-
console.log("当前文件列表:", context.fileList);
|
|
363
|
-
|
|
364
|
-
// 如果文件数量超过限制,删除第一个文件
|
|
365
|
-
if (context.fileList.length > 5) {
|
|
366
|
-
context.removeFile(0);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// 简单上传,不处理进度
|
|
370
|
-
const formData = new FormData();
|
|
371
|
-
formData.append("file", file);
|
|
372
|
-
|
|
373
|
-
const response = await fetch("/api/upload", {
|
|
374
|
-
method: "POST",
|
|
375
|
-
body: formData,
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
return response.json();
|
|
379
|
-
},
|
|
338
|
+
onConfirm: async (data) => {
|
|
339
|
+
// 此时文件已上传完成,data.files 包含上传结果
|
|
340
|
+
console.log("上传结果:", data);
|
|
341
|
+
return { success: true };
|
|
380
342
|
},
|
|
381
343
|
});
|
|
382
344
|
```
|
|
383
345
|
|
|
384
|
-
###
|
|
346
|
+
### 多文件上传
|
|
385
347
|
|
|
386
348
|
```typescript
|
|
387
349
|
ImportDialog.open({
|
|
388
350
|
title: "导入数据",
|
|
389
351
|
templateType: TemplateTypeEnum.BASE,
|
|
390
352
|
uploadConfig: {
|
|
353
|
+
multiple: true,
|
|
391
354
|
autoUpload: false, // 默认值,点击确定时上传
|
|
392
355
|
confirmLoading: true, // 显示确定按钮 loading(默认)
|
|
393
356
|
customUpload: async (file, onProgress) => {
|
|
394
|
-
//
|
|
357
|
+
// 如果文件数量超过限制,删除第一个文件
|
|
358
|
+
if (context.fileList.length > 5) {
|
|
359
|
+
context.removeFile(0);
|
|
360
|
+
}
|
|
361
|
+
return { file };
|
|
395
362
|
},
|
|
396
363
|
},
|
|
397
364
|
onConfirm: async (data) => {
|
|
398
365
|
// 此时文件已上传完成,data.files 包含上传结果
|
|
399
|
-
console.log("上传结果:", data
|
|
366
|
+
console.log("上传结果:", data);
|
|
400
367
|
return { success: true };
|
|
401
368
|
},
|
|
402
369
|
});
|
|
@@ -429,7 +396,7 @@ ImportDialog.open({
|
|
|
429
396
|
title: "大文件上传",
|
|
430
397
|
templateType: TemplateTypeEnum.BASE,
|
|
431
398
|
uploadConfig: {
|
|
432
|
-
autoUpload:
|
|
399
|
+
autoUpload: false,
|
|
433
400
|
maxFileSize: 500 * 1024 * 1024, // 500MB
|
|
434
401
|
chunkedUpload: {
|
|
435
402
|
initUpload: async (params) => {
|
|
@@ -458,59 +425,6 @@ ImportDialog.open({
|
|
|
458
425
|
});
|
|
459
426
|
```
|
|
460
427
|
|
|
461
|
-
### 分片上传(延迟上传)
|
|
462
|
-
|
|
463
|
-
```typescript
|
|
464
|
-
ImportDialog.open({
|
|
465
|
-
title: "大文件上传",
|
|
466
|
-
templateType: TemplateTypeEnum.BASE,
|
|
467
|
-
uploadConfig: {
|
|
468
|
-
autoUpload: false, // 延迟上传
|
|
469
|
-
maxFileSize: 500 * 1024 * 1024,
|
|
470
|
-
chunkedUpload: {
|
|
471
|
-
// 分片上传配置同上
|
|
472
|
-
},
|
|
473
|
-
},
|
|
474
|
-
onConfirm: async (data) => {
|
|
475
|
-
// 点击确定时执行分片上传,data.files 包含合并后的结果
|
|
476
|
-
console.log("分片上传完成:", data.files);
|
|
477
|
-
return { success: true };
|
|
478
|
-
},
|
|
479
|
-
});
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
### 多文件上传
|
|
483
|
-
|
|
484
|
-
```typescript
|
|
485
|
-
ImportDialog.open({
|
|
486
|
-
title: "批量上传文件",
|
|
487
|
-
templateType: TemplateTypeEnum.BASE,
|
|
488
|
-
uploadConfig: {
|
|
489
|
-
multiple: true,
|
|
490
|
-
maxFiles: 20,
|
|
491
|
-
autoUpload: true,
|
|
492
|
-
customUpload: async (file, onProgress) => {
|
|
493
|
-
// 自定义上传逻辑
|
|
494
|
-
const formData = new FormData();
|
|
495
|
-
formData.append("file", file);
|
|
496
|
-
|
|
497
|
-
const xhr = new XMLHttpRequest();
|
|
498
|
-
xhr.upload.addEventListener("progress", (e) => {
|
|
499
|
-
if (e.lengthComputable) {
|
|
500
|
-
onProgress?.(Math.round((e.loaded / e.total) * 100));
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
xhr.open("POST", "/api/upload");
|
|
505
|
-
await xhr.send(formData);
|
|
506
|
-
},
|
|
507
|
-
},
|
|
508
|
-
onUploadProgress: (file, progress) => {
|
|
509
|
-
console.log(`${file.name}: ${progress}%`);
|
|
510
|
-
},
|
|
511
|
-
});
|
|
512
|
-
```
|
|
513
|
-
|
|
514
428
|
### 带品牌选择的导入
|
|
515
429
|
|
|
516
430
|
```typescript
|
package/index.d.ts
CHANGED
|
@@ -437,7 +437,17 @@ export declare interface UploadConfig {
|
|
|
437
437
|
multiple?: boolean;
|
|
438
438
|
/** 单文件最大大小(字节),默认 100MB */
|
|
439
439
|
maxFileSize?: number;
|
|
440
|
-
/**
|
|
440
|
+
/**
|
|
441
|
+
* 文件预处理函数
|
|
442
|
+
* 在选择文件后立即调用,用于:
|
|
443
|
+
* - 二次加工上传参数
|
|
444
|
+
* - 自定义校验逻辑
|
|
445
|
+
* - 预上传处理(如获取签名URL等)
|
|
446
|
+
*
|
|
447
|
+
* @param file 原始文件
|
|
448
|
+
* @param context 上下文信息
|
|
449
|
+
* @returns 返回值会存储在 fileItem.response 中,点击确定时可获取
|
|
450
|
+
*/
|
|
441
451
|
customUpload?: (file: File, context?: {
|
|
442
452
|
/** 当前文件列表 */
|
|
443
453
|
fileList: FileUploadItem[];
|
|
@@ -450,10 +460,9 @@ export declare interface UploadConfig {
|
|
|
450
460
|
*/
|
|
451
461
|
chunkedUpload?: ChunkedUploadConfig;
|
|
452
462
|
/**
|
|
453
|
-
*
|
|
454
|
-
* - true:
|
|
455
|
-
* - false:
|
|
456
|
-
* 适用于 customUpload 和 chunkedUpload
|
|
463
|
+
* 断点续传控制(仅分片上传时生效)
|
|
464
|
+
* - true: 启用断点续传,自动恢复未完成的上传
|
|
465
|
+
* - false: 不启用断点续传(默认)
|
|
457
466
|
*/
|
|
458
467
|
autoUpload?: boolean;
|
|
459
468
|
/**
|