@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 CHANGED
@@ -5,15 +5,17 @@
5
5
  ## 特性
6
6
 
7
7
  - **多种模板类型** - 内置 5 种预设模板,支持自定义配置
8
- - **文件分片上传** - 支持大文件分片上传,自动合并
8
+ - **文件分片上传** - 支持大文件分片上传,自动合并,支持延迟上传
9
9
  - **多文件上传** - 支持批量文件上传,横向滚动列表展示
10
10
  - **上传时机控制** - 支持立即上传和延迟上传两种模式
11
+ - **灵活文件校验** - 可选的文件数量和大小校验,不传则不校验
11
12
  - **品牌选择** - 支持静态数据或异步加载品牌列表
12
13
  - **图片比例选择** - 支持配置图片裁剪比例选项
13
14
  - **日期范围选择** - 支持月份和日期范围选择
15
+ - **统一 Loading 样式** - 文件卡片和全局遮罩使用相同的渐变圆环动画
14
16
  - **纯原生实现** - 不依赖 Vue/React 等框架,可在任何环境使用
15
17
  - **TypeScript 支持** - 完整的类型定义
16
- - **国际化支持** - 内置多语言支持
18
+ - **标准化国际化** - 支持 zh_CN、en_US、ja_JP、zh_HK、zh_TW、id 等语言
17
19
 
18
20
  ## 安装
19
21
 
@@ -108,22 +110,69 @@ ImportDialog.open({
108
110
 
109
111
  ```typescript
110
112
  ImportDialog.open({
111
- title: "导入数据",
113
+ locale: "zh_CN" as I18nLocaleEnum,
114
+ type: ExportTypeEnum.excel,
112
115
  templateType: TemplateTypeEnum.BASE,
116
+ templateUrl: "/template/base_template.xlsx",
117
+ tips: ["提示信息 1", "提示信息 2"],
118
+ onConfirm: async (data) => {
119
+ return submitImportMock(data);
120
+ // 可以在这里进行额外的后处理
121
+ },
113
122
  uploadConfig: {
114
123
  multiple: true,
115
- autoUpload: false, // 默认值,点击确定时上传
116
- confirmLoading: true, // 显示确定按钮 loading(默认)
117
- customUpload: async (file, onProgress) => {
118
- // 如果文件数量超过限制,删除第一个文件
119
- if (context.fileList.length > 5) {
120
- context.removeFile(0);
124
+ confirmLoading: false,
125
+ maxFileSize: 1000,
126
+ // maxFiles: 2,
127
+ maxFileSizeUnit: "KB",
128
+ // 文件预处理函数:选择文件后立即调用
129
+ customUpload: async (file: File, context) => {
130
+ if (file.name.includes(",")) {
131
+ context?.removeFile(
132
+ context?.fileList.findIndex((f) => f.name === file.name),
133
+ );
121
134
  }
135
+ // 返回值会存储在 fileItem.response 中
136
+ return { file };
137
+ },
138
+ },
139
+ });
140
+ ```
141
+
142
+ ### 文件校验配置
143
+
144
+ ```typescript
145
+ ImportDialog.open({
146
+ title: "导入数据",
147
+ templateType: TemplateTypeEnum.BASE,
148
+ uploadConfig: {
149
+ multiple: true,
150
+ // 不配置 maxFiles 和 maxFileSize,则不进行任何校验
151
+ customUpload: async (file, context, onProgress) => {
152
+ return { file };
153
+ },
154
+ },
155
+ onConfirm: async (data) => {
156
+ console.log("上传结果:", data);
157
+ return { success: true };
158
+ },
159
+ });
160
+ ```
161
+
162
+ ```typescript
163
+ ImportDialog.open({
164
+ title: "导入数据",
165
+ templateType: TemplateTypeEnum.BASE,
166
+ uploadConfig: {
167
+ multiple: true,
168
+ maxFiles: 10, // 限制最多 10 个文件
169
+ maxFileSize: 50, // 限制单个文件最大 50MB
170
+ maxFileSizeUnit: "MB",
171
+ customUpload: async (file, context, onProgress) => {
122
172
  return { file };
123
173
  },
124
174
  },
125
175
  onConfirm: async (data) => {
126
- // 此时文件已上传完成,data.files 包含上传结果
127
176
  console.log("上传结果:", data);
128
177
  return { success: true };
129
178
  },
@@ -150,25 +199,26 @@ ImportDialog.open({
150
199
  });
151
200
  ```
152
201
 
153
- ### 分片上传(立即上传)
202
+ ### 分片上传(立即上传) 注意分片上传目前只支持单个文件上传
154
203
 
155
204
  ```typescript
156
205
  ImportDialog.open({
157
206
  title: "大文件上传",
158
207
  templateType: TemplateTypeEnum.BASE,
159
208
  uploadConfig: {
160
- autoUpload: false,
161
- maxFileSize: 500 * 1024 * 1024, // 500MB
209
+ autoUpload: true, // 选择文件后立即开始上传
210
+ maxFileSize: 500, // 可选:限制文件大小为 500MB
211
+ maxFileSizeUnit: "MB",
162
212
  chunkedUpload: {
163
- initUpload: async (params) => {
213
+ initUpload: async (fileName, fileSize) => {
164
214
  const response = await fetch("/api/upload/init", {
165
215
  method: "POST",
166
216
  headers: { "Content-Type": "application/json" },
167
- body: JSON.stringify(params),
217
+ body: JSON.stringify({ fileName, fileSize }),
168
218
  });
169
219
  return response.json();
170
220
  },
171
- getResumableOptions: (initResult) => ({
221
+ getResumableConfig: (initResult) => ({
172
222
  target: "/api/upload/chunk",
173
223
  headers: {
174
224
  Authorization: `Bearer ${token}`,
@@ -186,6 +236,58 @@ ImportDialog.open({
186
236
  });
187
237
  ```
188
238
 
239
+ ### 分片上传 点击确定上传
240
+
241
+ ````typescript
242
+ ImportDialog.open({
243
+ type: ExportTypeEnum.excel,
244
+ title: "分片上传(延迟)",
245
+ templateType: TemplateTypeEnum.BASE,
246
+ tabs: [{ label: "分片延迟上传", key: "chunked-delayed" }],
247
+ tips: [
248
+ "1. 选择文件后不会立即上传",
249
+ "2. 点击确定按钮时才开始分片上传",
250
+ "3. autoUpload: false(默认值)",
251
+ ],
252
+ uploadTitle: "选择大文件",
253
+ uploadHint: "选择文件后点击确定开始分片上传",
254
+ acceptTypes: ".xlsx,.xls,.csv,.zip",
255
+ uploadConfig: {
256
+ maxFileSize: 500,
257
+ maxFileSizeUnit: "MB",
258
+ autoUpload: false, // 选择文件后不立即上传,等待点击确定
259
+ chunkedUpload: {
260
+ initUpload: async (fileName: string, fileSize: number) => {
261
+ const response = await initImportTask({ fileName, fileSize });
262
+ console.info("initResult>>>", response);
263
+ return {
264
+ uploadSessionId: response?.uploadSessionId,
265
+ partSize: response?.partSize,
266
+ totalParts: response?.totalParts,
267
+ };
268
+ },
269
+ getResumableConfig: (initResult) => ({
270
+ target: `/newProxy/basic-data-io/api/file/upload/part?uploadSessionId=${initResult.uploadSessionId}`,
271
+ headers: {
272
+ "TCSL-BP-TOKEN":
273
+ window.sessionStorage.getItem("token") || slyToken,
274
+ },
275
+ // query: { uploadSessionId: initResult.uploadSessionId },
276
+ }),
277
+ mergeChunks: async (uploadSessionId: string) => {
278
+ const response = await uploadFileMerge(uploadSessionId);
279
+
280
+ return response;
281
+ },
282
+ },
283
+ },
284
+ onConfirm: async (data) => {
285
+ console.info("openChunkedUploadDelayed>>>", data);
286
+ return { success: true, message: "导入成功" };
287
+ },
288
+ });
289
+ ```
290
+
189
291
  ### 带品牌选择的导入
190
292
 
191
293
  ```typescript
@@ -213,7 +315,7 @@ ImportDialog.open({
213
315
  return { success: true };
214
316
  },
215
317
  });
216
- ```
318
+ ````
217
319
 
218
320
  ### 自定义日期范围
219
321
 
@@ -296,15 +398,28 @@ ImportDialog.open({
296
398
 
297
399
  所有上传相关配置统一放在 `uploadConfig` 对象中:
298
400
 
299
- | 参数 | 类型 | 默认值 | 说明 |
300
- | ---------------- | ----------------------------------------------- | ----------- | ----------------------- |
301
- | `autoUpload` | `boolean` | `false` | 是否立即上传文件 |
302
- | `multiple` | `boolean` | `false` | 是否支持多文件上传 |
303
- | `maxFiles` | `number` | `10` | 最大文件数量 |
304
- | `maxFileSize` | `number` | `104857600` | 单文件最大大小(100MB) |
305
- | `customUpload` | `(file, context?, onProgress?) => Promise<any>` | - | 自定义上传函数 |
306
- | `chunkedUpload` | `ChunkUploadStrategy` | - | 分片上传策略配置 |
307
- | `confirmLoading` | `boolean` | `true` | 确定按钮 loading 控制 |
401
+ | 参数 | 类型 | 默认值 | 说明 |
402
+ | ----------------- | ----------------------------------------------- | ------- | ---------------------------- |
403
+ | `autoUpload` | `boolean` | `false` | 是否立即上传文件 |
404
+ | `multiple` | `boolean` | `false` | 是否支持多文件上传 |
405
+ | `maxFiles` | `number` | - | 最大文件数量,不传则不校验 |
406
+ | `maxFileSize` | `number` | - | 单文件最大大小,不传则不校验 |
407
+ | `maxFileSizeUnit` | `'KB' \| 'MB' \| 'GB'` | `'MB'` | 文件大小单位 |
408
+ | `customUpload` | `(file, context?, onProgress?) => Promise<any>` | - | 自定义上传函数 |
409
+ | `chunkedUpload` | `ChunkUploadStrategy` | - | 分片上传策略配置 |
410
+ | `confirmLoading` | `boolean` | `true` | 确定按钮 loading 控制 |
411
+ | `onFileChange` | `(files: FileUploadItem[]) => void` | - | 文件列表变化回调 |
412
+ | `onProgress` | `(file, progress) => void` | - | 上传进度回调 |
413
+ | `onSuccess` | `(file, response) => void` | - | 上传成功回调 |
414
+ | `onError` | `(file, error) => void` | - | 上传失败回调 |
415
+
416
+ **文件校验配置说明**:
417
+
418
+ - `maxFiles`:限制最大文件数量,不传递则不进行数量校验
419
+ - `maxFileSize` 和 `maxFileSizeUnit` 组合使用来限制文件大小,不传递则不进行大小校验
420
+ - 例如:`maxFileSize: 10, maxFileSizeUnit: 'KB'` 表示最大 10KB
421
+ - 例如:`maxFileSize: 500, maxFileSizeUnit: 'MB'` 表示最大 500MB
422
+ - 校验参数完全可选,可根据需要灵活配置
308
423
 
309
424
  ##### 分片上传策略 (ChunkUploadStrategy)
310
425
 
@@ -356,13 +471,30 @@ interface Context {
356
471
 
357
472
  ### 国际化 (I18nLocaleEnum)
358
473
 
359
- | 语言 | 枚举值 |
360
- | -------- | ------- |
361
- | 简体中文 | `ZH_CN` |
362
- | 繁体中文 | `ZH_TW` |
363
- | 英语 | `EN_US` |
364
- | 日语 | `JA` |
365
- | 印尼语 | `ID` |
474
+ | 语言 | 枚举值 |
475
+ | ---------------- | ------- |
476
+ | 简体中文 | `zh_CN` |
477
+ | 繁體中文(香港) | `zh_HK` |
478
+ | 繁體中文(臺灣) | `zh_TW` |
479
+ | 英语(美国) | `en_US` |
480
+ | 日本语 | `ja_JP` |
481
+ | 印尼语 | `id` |
482
+
483
+ **使用方式**:
484
+
485
+ ```typescript
486
+ import { ImportDialog, I18nLocaleEnum } from "@sl-material/sl-import";
487
+
488
+ ImportDialog.open({
489
+ locale: I18nLocaleEnum.ZH_CN, // 简体中文
490
+ // locale: I18nLocaleEnum.ZH_HK, // 繁體中文(香港)
491
+ // locale: I18nLocaleEnum.ZH_TW, // 繁體中文(臺灣)
492
+ // locale: I18nLocaleEnum.EN_US, // 英语(美国)
493
+ // locale: I18nLocaleEnum.JA_JP, // 日本语
494
+ // locale: I18nLocaleEnum.ID, // 印尼语
495
+ // ... 其他配置
496
+ });
497
+ ```
366
498
 
367
499
  ### 类型定义
368
500
 
@@ -409,6 +541,53 @@ interface FileUploadItem {
409
541
  }
410
542
  ```
411
543
 
544
+ ## 最新特性
545
+
546
+ ### 🎯 灵活的文件校验
547
+
548
+ 文件校验参数完全可选,可根据需要灵活配置:
549
+
550
+ ```typescript
551
+ // 不进行任何校验
552
+ uploadConfig: {
553
+ multiple: true,
554
+ customUpload: myUploadFunction
555
+ }
556
+
557
+ // 完整校验配置
558
+ uploadConfig: {
559
+ multiple: true,
560
+ maxFiles: 10, // 限制最多 10 个文件
561
+ maxFileSize: 50, // 限制单个文件最大 50MB
562
+ maxFileSizeUnit: "MB",
563
+ customUpload: myUploadFunction
564
+ }
565
+ ```
566
+
567
+ ### 🌍 标准化国际化
568
+
569
+ 支持 6 种语言,使用标准的语言代码格式:
570
+
571
+ - `zh_CN` - 简体中文
572
+ - `zh_HK` - 繁體中文(香港)
573
+ - `zh_TW` - 繁體中文(臺灣)
574
+ - `en_US` - 英语(美国)
575
+ - `ja_JP` - 日本语
576
+ - `id` - 印尼语
577
+
578
+ ### ⚡ 统一 Loading 动画
579
+
580
+ 文件卡片和全局遮罩使用相同的渐变圆环动画,视觉效果统一且流畅。
581
+
582
+ ### 🔄 分片上传延迟模式
583
+
584
+ 支持分片上传的延迟模式,文件选择后不会立即上传,用户可以:
585
+
586
+ 1. 选择多个文件
587
+ 2. 预览文件列表
588
+ 3. 手动触发上传或删除文件
589
+ 4. 点击确认按钮开始上传
590
+
412
591
  ## UMD 使用方式
413
592
 
414
593
  ```html
@@ -425,6 +604,30 @@ interface FileUploadItem {
425
604
 
426
605
  > **注意**:UMD 版本同样已内联 CSS,无需额外引入样式文件。
427
606
 
607
+ ## 更新日志
608
+
609
+ ### v1.1.0-beta4
610
+
611
+ #### 🚀 新增特性
612
+
613
+ - **灵活文件校验**:`maxFiles` 和 `maxFileSize` 参数改为可选,不传则不校验
614
+ - **标准化国际化**:统一语言代码格式为 `zh_CN`、`en_US`、`ja_JP` 等
615
+ - **新增语言支持**:添加 `zh_HK`(繁體中文-香港)支持
616
+ - **统一 Loading 样式**:文件卡片和全局遮罩使用相同的渐变圆环动画
617
+ - **分片上传延迟模式**:支持文件选择后延迟上传,用户可手动控制上传时机
618
+
619
+ #### 🐛 修复问题
620
+
621
+ - 修复 loading 动画跳动问题
622
+ - 修复分片上传延迟模式下的配置问题
623
+ - 优化文件校验逻辑的时机和顺序
624
+
625
+ #### 💎 优化改进
626
+
627
+ - 所有硬编码中文提示改为国际化调用
628
+ - 优化文件大小单位配置,支持 KB、MB、GB
629
+ - 改进错误提示信息的准确性和友好性
630
+
428
631
  ## License
429
632
 
430
633
  MIT
package/index.d.ts CHANGED
@@ -60,6 +60,8 @@ export declare enum ExportTypeEnum {
60
60
  excel = "excel"
61
61
  }
62
62
 
63
+ declare type FileSizeUnit = "KB" | "MB" | "GB";
64
+
63
65
  export declare interface FileUploadItem {
64
66
  id: string;
65
67
  file: File;
@@ -89,11 +91,12 @@ export declare type I18nLocale = I18nLocaleEnum;
89
91
  * 支持的语言枚举
90
92
  */
91
93
  export declare enum I18nLocaleEnum {
92
- ZH_CN = "zh-CN",// 中文(简体)
93
- ZH_TW = "zh-TW",// 中文(繁体)
94
- JA = "ja",// 日语
95
- ID = "id",// 印尼语
96
- EN_US = "en-US"
94
+ ZH_CN = "zh_CN",// 简体中文
95
+ EN_US = "en_US",// 英语(美国)
96
+ JA_JP = "ja_JP",// 日语(日本)
97
+ ZH_HK = "zh_HK",// 繁體中文(香港)
98
+ ZH_TW = "zh_TW",// 繁體中文(臺灣)
99
+ ID = "id"
97
100
  }
98
101
 
99
102
  export declare interface ImageRatioOption {
@@ -282,11 +285,23 @@ export declare interface LocaleMessages {
282
285
  startDate: string;
283
286
  endDate: string;
284
287
  to: string;
288
+ pleaseSelectFile: string;
289
+ maxFilesLimit: string;
290
+ fileFormatNotSupported: string;
291
+ fileSizeExceeded: string;
285
292
  fileTypeError: string;
286
293
  fileSizeError: string;
287
294
  uploadFailed: string;
295
+ uploadFailedRetry: string;
288
296
  uploadSuccess: string;
289
297
  uploading: string;
298
+ processingFailed: string;
299
+ fileUploadingCannotDelete: string;
300
+ filesUploadingCannotClear: string;
301
+ filesUploading: string;
302
+ filesUploadFailed: string;
303
+ waitForUploadComplete: string;
304
+ chunkedUploadConfigRequired: string;
290
305
  uploadTitleBase: string;
291
306
  uploadTitleTemplate1: string;
292
307
  uploadTitleTemplate2: string;
@@ -414,6 +429,7 @@ declare namespace types {
414
429
  ImageRatioOption,
415
430
  ImportFormData,
416
431
  FileUploadStatus,
432
+ FileSizeUnit,
417
433
  FileUploadItem,
418
434
  ChunkUploadInitResult,
419
435
  ResumableConfig,
@@ -431,12 +447,14 @@ declare namespace types {
431
447
  export { types }
432
448
 
433
449
  export declare interface UploadConfig {
434
- /** 最大文件数量,默认 10 */
450
+ /** 最大文件数量,不传则不校验 */
435
451
  maxFiles?: number;
436
452
  /** 是否支持多文件上传,默认 false */
437
453
  multiple?: boolean;
438
- /** 单文件最大大小(字节),默认 100MB */
454
+ /** 单文件最大大小,不传则不校验 */
439
455
  maxFileSize?: number;
456
+ /** 文件大小单位,默认 'MB' */
457
+ maxFileSizeUnit?: FileSizeUnit;
440
458
  /**
441
459
  * 文件预处理函数
442
460
  * 在选择文件后立即调用,用于:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sl-material/sl-import",
3
- "version": "1.1.0-beta3",
3
+ "version": "1.1.0-beta5",
4
4
  "description": "导入组件 - 支持批量导入文件,提供多种模板配置",
5
5
  "main": "./sl-import.cjs.js",
6
6
  "module": "./sl-import.es.js",