antd-import-export 1.0.5 → 1.0.6

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
@@ -15,19 +15,6 @@
15
15
 
16
16
  [在线演示](https://demo.29dev.cn/antd-import-export/)
17
17
 
18
-
19
- ## 从 1.0.4 升级
20
-
21
- 1.0.5 重命名了两个组件、移除了批量导出组件:
22
-
23
- | 1.0.4 及以前 | 1.0.5 |
24
- | --- | --- |
25
- | `ExcelImportButton` | `ImportButton` |
26
- | `ExcelExportButton` | `ExportButton` |
27
- | `BatchExportButton` | 改用 `exportRows()`,按钮自己渲染(见[组件](#组件)) |
28
-
29
- 项目仍在开发阶段,这类调整不单独发大版本。
30
-
31
18
  ## 依赖要求
32
19
 
33
20
  | 依赖 | 版本 |
@@ -37,20 +24,6 @@
37
24
  | antd | >=6.0.0 |
38
25
  | @ant-design/icons | >=5.0.0 |
39
26
 
40
- ## 大文件表现
41
-
42
- Excel 的解析和生成在主线程执行——这是 ExcelJS 自身的用法,官方没有提供 Worker 方案。代价是处理大文件时页面会短暂无响应:
43
-
44
- | 行数 | 导入解析 | 导出生成 |
45
- | --- | --- | --- |
46
- | 1,000 | 约 25ms | 约 60ms |
47
- | 5,000 | 约 125ms | 约 300ms |
48
- | 20,000 | 约 500ms | 约 1 秒 |
49
-
50
- 单次上限 2 万行,超出会在前端直接拦截。生成文件期间取消按钮会禁用,因为主线程被占满时点击不会即时生效,避免让用户误以为没响应。
51
-
52
- 绝大多数实际文件在几千行以内,感知不到停顿。
53
-
54
27
  ## 字段定义
55
28
 
56
29
  导入导出的一切都由 `FieldSchema[]` 驱动:导出用它生成表头,导入模板用它写填写要求,解析时用它逐格校验。
@@ -81,10 +54,10 @@ const fieldSchemas: FieldSchema[] = [
81
54
  | `boolean` | required / true_label / false_label / default_value | 单元格填文案,接口值转成布尔 |
82
55
  | `date` | required / default_value | 严格 `YYYY-MM-DD` |
83
56
  | `time` | required / default_value | 严格 `HH:mm`,输出补零 |
84
- | `datetime` | required / default_value | 严格 `YYYY-MM-DD HH:mm` |
85
- | `list` | required / list_max_length / text_max_length / item_key? / default_value | 逗号分号均可,导出统一用英文分号 |
57
+ | `datetime` | required / default_value | 严格 `YYYY-MM-DD HH:mm` 或 `YYYY-MM-DD HH:mm:ss`,秒为 0 时不带秒 |
58
+ | `list` | required / list_max_length / text_max_length / item_key? / default_value | 中英文分号分隔,导出统一用英文分号 |
86
59
  | `single_choice` | required / option_map / default_value | 单元格填文案,接口值取 option_map 里的值 |
87
- | `multiple_choice` | required / option_map / default_value | 多值用中英文分号分隔 |
60
+ | `multiple_choice` | required / option_map / default_value | 中英文分号分隔,导出统一用英文分号 |
88
61
 
89
62
  `importable: false` 的列只出现在导出文件里,不参与导入模板和解析。
90
63
 
@@ -106,34 +79,36 @@ const result = validateField("19.99", {
106
79
  ## 组件
107
80
 
108
81
  ```tsx
109
- import { ImportButton, ExportButton, exportRows } from "antd-import-export";
82
+ import { ImportButton, ExportButton, exportRowsToFile } from "antd-import-export";
110
83
 
111
84
  // 导入: 内置模板下载、文件解析、预览编辑、分批提交、行级错误回填
112
85
  <ImportButton
113
86
  title="供应商"
114
87
  fieldSchemas={dataSchema}
115
- importRows={(payloads, signal) => supplierImportData(payloads, signal)}
116
- onImported={onRefresh}
88
+ importRows={(rows, signal) => supplierImportData(rows, signal)}
89
+ afterImport={onRefresh}
117
90
  />;
118
91
 
119
92
  // 按当前筛选条件导出, 内部用游标分批拉取
120
93
  <ExportButton
121
94
  title="供应商"
122
95
  fieldSchemas={dataSchema}
123
- filters={queryForm}
124
96
  totalCount={dataCount}
125
- fetchPage={(params, signal) => supplierExportData(params, signal)}
97
+ // 筛选条件在自己的 exportRows 里合并, 分页参数由包传入
98
+ exportRows={(params, signal) => supplierExportData({ ...queryForm, ...params }, signal)}
126
99
  />;
127
100
  ```
128
101
 
129
- 两个组件都不发请求,只调用你传进来的 `importRows` / `fetchPage`。
102
+ 两个组件都不发请求,只调用你传进来的 `importRows` / `exportRows`。
103
+
104
+ 退出登录或切换账号时调用 `resetTasks()`,会中止所有在途的导入导出并清空任务。
130
105
 
131
106
  导出已勾选的行这类「数据已经在内存里」的场景,包内只提供函数,按钮由你自己渲染:
132
107
 
133
108
  ```tsx
134
- import { exportRows } from "antd-import-export";
109
+ import { exportRowsToFile } from "antd-import-export";
135
110
 
136
- await exportRows({ title: "供应商", fieldSchemas: dataSchema, rows: selectedRows });
111
+ await exportRowsToFile({ title: "供应商", fieldSchemas: dataSchema, rows: selectedRows });
137
112
  ```
138
113
 
139
114
  ### ImportButton
@@ -142,8 +117,10 @@ await exportRows({ title: "供应商", fieldSchemas: dataSchema, rows: selectedR
142
117
  | --- | --- | --- |
143
118
  | `title` | `string` | 按钮、模板文件名、任务标题共用 |
144
119
  | `fieldSchemas` | `FieldSchema[]` | 字段定义 |
120
+ | `maxRows` | `number` | 单次导入上限,默认 2 万行;超出直接拦在提交前 |
145
121
  | `importRows` | `(rows, signal) => Promise<Record<string, unknown>[]>` | 一批行提交,返回等长结果;**空对象表示成功** |
146
- | `onImported` | `() => void` | 任务结束后回调,通常用来刷新列表 |
122
+ | `beforeImport` | `() => void \| Promise<void>` | 提交前触发,可做二次确认或自定义校验;抛错即中止 |
123
+ | `afterImport` | `() => void` | 任务结束(成功/失败/取消)时触发一次,通常用来刷新列表 |
147
124
 
148
125
  ### ExportButton
149
126
 
@@ -151,34 +128,23 @@ await exportRows({ title: "供应商", fieldSchemas: dataSchema, rows: selectedR
151
128
  | --- | --- | --- |
152
129
  | `title` | `string` | 文件名与任务标题 |
153
130
  | `fieldSchemas` | `FieldSchema[]` | 字段定义 |
154
- | `filters` | `Record<string, unknown>` | 并入每批请求参数 |
155
- | `totalCount` | `number` | 用于条数上限校验与进度总数 |
156
- | `fetchPage` | `(params, signal) => Promise<{ count, results }>` | 游标分页;**每行必须带数字 `id`** |
157
- | `buttonText` | `string` | 默认「导出」 |
131
+ | `totalCount` | `number` | 列表当前条数,只用于判断有没有数据;上限以接口返回的总数为准 |
132
+ | `maxRows` | `number` | 单次导出上限,默认 2 万行;每页返回后都会校验 |
133
+ | `exportRows` | `(params, signal) => Promise<{ count, results }>` | 游标分页;**每行必须带数字 `id`** |
134
+ | `beforeExport` | `() => void \| Promise<void>` | 创建任务前触发,可做二次确认或自定义校验;抛错即中止 |
135
+ | `afterExport` | `() => void` | 任务结束(成功/失败/取消)时触发一次 |
158
136
 
159
- ### exportRows
137
+ ### exportRowsToFile
160
138
 
161
139
  | 参数 | 类型 | 说明 |
162
140
  | --- | --- | --- |
163
141
  | `title` | `string` | 用于生成 `标题_时间戳.xlsx` |
164
142
  | `fieldSchemas` | `FieldSchema[]` | 字段定义 |
165
143
  | `rows` | `object[]` | 已在内存中的行 |
144
+ | `maxRows` | `number` | 单次导出上限,默认 2 万行 |
166
145
 
167
146
  返回 `Promise<Blob>`。空数组或超过 2 万行时**抛出可直接展示的错误**;不弹提示、不管理 loading,由调用方决定交互。
168
147
 
169
- ### 自定义触发器
170
-
171
- 想用自己的按钮、但要复用任务引擎和进度弹窗,可以直接组合:
172
-
173
- ```tsx
174
- const [taskId, setTaskId] = useState<string>();
175
-
176
- <button onClick={() => setTaskId(enqueueExport({ title, fileName, fieldSchemas, fetchPage }))}>导出</button>;
177
- {
178
- taskId ? <ExportTaskModal taskId={taskId} onClose={() => setTaskId(undefined)} /> : null;
179
- }
180
- ```
181
-
182
148
  ### 导入接口需要幂等
183
149
 
184
150
  一批请求失败时,前端无法确定服务端是否已经写入。任务会把这些行标成「结果未知,重试可能重复」,用户继续任务时会重新提交这一批数据。
@@ -203,7 +169,7 @@ const [taskId, setTaskId] = useState<string>();
203
169
 
204
170
  ## Excel 读写
205
171
 
206
- ExcelJS 只在 Worker 里加载,主线程不承担解析和生成。组件接入后这一步由组件内部完成,也可以直接用:
172
+ ExcelJS 按需加载(首次导入/导出时才引入),解析和生成在主线程执行。组件接入后这一步由组件内部完成,也可以直接用:
207
173
 
208
174
  ```ts
209
175
  import { parseImportFile, buildExportBlob, downloadImportTemplate } from "antd-import-export";
package/README_EN.md CHANGED
@@ -14,19 +14,6 @@
14
14
 
15
15
  [Live demo](https://demo.29dev.cn/antd-import-export/)
16
16
 
17
-
18
- ## Upgrading from 1.0.4
19
-
20
- 1.0.5 renames two components and removes the batch export component:
21
-
22
- | 1.0.4 and earlier | 1.0.5 |
23
- | --- | --- |
24
- | `ExcelImportButton` | `ImportButton` |
25
- | `ExcelExportButton` | `ExportButton` |
26
- | `BatchExportButton` | use `exportRows()` and render your own button (see [Components](#components)) |
27
-
28
- The project is still under development; changes like this do not get their own major version yet.
29
-
30
17
  ## Requirements
31
18
 
32
19
  | Package | Version |
@@ -36,20 +23,6 @@ The project is still under development; changes like this do not get their own m
36
23
  | antd | >=6.0.0 |
37
24
  | @ant-design/icons | >=5.0.0 |
38
25
 
39
- ## Large files
40
-
41
- Parsing and generating happen on the main thread — that is how ExcelJS works, it ships no worker mode. Very large files block the UI briefly:
42
-
43
- | Rows | Import parse | Export build |
44
- | --- | --- | --- |
45
- | 1,000 | ~25ms | ~60ms |
46
- | 5,000 | ~125ms | ~300ms |
47
- | 20,000 | ~500ms | ~1s |
48
-
49
- The hard limit is 20,000 rows per operation. The cancel button is disabled while the file is being generated, because clicks cannot take effect while the main thread is busy.
50
-
51
- Most real-world files stay in the low thousands of rows and show no noticeable pause.
52
-
53
26
  ## Field schema
54
27
 
55
28
  Everything is driven by `FieldSchema[]`: export headers, template hints and cell-level validation.
@@ -74,10 +47,10 @@ const fieldSchemas: FieldSchema[] = [
74
47
  | `boolean` | required / true_label / false_label / default_value | labels in the cell, boolean on the wire |
75
48
  | `date` | required / default_value | strict `YYYY-MM-DD` |
76
49
  | `time` | required / default_value | strict `HH:mm` |
77
- | `datetime` | required / default_value | strict `YYYY-MM-DD HH:mm` |
78
- | `list` | required / list_max_length / text_max_length / item_key? / default_value | comma or semicolon separated on import |
50
+ | `datetime` | required / default_value | strict `YYYY-MM-DD HH:mm` or `YYYY-MM-DD HH:mm:ss`; seconds are dropped when zero |
51
+ | `list` | required / list_max_length / text_max_length / item_key? / default_value | Chinese or English semicolons; exports always use `;` |
79
52
  | `single_choice` | required / option_map / default_value | label in the cell, mapped value on the wire |
80
- | `multiple_choice` | required / option_map / default_value | multiple values separated by semicolons |
53
+ | `multiple_choice` | required / option_map / default_value | Chinese or English semicolons; exports always use `;` |
81
54
 
82
55
  Columns marked `importable: false` only appear in exported files.
83
56
 
@@ -98,32 +71,34 @@ validateField("19.99", {
98
71
  ## Components
99
72
 
100
73
  ```tsx
101
- import { ImportButton, ExportButton, exportRows } from "antd-import-export";
74
+ import { ImportButton, ExportButton, exportRowsToFile } from "antd-import-export";
102
75
 
103
76
  <ImportButton
104
77
  title="Supplier"
105
78
  fieldSchemas={fieldSchemas}
106
- importRows={(payloads, signal) => importSuppliers(payloads, signal)}
107
- onImported={refresh}
79
+ importRows={(rows, signal) => importSuppliers(rows, signal)}
80
+ afterImport={refresh}
108
81
  />;
109
82
 
110
83
  <ExportButton
111
84
  title="Supplier"
112
85
  fieldSchemas={fieldSchemas}
113
- filters={queryForm}
114
86
  totalCount={totalCount}
115
- fetchPage={(params, signal) => exportSuppliers(params, signal)}
87
+ // merge your own filters inside exportRows; paging params come from the package
88
+ exportRows={(params, signal) => exportSuppliers({ ...queryForm, ...params }, signal)}
116
89
  />;
117
90
  ```
118
91
 
119
- Neither component issues requests: they call the `importRows` / `fetchPage` you provide.
92
+ Neither component issues requests: they call the `importRows` / `exportRows` you provide.
93
+
94
+ Call `resetTasks()` on logout or account switch to abort every in-flight import/export and clear the task list.
120
95
 
121
96
  To export rows that are already in memory, render your own button and call the function:
122
97
 
123
98
  ```tsx
124
- import { exportRows } from "antd-import-export";
99
+ import { exportRowsToFile } from "antd-import-export";
125
100
 
126
- await exportRows({ title: "Supplier", fieldSchemas, rows: selectedRows });
101
+ await exportRowsToFile({ title: "Supplier", fieldSchemas, rows: selectedRows });
127
102
  ```
128
103
 
129
104
  ### ImportButton
@@ -132,8 +107,10 @@ await exportRows({ title: "Supplier", fieldSchemas, rows: selectedRows });
132
107
  | --- | --- | --- |
133
108
  | `title` | `string` | shared by the button, template file name and task title |
134
109
  | `fieldSchemas` | `FieldSchema[]` | field definitions |
110
+ | `maxRows` | `number` | per-import limit, defaults to 20,000 rows |
135
111
  | `importRows` | `(rows, signal) => Promise<Record<string, unknown>[]>` | submits one batch, returns the same length; **empty object means success** |
136
- | `onImported` | `() => void` | called when the task finishes |
112
+ | `beforeImport` | `() => void \| Promise<void>` | runs before submitting; throw to abort |
113
+ | `afterImport` | `() => void` | fires once when the task ends (completed / failed / canceled) |
137
114
 
138
115
  ### ExportButton
139
116
 
@@ -141,34 +118,23 @@ await exportRows({ title: "Supplier", fieldSchemas, rows: selectedRows });
141
118
  | --- | --- | --- |
142
119
  | `title` | `string` | file name and task title |
143
120
  | `fieldSchemas` | `FieldSchema[]` | field definitions |
144
- | `filters` | `Record<string, unknown>` | merged into every page request |
145
- | `totalCount` | `number` | used for the row limit and progress total |
146
- | `fetchPage` | `(params, signal) => Promise<{ count, results }>` | cursor paging; **every row needs a numeric `id`** |
147
- | `buttonText` | `string` | defaults to `导出` |
121
+ | `totalCount` | `number` | current row count, only used to detect an empty list |
122
+ | `maxRows` | `number` | per-export limit, defaults to 20,000 rows; checked after every page |
123
+ | `exportRows` | `(params, signal) => Promise<{ count, results }>` | cursor paging; **every row needs a numeric `id`** |
124
+ | `beforeExport` | `() => void \| Promise<void>` | runs before the task is created; throw to abort |
125
+ | `afterExport` | `() => void` | fires once when the task ends (completed / failed / canceled) |
148
126
 
149
- ### exportRows
127
+ ### exportRowsToFile
150
128
 
151
129
  | option | type | notes |
152
130
  | --- | --- | --- |
153
131
  | `title` | `string` | used to build `title_timestamp.xlsx` |
154
132
  | `fieldSchemas` | `FieldSchema[]` | field definitions |
155
133
  | `rows` | `object[]` | rows already in memory |
134
+ | `maxRows` | `number` | per-export limit, defaults to 20,000 rows |
156
135
 
157
136
  Returns `Promise<Blob>`. Throws a ready-to-display error when `rows` is empty or exceeds 20,000; it does not show messages or manage loading state.
158
137
 
159
- ### Custom trigger
160
-
161
- To use your own button while reusing the task engine and progress modal:
162
-
163
- ```tsx
164
- const [taskId, setTaskId] = useState<string>();
165
-
166
- <button onClick={() => setTaskId(enqueueExport({ title, fileName, fieldSchemas, fetchPage }))}>Export</button>;
167
- {
168
- taskId ? <ExportTaskModal taskId={taskId} onClose={() => setTaskId(undefined)} /> : null;
169
- }
170
- ```
171
-
172
138
  ### Two prerequisites
173
139
 
174
140
  1. They use `App.useApp()`, so wrap the root with antd's `<App>`.
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ import type { ImportRow } from "../core/excel/importRow";
3
+ import type { FieldSchema } from "../core/schema";
4
+ interface EditableImportCellProps {
5
+ field: FieldSchema;
6
+ record: ImportRow;
7
+ disabled: boolean;
8
+ onChange: (value: unknown) => void;
9
+ onSave: (value: unknown) => void;
10
+ }
11
+ declare const EditableImportCell: React.FC<EditableImportCellProps>;
12
+ export default EditableImportCell;
@@ -3,13 +3,18 @@ import type { FieldSchema } from "../core/schema";
3
3
  import type { PagedData } from "../core/types";
4
4
  export interface ExportButtonProps {
5
5
  title: string;
6
- buttonText?: string;
7
6
  fieldSchemas: FieldSchema[];
8
- filters: Record<string, unknown>;
9
- /** 当前列表按同样筛选条件查出的总条数 */
7
+ /** 当前列表的条数, 只用于判断有没有数据; 实际上限以接口返回的总数为准 */
10
8
  totalCount: number;
9
+ /** 单次导出上限, 默认 2 万行 */
10
+ maxRows?: number;
11
11
  disabled?: boolean;
12
- fetchPage: (params: Record<string, unknown>, signal: AbortSignal) => Promise<PagedData<object>>;
12
+ /** 拉取一页待导出的数据; 分页参数由包传入, 筛选条件在这里合并 */
13
+ exportRows: (params: Record<string, unknown>, signal: AbortSignal) => Promise<PagedData<object>>;
14
+ /** 创建任务前触发, 可做二次确认或自定义校验; 抛错则中止, 不创建任务 */
15
+ beforeExport?: () => void | Promise<void>;
16
+ /** 导出任务结束(成功/失败/取消)时回调一次 */
17
+ afterExport?: () => void;
13
18
  }
14
19
  declare const ExportButton: React.FC<ExportButtonProps>;
15
20
  export default ExportButton;
@@ -4,8 +4,14 @@ import type { FieldSchema } from "../core/schema";
4
4
  export interface ImportButtonProps {
5
5
  title: string;
6
6
  fieldSchemas: FieldSchema[];
7
+ /** 单次导入上限, 默认 2 万行 */
8
+ maxRows?: number;
9
+ /** 提交一批待导入的行, 返回等长的逐行结果; 空对象表示成功 */
7
10
  importRows: (rows: Record<string, unknown>[], signal: AbortSignal) => Promise<ImportRowErrorBody[]>;
8
- onImported: () => void;
11
+ /** 开始提交前触发, 可做二次确认或自定义校验; 抛错则中止, 不创建任务 */
12
+ beforeImport?: () => void | Promise<void>;
13
+ /** 导入任务结束(成功/失败/取消)时回调一次, 通常用来刷新列表 */
14
+ afterImport: () => void;
9
15
  }
10
16
  declare const ImportButton: React.FC<ImportButtonProps>;
11
17
  export default ImportButton;
@@ -0,0 +1,20 @@
1
+ import type { ImportRow } from "../core/excel/importRow";
2
+ import type { TaskItem } from "../core/task";
3
+ export type DataStatusKey = "valid" | "invalid";
4
+ export type ImportStatusKey = "pending" | "running" | "completed" | "failed" | "canceled";
5
+ export declare function getTaskMeta(task: TaskItem): {
6
+ label: string;
7
+ color: string;
8
+ };
9
+ export declare function getRemainingTimeText(task: TaskItem, remainingSeconds: number | null): string | null;
10
+ export declare function getTaskProgressStatus(task: TaskItem): "exception" | "success" | "normal";
11
+ export declare const dataStatusMeta: Record<DataStatusKey, {
12
+ label: string;
13
+ color: string;
14
+ }>;
15
+ export declare const importStatusMeta: Record<ImportStatusKey, {
16
+ label: string;
17
+ color: string;
18
+ }>;
19
+ export declare function getDataStatusKey(record: ImportRow): DataStatusKey;
20
+ export declare function getImportStatusKey(record: ImportRow, taskId: string | undefined, task: TaskItem | undefined): ImportStatusKey;
@@ -1,16 +1,16 @@
1
1
  import type { FieldSchema } from "../schema";
2
2
  /** 生成 `标题_20261123153300` 形式的文件名(不含扩展名) */
3
3
  export declare function makeExportFileName(title: string): string;
4
- /** 条数超出上限时返回可直接展示的提示, 未超出返回 null */
5
- export declare function formatExportRowLimitMessage(rowCount: number): string | null;
6
- export interface ExportRowsOptions {
4
+ export interface ExportRowsToFileOptions {
7
5
  title: string;
8
6
  fieldSchemas: FieldSchema[];
9
7
  rows: object[];
8
+ /** 单次导出上限, 默认 2 万行 */
9
+ maxRows?: number;
10
10
  }
11
11
  /**
12
12
  * 导出内存中的一批行: 校验条数上限、按约定生成文件名并下载。
13
13
  * 只负责数据到文件, 不弹提示也不管理 loading;
14
14
  * 没有数据或超出上限时抛出可直接展示的错误, 由调用方决定如何反馈。
15
15
  */
16
- export declare function exportRows(options: ExportRowsOptions): Promise<Blob>;
16
+ export declare function exportRowsToFile(options: ExportRowsToFileOptions): Promise<Blob>;
@@ -1,5 +1,9 @@
1
- /** 单次导入/导出的最大行数 */
1
+ /** 单次导入/导出的默认行数上限 */
2
2
  export declare const MAX_IMPORT_ROWS = 20000;
3
3
  export declare const MAX_EXPORT_ROWS = 20000;
4
4
  /** 单个导入文件大小上限 */
5
5
  export declare const MAX_IMPORT_FILE_SIZE: number;
6
+ /** 条数超出上限时返回可直接展示的提示, 未超出返回 null */
7
+ export declare function formatRowLimitMessage(rowCount: number, maxRows: number, direction: "导入" | "导出"): string | null;
8
+ /** 超出上限时抛出可直接展示的错误 */
9
+ export declare function assertRowLimit(rowCount: number, maxRows: number, direction: "导入" | "导出"): void;
@@ -0,0 +1,4 @@
1
+ import type { ExportTaskOptions } from "./types";
2
+ export declare function enqueueExport(options: ExportTaskOptions): string;
3
+ /** 重复下载已完成的导出文件 */
4
+ export declare function downloadTask(taskId: string): boolean;
@@ -0,0 +1,21 @@
1
+ import type { ImportRow } from "../excel/importRow";
2
+ import type { ImportTaskOptions } from "./types";
3
+ export declare function clearImportFlush(taskId: string): void;
4
+ /** 清空合批队列与定时器; 退出登录、清空任务时调用 */
5
+ export declare function clearImportFlushTimer(): void;
6
+ /** 新增并立即执行导入任务; 任务内部按配置的并发数逐行执行 */
7
+ export declare function enqueueImport(options: ImportTaskOptions): string;
8
+ /**
9
+ * 继续导入: 从头扫一遍, 只执行非已完成行, 让暂停/失败后编辑过的行重新提交.
10
+ */
11
+ export declare function continueTask(taskId: string): void;
12
+ /** 暂停导入: 当前请求/当前行结束后停下, 不 abort 已发出的导入写请求 */
13
+ export declare function pauseTask(taskId: string): void;
14
+ /** 暂停时保存待导入行的编辑结果, 继续任务时使用新数据 */
15
+ export declare function updateImportRowData(taskId: string, rowIndex: number, row: ImportRow): void;
16
+ /** 校验失败行仍留在任务里, 只标记跳过并保存校验错误; 修复后取消标记即可, 不移动数组 */
17
+ export declare function setImportRowValidation(taskId: string, rowIndex: number, validationErrors: Record<string, string>): void;
18
+ /** 暂停时删除尚未导入的行: 从后续调度中跳过, 已完成/失败/进行中的行不允许删除 */
19
+ export declare function deleteImportRows(taskId: string, rowIndexes: number[]): void;
20
+ /** 编辑失败行某个字段后, 清掉该字段上一次的后端错误 */
21
+ export declare function clearImportRowFieldError(taskId: string, rowIndex: number, field: string): void;
@@ -0,0 +1,12 @@
1
+ export type { ExportTaskOptions, ImportRowStatus, ImportTaskOptions, TaskItem, TaskStatus } from "./types";
2
+ export { ImportPauseError } from "./types";
3
+ export { getTasksSnapshot, subscribeTasks } from "./store";
4
+ export { downloadTask, enqueueExport } from "./exportRunner";
5
+ export { clearImportRowFieldError, continueTask, deleteImportRows, enqueueImport, pauseTask, setImportRowValidation, updateImportRowData, } from "./importRunner";
6
+ export { formatTaskPercent, formatTaskRemainingSeconds, getTaskDisplayPercent, getTaskRemainingSeconds, getTaskSuccessCount, } from "./stats";
7
+ /** 取消: 停止任务但保留任务和预览, 由用户关闭/清除 */
8
+ export declare function cancelTask(taskId: string): void;
9
+ /** 移除任务; 执行中的任务先中断, 完成任务的 Blob 也会随引用释放 */
10
+ export declare function dismissTask(taskId: string): void;
11
+ /** 退出登录/切换账号时清空当前用户的任务, 同时中断所有在途请求 */
12
+ export declare function resetTasks(): void;
@@ -0,0 +1,16 @@
1
+ import type { TaskItem, TaskSample } from "./types";
2
+ /** 采样只保留最近 15 秒(最多 20 个点): 用近期速度估算剩余时间, 不被任务开始阶段的慢速拖住 */
3
+ export declare function appendSample(previousSamples: TaskSample[], processed: number): TaskSample[];
4
+ /**
5
+ * 剩余时间估算: 采样只覆盖最近 15 秒, 取首尾两点算近期速度, 再按剩余行数外推.
6
+ * 任务刚起步、采样不足或速度算不出来时返回 null, 调用方显示"计算中".
7
+ */
8
+ export declare function getTaskRemainingSeconds(task: TaskItem): number | null;
9
+ /** 导入任务的完成数只看成功导入的行; 失败/跳过/校验失败都不算完成 */
10
+ export declare function getTaskSuccessCount(task: TaskItem): number;
11
+ /** 显示用百分比: 未完成时直接截断, 不四舍五入成 100% */
12
+ export declare function getTaskDisplayPercent(task: TaskItem): number;
13
+ /** 百分比展示固定一位小数; 传入值已经截断, 这里不会再发生进位 */
14
+ export declare function formatTaskPercent(percent: number): string;
15
+ /** 剩余时间转中文文案; null 表示采样点还不够, 算不出速度 */
16
+ export declare function formatTaskRemainingSeconds(remainingSeconds: number | null): string;
@@ -0,0 +1,17 @@
1
+ import type { ExportRuntime, ImportRuntime, TaskItem } from "./types";
2
+ export declare const exportRuntimes: Map<string, ExportRuntime>;
3
+ export declare const importRuntimes: Map<string, ImportRuntime>;
4
+ export declare const controllers: Map<string, AbortController>;
5
+ /** 供框架层订阅任务变化; store 本身不依赖 React */
6
+ export declare function subscribeTasks(listener: () => void): () => void;
7
+ /** 供框架层读取当前任务快照; 没有变化时返回同一引用 */
8
+ export declare function getTasksSnapshot(): TaskItem[];
9
+ export declare function makeTaskId(): string;
10
+ export declare function findTask(taskId: string): TaskItem | undefined;
11
+ export declare function updateTask(taskId: string, patch: Partial<TaskItem>): void;
12
+ /** 新增任务并通知订阅者 */
13
+ export declare function addTask(task: TaskItem): void;
14
+ /** 移除任务并通知订阅者 */
15
+ export declare function removeTask(taskId: string): void;
16
+ /** 清空所有任务与在途请求 */
17
+ export declare function resetStore(): void;
@@ -0,0 +1,105 @@
1
+ import type { ImportRow } from "../excel/importRow";
2
+ import type { FieldSchema } from "../schema";
3
+ import type { ImportRowFieldError, ImportRowResult, PagedData } from "../types";
4
+ export type TaskStatus = "running" | "paused" | "completed" | "failed" | "canceled";
5
+ type TaskType = "export" | "import";
6
+ export interface TaskSample {
7
+ time: number;
8
+ processed: number;
9
+ }
10
+ export type ImportRowStatus = "queued" | "running" | "completed" | "failed" | "canceled" | "deleted";
11
+ export interface ImportRowState {
12
+ status: ImportRowStatus;
13
+ message?: string;
14
+ fieldErrors?: ImportRowFieldError[];
15
+ validationErrors?: Record<string, string>;
16
+ }
17
+ interface ImportFailure {
18
+ index: number;
19
+ rowNumber: number;
20
+ message: string;
21
+ fieldErrors?: ImportRowFieldError[];
22
+ }
23
+ export interface TaskItem {
24
+ id: string;
25
+ type: TaskType;
26
+ title: string;
27
+ status: TaskStatus;
28
+ pausing?: boolean;
29
+ total: number;
30
+ processed: number;
31
+ errorMessage?: string;
32
+ fileName?: string;
33
+ blob?: Blob;
34
+ failures?: ImportFailure[];
35
+ rowStates?: ImportRowState[];
36
+ /** 导入成功行数; 导出任务不使用 */
37
+ successCount?: number;
38
+ /** 导入失败行数; 导出任务不使用 */
39
+ failureCount?: number;
40
+ /** 导入中因前端校验待修复的行数 */
41
+ validationFailedCount?: number;
42
+ /** 导出任务正在生成文件/触发下载 */
43
+ finalizing?: boolean;
44
+ /** 导入任务正在取消, 在途行结束前保持该状态 */
45
+ canceling?: boolean;
46
+ samples: TaskSample[];
47
+ }
48
+ export interface TaskState {
49
+ tasks: TaskItem[];
50
+ }
51
+ export interface ExportTaskOptions {
52
+ title: string;
53
+ fileName: string;
54
+ fieldSchemas: FieldSchema[];
55
+ exportRows: (params: Record<string, unknown>, signal: AbortSignal) => Promise<PagedData<object>>;
56
+ /** 单次导出上限, 默认 2 万行; 每页返回后都会校验 */
57
+ maxRows?: number;
58
+ /** 任务结束(成功/失败/取消)时回调一次, 用于埋点或清理 */
59
+ onFinished?: () => void;
60
+ }
61
+ /** 导入行遇到权限/系统错误时立即暂停任务, 不按普通行级失败继续执行 */
62
+ export declare class ImportPauseError extends Error {
63
+ constructor(message: string);
64
+ }
65
+ export interface ImportTaskOptions {
66
+ title: string;
67
+ /** 唯一数据源: 行值、校验错误、行号都在这里, 提交时再派生接口 payload */
68
+ rows: ImportRow[];
69
+ fieldSchemas: FieldSchema[];
70
+ /** 文件里实际存在的列; 更新时未包含的列表示不修改 */
71
+ includedKeys: string[];
72
+ importRows: (rows: ImportRow[], signal: AbortSignal) => Promise<ImportRowResult[]>;
73
+ /** 单次导入上限, 默认 2 万行 */
74
+ maxRows?: number;
75
+ /** 每批行数; 批越小请求返回越快, 默认 20 */
76
+ batchSize?: number;
77
+ /** 同时执行的批次数量, 默认 3 */
78
+ concurrency?: number;
79
+ onFinished?: () => void;
80
+ }
81
+ export interface ExportRuntime {
82
+ options: ExportTaskOptions;
83
+ cursorId?: number;
84
+ rows: object[];
85
+ total: number;
86
+ cancelRequested: boolean;
87
+ controller: AbortController | null;
88
+ }
89
+ export interface ImportRuntime {
90
+ options: ImportTaskOptions;
91
+ nextIndex: number;
92
+ processed: number;
93
+ successCount: number;
94
+ failures: ImportFailure[];
95
+ rowStates: ImportRowState[];
96
+ validationFailedCount: number;
97
+ pauseRequested: boolean;
98
+ cancelRequested: boolean;
99
+ deletedIndexes: Set<number>;
100
+ skippedIndexes: Set<number>;
101
+ /** 本轮执行累计的失败行数, 超过阈值触发暂停 */
102
+ runFailureCount: number;
103
+ controller: AbortController | null;
104
+ }
105
+ export {};