@sl-material/sl-import 1.0.0-beta0 → 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 +77 -64
- package/index.d.ts +27 -6
- package/package.json +1 -1
- package/sl-import.cjs.js +1 -1
- package/sl-import.es.js +342 -212
- package/sl-import.umd.umd.js +33 -33
package/README.md
CHANGED
|
@@ -174,14 +174,15 @@ const handleImport = async () => {
|
|
|
174
174
|
|
|
175
175
|
所有上传相关配置统一放在 `uploadConfig` 对象中:
|
|
176
176
|
|
|
177
|
-
| 参数
|
|
178
|
-
|
|
|
179
|
-
| `autoUpload`
|
|
180
|
-
| `multiple`
|
|
181
|
-
| `maxFiles`
|
|
182
|
-
| `maxFileSize`
|
|
183
|
-
| `customUpload`
|
|
184
|
-
| `chunkedUpload`
|
|
177
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
178
|
+
| ---------------- | ----------------------------------------------- | ----------- | ----------------------- |
|
|
179
|
+
| `autoUpload` | `boolean` | `false` | 是否立即上传文件 |
|
|
180
|
+
| `multiple` | `boolean` | `false` | 是否支持多文件上传 |
|
|
181
|
+
| `maxFiles` | `number` | `10` | 最大文件数量 |
|
|
182
|
+
| `maxFileSize` | `number` | `104857600` | 单文件最大大小(100MB) |
|
|
183
|
+
| `customUpload` | `(file, context?, onProgress?) => Promise<any>` | - | 自定义上传函数 |
|
|
184
|
+
| `chunkedUpload` | `ChunkUploadStrategy` | - | 分片上传策略配置 |
|
|
185
|
+
| `confirmLoading` | `boolean` | `true` | 确定按钮 loading 控制 |
|
|
185
186
|
|
|
186
187
|
##### 分片上传策略 (ChunkUploadStrategy)
|
|
187
188
|
|
|
@@ -193,6 +194,19 @@ interface ChunkUploadStrategy {
|
|
|
193
194
|
}
|
|
194
195
|
```
|
|
195
196
|
|
|
197
|
+
##### 文件操作上下文
|
|
198
|
+
|
|
199
|
+
`customUpload` 函数的第三个参数,提供基本的文件操作能力:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
interface Context {
|
|
203
|
+
/** 当前文件列表 */
|
|
204
|
+
fileList: FileUploadItem[];
|
|
205
|
+
/** 删除指定索引的文件 */
|
|
206
|
+
removeFile: (index: number) => void;
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
196
210
|
#### 回调函数
|
|
197
211
|
|
|
198
212
|
| 参数 | 类型 | 说明 |
|
|
@@ -303,20 +317,72 @@ ImportDialog.open({
|
|
|
303
317
|
});
|
|
304
318
|
```
|
|
305
319
|
|
|
306
|
-
###
|
|
320
|
+
### 使用文件操作功能
|
|
307
321
|
|
|
308
322
|
```typescript
|
|
323
|
+
import { ImportDialog, TemplateTypeEnum } from "@sl-material/sl-import";
|
|
324
|
+
|
|
309
325
|
ImportDialog.open({
|
|
310
326
|
title: "导入数据",
|
|
311
327
|
templateType: TemplateTypeEnum.BASE,
|
|
312
328
|
uploadConfig: {
|
|
329
|
+
autoUpload: false,
|
|
330
|
+
customUpload: async (file, context) => {
|
|
331
|
+
// 如果文件数量超过限制,删除第一个文件
|
|
332
|
+
console.info("file", file, "context", context);
|
|
333
|
+
return {
|
|
334
|
+
file,
|
|
335
|
+
};
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
onConfirm: async (data) => {
|
|
339
|
+
// 此时文件已上传完成,data.files 包含上传结果
|
|
340
|
+
console.log("上传结果:", data);
|
|
341
|
+
return { success: true };
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### 多文件上传
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
ImportDialog.open({
|
|
350
|
+
title: "导入数据",
|
|
351
|
+
templateType: TemplateTypeEnum.BASE,
|
|
352
|
+
uploadConfig: {
|
|
353
|
+
multiple: true,
|
|
313
354
|
autoUpload: false, // 默认值,点击确定时上传
|
|
355
|
+
confirmLoading: true, // 显示确定按钮 loading(默认)
|
|
314
356
|
customUpload: async (file, onProgress) => {
|
|
315
|
-
//
|
|
357
|
+
// 如果文件数量超过限制,删除第一个文件
|
|
358
|
+
if (context.fileList.length > 5) {
|
|
359
|
+
context.removeFile(0);
|
|
360
|
+
}
|
|
361
|
+
return { file };
|
|
316
362
|
},
|
|
317
363
|
},
|
|
318
364
|
onConfirm: async (data) => {
|
|
319
365
|
// 此时文件已上传完成,data.files 包含上传结果
|
|
366
|
+
console.log("上传结果:", data);
|
|
367
|
+
return { success: true };
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### 禁用确定按钮 Loading
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
ImportDialog.open({
|
|
376
|
+
title: "导入数据",
|
|
377
|
+
templateType: TemplateTypeEnum.BASE,
|
|
378
|
+
uploadConfig: {
|
|
379
|
+
autoUpload: false,
|
|
380
|
+
confirmLoading: false, // 不显示确定按钮 loading
|
|
381
|
+
customUpload: async (file, onProgress) => {
|
|
382
|
+
// 上传逻辑
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
onConfirm: async (data) => {
|
|
320
386
|
console.log("上传结果:", data.files);
|
|
321
387
|
return { success: true };
|
|
322
388
|
},
|
|
@@ -330,7 +396,7 @@ ImportDialog.open({
|
|
|
330
396
|
title: "大文件上传",
|
|
331
397
|
templateType: TemplateTypeEnum.BASE,
|
|
332
398
|
uploadConfig: {
|
|
333
|
-
autoUpload:
|
|
399
|
+
autoUpload: false,
|
|
334
400
|
maxFileSize: 500 * 1024 * 1024, // 500MB
|
|
335
401
|
chunkedUpload: {
|
|
336
402
|
initUpload: async (params) => {
|
|
@@ -359,59 +425,6 @@ ImportDialog.open({
|
|
|
359
425
|
});
|
|
360
426
|
```
|
|
361
427
|
|
|
362
|
-
### 分片上传(延迟上传)
|
|
363
|
-
|
|
364
|
-
```typescript
|
|
365
|
-
ImportDialog.open({
|
|
366
|
-
title: "大文件上传",
|
|
367
|
-
templateType: TemplateTypeEnum.BASE,
|
|
368
|
-
uploadConfig: {
|
|
369
|
-
autoUpload: false, // 延迟上传
|
|
370
|
-
maxFileSize: 500 * 1024 * 1024,
|
|
371
|
-
chunkedUpload: {
|
|
372
|
-
// 分片上传配置同上
|
|
373
|
-
},
|
|
374
|
-
},
|
|
375
|
-
onConfirm: async (data) => {
|
|
376
|
-
// 点击确定时执行分片上传,data.files 包含合并后的结果
|
|
377
|
-
console.log("分片上传完成:", data.files);
|
|
378
|
-
return { success: true };
|
|
379
|
-
},
|
|
380
|
-
});
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
### 多文件上传
|
|
384
|
-
|
|
385
|
-
```typescript
|
|
386
|
-
ImportDialog.open({
|
|
387
|
-
title: "批量上传文件",
|
|
388
|
-
templateType: TemplateTypeEnum.BASE,
|
|
389
|
-
uploadConfig: {
|
|
390
|
-
multiple: true,
|
|
391
|
-
maxFiles: 20,
|
|
392
|
-
autoUpload: true,
|
|
393
|
-
customUpload: async (file, onProgress) => {
|
|
394
|
-
// 自定义上传逻辑
|
|
395
|
-
const formData = new FormData();
|
|
396
|
-
formData.append("file", file);
|
|
397
|
-
|
|
398
|
-
const xhr = new XMLHttpRequest();
|
|
399
|
-
xhr.upload.addEventListener("progress", (e) => {
|
|
400
|
-
if (e.lengthComputable) {
|
|
401
|
-
onProgress?.(Math.round((e.loaded / e.total) * 100));
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
xhr.open("POST", "/api/upload");
|
|
406
|
-
await xhr.send(formData);
|
|
407
|
-
},
|
|
408
|
-
},
|
|
409
|
-
onUploadProgress: (file, progress) => {
|
|
410
|
-
console.log(`${file.name}: ${progress}%`);
|
|
411
|
-
},
|
|
412
|
-
});
|
|
413
|
-
```
|
|
414
|
-
|
|
415
428
|
### 带品牌选择的导入
|
|
416
429
|
|
|
417
430
|
```typescript
|
package/index.d.ts
CHANGED
|
@@ -437,20 +437,41 @@ export declare interface UploadConfig {
|
|
|
437
437
|
multiple?: boolean;
|
|
438
438
|
/** 单文件最大大小(字节),默认 100MB */
|
|
439
439
|
maxFileSize?: number;
|
|
440
|
-
/**
|
|
441
|
-
|
|
440
|
+
/**
|
|
441
|
+
* 文件预处理函数
|
|
442
|
+
* 在选择文件后立即调用,用于:
|
|
443
|
+
* - 二次加工上传参数
|
|
444
|
+
* - 自定义校验逻辑
|
|
445
|
+
* - 预上传处理(如获取签名URL等)
|
|
446
|
+
*
|
|
447
|
+
* @param file 原始文件
|
|
448
|
+
* @param context 上下文信息
|
|
449
|
+
* @returns 返回值会存储在 fileItem.response 中,点击确定时可获取
|
|
450
|
+
*/
|
|
451
|
+
customUpload?: (file: File, context?: {
|
|
452
|
+
/** 当前文件列表 */
|
|
453
|
+
fileList: FileUploadItem[];
|
|
454
|
+
/** 删除指定索引的文件 */
|
|
455
|
+
removeFile: (index: number) => void;
|
|
456
|
+
}, onProgress?: (progress: number) => void) => Promise<any>;
|
|
442
457
|
/**
|
|
443
458
|
* 分片上传配置
|
|
444
459
|
* 配置此项后自动启用分片上传(仅单文件模式生效)
|
|
445
460
|
*/
|
|
446
461
|
chunkedUpload?: ChunkedUploadConfig;
|
|
447
462
|
/**
|
|
448
|
-
*
|
|
449
|
-
* - true:
|
|
450
|
-
* - false:
|
|
451
|
-
* 适用于 customUpload 和 chunkedUpload
|
|
463
|
+
* 断点续传控制(仅分片上传时生效)
|
|
464
|
+
* - true: 启用断点续传,自动恢复未完成的上传
|
|
465
|
+
* - false: 不启用断点续传(默认)
|
|
452
466
|
*/
|
|
453
467
|
autoUpload?: boolean;
|
|
468
|
+
/**
|
|
469
|
+
* 确定按钮 loading 控制
|
|
470
|
+
* - true: 点击确定时显示 loading 状态(默认)
|
|
471
|
+
* - false: 点击确定时不显示 loading 状态
|
|
472
|
+
* 主要用于延迟上传场景,控制上传过程中的 UI 反馈
|
|
473
|
+
*/
|
|
474
|
+
confirmLoading?: boolean;
|
|
454
475
|
}
|
|
455
476
|
|
|
456
477
|
export { }
|