antd-import-export 1.0.7 → 1.0.9

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
@@ -26,7 +26,17 @@
26
26
 
27
27
  ## 字段定义
28
28
 
29
- 导入导出的一切都由 `FieldSchema[]` 驱动:导出用它生成表头,导入模板用它写填写要求,解析时用它逐格校验。
29
+ 导入导出的一切都由 `FieldSchema[]` 驱动:导出用它生成表头,导入模板用它写填写要求,解析时用它逐格校验。**数组顺序就是列顺序。**
30
+
31
+ 每个字段由公共部分和类型相关的 `property` 组成:
32
+
33
+ | 属性 | 必填 | 说明 |
34
+ | --- | --- | --- |
35
+ | `key` | 是 | 接口字段名;导出取数、提交 payload、行级错误回填都按它对应 |
36
+ | `title` | 是 | 列名:导出表头、模板里的填写说明、预览表格的列标题都用它 |
37
+ | `type` | 是 | 九种类型之一,决定 `property` 的结构和校验规则 |
38
+ | `property` | 是 | 类型相关配置,见下表 |
39
+ | `importable` | 否 | 默认 `true`。设为 `false` 表示该列**只导出不导入**:不进模板、不参与解析,导出表头会标注「(仅导出)」 |
30
40
 
31
41
  ```ts
32
42
  import type { FieldSchema } from "antd-import-export";
@@ -53,13 +63,12 @@ const fieldSchemas: FieldSchema[] = [
53
63
  | `number` | required / precision / max_digits? / min_value? / max_value? / default_value | 精度按十进制位数判断,不受浮点误差影响 |
54
64
  | `boolean` | required / true_label / false_label / default_value | 单元格填文案,接口值转成布尔 |
55
65
  | `date` | required / default_value | 严格 `YYYY-MM-DD` |
56
- | `time` | required / default_value | 严格 `HH:mm`,输出补零 |
66
+ | `time` | required / default_value | 严格 `HH:mm` 或 `HH:mm:ss`,输出补零,秒为 0 时不带秒 |
57
67
  | `datetime` | required / default_value | 严格 `YYYY-MM-DD HH:mm` 或 `YYYY-MM-DD HH:mm:ss`,秒为 0 时不带秒 |
58
68
  | `list` | required / list_max_length / text_max_length / item_key? / default_value | 中英文分号分隔,导出统一用英文分号 |
59
69
  | `single_choice` | required / option_map / default_value | 单元格填文案,接口值取 option_map 里的值 |
60
70
  | `multiple_choice` | required / option_map / default_value | 中英文分号分隔,导出统一用英文分号 |
61
71
 
62
- `importable: false` 的列只出现在导出文件里,不参与导入模板和解析。
63
72
 
64
73
  ## 逐字段校验
65
74
 
@@ -85,7 +94,7 @@ import { ImportButton, ExportButton, exportRowsToFile } from "antd-import-export
85
94
  <ImportButton
86
95
  title="供应商"
87
96
  fieldSchemas={dataSchema}
88
- importRows={(rows, signal) => supplierImportData(rows, signal)}
97
+ importRows={(rows) => supplierImportData(rows)}
89
98
  afterImport={onRefresh}
90
99
  />;
91
100
 
@@ -94,13 +103,13 @@ import { ImportButton, ExportButton, exportRowsToFile } from "antd-import-export
94
103
  title="供应商"
95
104
  fieldSchemas={dataSchema}
96
105
  // 筛选条件在自己的 exportRows 里合并, 分页参数由包传入
97
- exportRows={(params, signal) => supplierExportData({ ...queryForm, ...params }, signal)}
106
+ exportRows={(params) => supplierExportData({ ...queryForm, ...params })}
98
107
  />;
99
108
  ```
100
109
 
101
110
  两个组件都不发请求,只调用你传进来的 `importRows` / `exportRows`。
102
111
 
103
- 列表为空时用 `disabled` 禁用按钮,或在前置回调里拦截——组件本身不关心列表条数,上限以接口返回的总数为准。
112
+ 列表为空时用 `disabled` 禁用按钮,或在前置回调里拦截——组件不关心列表条数,也不内置条数上限。
104
113
 
105
114
  退出登录或切换账号时调用 `resetTasks()`,会中止所有在途的导入导出并清空任务。
106
115
 
@@ -119,11 +128,11 @@ await exportRowsToFile({ title: "供应商", fieldSchemas: dataSchema, rows: sel
119
128
  | `title` | `string` | 按钮、模板文件名、任务标题共用 |
120
129
  | `fieldSchemas` | `FieldSchema[]` | 字段定义 |
121
130
  | `buttonText` | `string` | 导入按钮文案,默认「导入」 |
122
- | `maxRows` | `number` | 单次导入上限,默认 2 万行;超出直接拦在提交前 |
123
- | `batchSize` | `number` | 每批提交的行数,默认 20,范围 1–200 |
124
- | `importRows` | `(rows, signal) => Promise<Record<string, unknown>[]>` | 一批行提交,返回等长结果;**空对象表示成功** |
125
- | `beforeImport` | `() => void \| Promise<void>` | 提交前触发,可做二次确认或自定义校验;抛错即中止 |
126
- | `afterImport` | `() => void` | 任务结束(成功/失败/取消)时触发一次,通常用来刷新列表 |
131
+ | `batchSize` | `number` | 每批提交的行数,默认 20,上限 200(与后端约定);非法值回落到 20 |
132
+ | `importRows` | `(rows) => Promise<Record<string, unknown>[]>` | 一批行提交,返回等长结果;**空对象表示成功** |
133
+ | `beforeImport` | `(rows) => void \| Promise<void>` | 解析完成、打开预览前触发;`rows` 是解析并校验过的行;抛错即中止 |
134
+ | `afterImport` | `() => void` | 任务结束(成功/失败/取消)时触发一次,通常用来刷新列表;暂停不触发 |
135
+ | `onModalClose` | `() => void` | 弹窗关闭后触发一次,完成、取消、中途关闭都会触发 |
127
136
 
128
137
  ### ExportButton
129
138
 
@@ -132,11 +141,10 @@ await exportRowsToFile({ title: "供应商", fieldSchemas: dataSchema, rows: sel
132
141
  | `title` | `string` | 文件名与任务标题 |
133
142
  | `fieldSchemas` | `FieldSchema[]` | 字段定义 |
134
143
  | `buttonText` | `string` | 按钮文案,默认「导出」 |
135
- | `maxRows` | `number` | 单次导出上限,默认 2 万行;每页返回后都会校验 |
136
- | `batchSize` | `number` | 每页请求条数,以 `page_size` 传给接口;不传由后端决定 |
137
- | `exportRows` | `(params, signal) => Promise<{ count, results }>` | 游标分页;**每行必须带数字 `id`** |
144
+ | `exportRows` | `(params) => Promise<{ count, results }>` | 游标分页;**每行必须带数字 `id`** |
138
145
  | `beforeExport` | `() => void \| Promise<void>` | 创建任务前触发,可做二次确认或自定义校验;抛错即中止 |
139
146
  | `afterExport` | `() => void` | 任务结束(成功/失败/取消)时触发一次 |
147
+ | `onModalClose` | `() => void` | 弹窗关闭后触发一次,无论任务是否结束 |
140
148
 
141
149
  生成文件期间取消按钮会禁用:ExcelJS 的解析与生成是一整段同步执行,主线程被占满时 abort 只在结束后才生效。
142
150
 
@@ -147,7 +155,6 @@ await exportRowsToFile({ title: "供应商", fieldSchemas: dataSchema, rows: sel
147
155
  | `title` | `string` | 用于生成 `标题_时间戳.xlsx` |
148
156
  | `fieldSchemas` | `FieldSchema[]` | 字段定义 |
149
157
  | `rows` | `object[]` | 已在内存中的行 |
150
- | `maxRows` | `number` | 单次导出上限,默认 2 万行 |
151
158
 
152
159
  返回 `Promise<Blob>`。空数组或超过 2 万行时**抛出可直接展示的错误**;不弹提示、不管理 loading,由调用方决定交互。
153
160
 
@@ -172,13 +179,36 @@ await exportRowsToFile({ title: "供应商", fieldSchemas: dataSchema, rows: sel
172
179
 
173
180
  除返回数组之外,`importRows` 抛出的任何异常都会暂停整个任务(取消时除外),不区分状态码。提示文案依次取:后端返回的 `detail` → HTTP 状态码对应的可读文案 → `error.message`。
174
181
 
182
+ ### beforeImport 拿到什么
183
+
184
+ `beforeImport(rows)` 在**解析完成、打开预览之前**触发,拿到的是解析并逐格校验过的行:
185
+
186
+ | 内容 | 是否包含 |
187
+ | --- | --- |
188
+ | 解析出的行 | ✅ |
189
+ | 逐格校验结果 | ✅ 在 `errors` 里 |
190
+ | 用户的编辑 | ❌ 此时还没进入预览,自然没有编辑 |
191
+ | 用户删除的行 | ❌ 同上 |
192
+
193
+ 抛错即中止,**预览不会打开**。典型用途是条数上限和准入判断:
194
+
195
+ ```tsx
196
+ beforeImport={(rows) => {
197
+ if (rows.length > 20000) {
198
+ throw new Error(`导入数据 ${rows.length.toLocaleString()} 条,超过上限 20,000 条,请分批导入`);
199
+ }
200
+ }}
201
+ ```
202
+
203
+ `rows` 里可能含校验失败的行(`errors` 非空),它们后续提交时会被跳过;如果只想按可提交的行数判断,自行过滤即可。
204
+
175
205
  ### 导出数据约定
176
206
 
177
207
  `exportRows` 每次拉一页数据,返回:
178
208
 
179
209
  | 字段 | 类型 | 说明 |
180
210
  | --- | --- | --- |
181
- | `count` | `number` | 当前筛选条件下的总条数,用于进度显示与上限校验 |
211
+ | `count` | `number` | 当前筛选条件下的总条数,用于进度显示 |
182
212
  | `results` | `object[]` | 本页数据;**每行必须有数字 `id`**,包用它做游标 |
183
213
 
184
214
  分页规则由包驱动,`exportRows` 收到的参数只有两种:
@@ -188,9 +218,10 @@ await exportRowsToFile({ title: "供应商", fieldSchemas: dataSchema, rows: sel
188
218
  | 第一页 | `{}` |
189
219
  | 后续页 | `{ cursor_id: 上一页最后一条的 id }` |
190
220
 
191
- 配了 `batchSize` 时,两种调用都会多带一个 `page_size`。
192
221
 
193
- `results` 返回空数组即视为没有更多数据,任务结束。每页条数由后端决定,包不传 `page_size`。
222
+ 包只传游标,不传任何分页参数——每次拉多少条由后端决定,或在你的 `exportRows` 里自己加。
223
+
224
+ `results` 返回空数组即视为没有更多数据,任务结束。
194
225
 
195
226
  ### 错误状态码的识别
196
227
 
@@ -203,19 +234,17 @@ await exportRowsToFile({ title: "供应商", fieldSchemas: dataSchema, rows: sel
203
234
 
204
235
  axios 的错误天然符合第一种形状。用 fetch 的时候,请把 `Response` 包成上面任一种形状再抛出,否则会被当成普通异常,只显示「导入失败, 任务已暂停」这类通用文案,而不是「登录已过期」这种具体提示。
205
236
 
206
- ### signal 的语义
237
+ ### 取消与暂停的时机
207
238
 
208
- `importRows` / `exportRows` 拿到的是同一个 `AbortSignal`,触发时机不同:
239
+ 点「取消」或「暂停」后,**当前请求会先跑完**,任务再进入终态。不会中断已经发出去的请求:
209
240
 
210
- | 时机 | 是否触发 |
241
+ | 动作 | 行为 |
211
242
  | --- | --- |
212
- | 关闭弹窗、卸载页面 | ✅ |
213
- | 退出登录 `resetTasks()` | ✅ |
214
- | 导出点击「取消」 | ✅ |
215
- | 导入点击「取消」 | ❌ 故意不触发 |
216
- | 导入点击「暂停」 | ❌ 故意不触发 |
243
+ | 导出取消 | 等当前页返回后结束 |
244
+ | 导入取消 / 暂停 | 等在途批次返回后结束 |
245
+ | 关闭弹窗、退出登录 | 同上,任务被丢弃,在途请求跑完自行结束 |
217
246
 
218
- 导入是写操作:中断已发出的批次后,无法确定服务端是否落库。所以取消和暂停都只停止领取新批次,等在途批次返回、拿到真实结果后再结束任务。导出是只读的,取消会立即中断请求。
247
+ 导入是写操作,中断在途批次后无法确定服务端是否落库,因此两边的取消语义保持一致:**只停止领取新批次**。
219
248
 
220
249
  ### 两个使用前提
221
250
 
package/README_EN.md CHANGED
@@ -25,7 +25,17 @@
25
25
 
26
26
  ## Field schema
27
27
 
28
- Everything is driven by `FieldSchema[]`: export headers, template hints and cell-level validation.
28
+ Everything is driven by `FieldSchema[]`: export headers, template hints and cell-level validation. **The array order is the column order.**
29
+
30
+ Each field is the common part plus a type-specific `property`:
31
+
32
+ | Field | Required | Notes |
33
+ | --- | --- | --- |
34
+ | `key` | yes | API field name; used for export data, the submit payload and mapping row errors back |
35
+ | `title` | yes | Column name: export header, template hint and preview column all use it |
36
+ | `type` | yes | One of nine types; decides the shape of `property` and the validation rules |
37
+ | `property` | yes | Type-specific config, see the table below |
38
+ | `importable` | no | Defaults to `true`. `false` means **export only**: excluded from the template and parsing, and the export header is marked "(仅导出)" |
29
39
 
30
40
  ```ts
31
41
  import type { FieldSchema } from "antd-import-export";
@@ -46,13 +56,12 @@ const fieldSchemas: FieldSchema[] = [
46
56
  | `number` | required / precision / max_digits? / min_value? / max_value? / default_value | precision judged on decimal places |
47
57
  | `boolean` | required / true_label / false_label / default_value | labels in the cell, boolean on the wire |
48
58
  | `date` | required / default_value | strict `YYYY-MM-DD` |
49
- | `time` | required / default_value | strict `HH:mm` |
59
+ | `time` | required / default_value | strict `HH:mm` or `HH:mm:ss`; seconds are dropped when zero |
50
60
  | `datetime` | required / default_value | strict `YYYY-MM-DD HH:mm` or `YYYY-MM-DD HH:mm:ss`; seconds are dropped when zero |
51
61
  | `list` | required / list_max_length / text_max_length / item_key? / default_value | Chinese or English semicolons; exports always use `;` |
52
62
  | `single_choice` | required / option_map / default_value | label in the cell, mapped value on the wire |
53
63
  | `multiple_choice` | required / option_map / default_value | Chinese or English semicolons; exports always use `;` |
54
64
 
55
- Columns marked `importable: false` only appear in exported files.
56
65
 
57
66
  ## Validation
58
67
 
@@ -76,7 +85,7 @@ import { ImportButton, ExportButton, exportRowsToFile } from "antd-import-export
76
85
  <ImportButton
77
86
  title="Supplier"
78
87
  fieldSchemas={fieldSchemas}
79
- importRows={(rows, signal) => importSuppliers(rows, signal)}
88
+ importRows={(rows) => importSuppliers(rows)}
80
89
  afterImport={refresh}
81
90
  />;
82
91
 
@@ -84,13 +93,13 @@ import { ImportButton, ExportButton, exportRowsToFile } from "antd-import-export
84
93
  title="Supplier"
85
94
  fieldSchemas={fieldSchemas}
86
95
  // merge your own filters inside exportRows; paging params come from the package
87
- exportRows={(params, signal) => exportSuppliers({ ...queryForm, ...params }, signal)}
96
+ exportRows={(params) => exportSuppliers({ ...queryForm, ...params })}
88
97
  />;
89
98
  ```
90
99
 
91
100
  Neither component issues requests: they call the `importRows` / `exportRows` you provide.
92
101
 
93
- Disable the button when the list is empty, or reject inside the before callback — the component does not know the row count, and the limit comes from the API response.
102
+ Disable the button when the list is empty, or reject inside the before callback — the component neither knows nor enforces the row count.
94
103
 
95
104
  Call `resetTasks()` on logout or account switch to abort every in-flight import/export and clear the task list.
96
105
 
@@ -109,11 +118,11 @@ await exportRowsToFile({ title: "Supplier", fieldSchemas, rows: selectedRows });
109
118
  | `title` | `string` | shared by the button, template file name and task title |
110
119
  | `fieldSchemas` | `FieldSchema[]` | field definitions |
111
120
  | `buttonText` | `string` | import button label, defaults to `导入` |
112
- | `maxRows` | `number` | per-import limit, defaults to 20,000 rows |
113
- | `batchSize` | `number` | rows submitted per batch, defaults to 20 (1–200) |
114
- | `importRows` | `(rows, signal) => Promise<Record<string, unknown>[]>` | submits one batch, returns the same length; **empty object means success** |
115
- | `beforeImport` | `() => void \| Promise<void>` | runs before submitting; throw to abort |
116
- | `afterImport` | `() => void` | fires once when the task ends (completed / failed / canceled) |
121
+ | `batchSize` | `number` | rows per batch, defaults to 20, capped at 200 (backend contract); invalid values fall back to 20 |
122
+ | `importRows` | `(rows) => Promise<Record<string, unknown>[]>` | submits one batch, returns the same length; **empty object means success** |
123
+ | `beforeImport` | `(rows) => void \| Promise<void>` | runs after parsing and before the preview opens; `rows` are parsed and validated; throw to abort |
124
+ | `afterImport` | `() => void` | fires once when the task ends (completed / failed / canceled), not on pause |
125
+ | `onModalClose` | `() => void` | fires once after the modal closes, whatever the outcome |
117
126
 
118
127
  ### ExportButton
119
128
 
@@ -122,11 +131,10 @@ await exportRowsToFile({ title: "Supplier", fieldSchemas, rows: selectedRows });
122
131
  | `title` | `string` | file name and task title |
123
132
  | `fieldSchemas` | `FieldSchema[]` | field definitions |
124
133
  | `buttonText` | `string` | button label, defaults to `导出` |
125
- | `maxRows` | `number` | per-export limit, defaults to 20,000 rows; checked after every page |
126
- | `batchSize` | `number` | rows per page, sent as `page_size`; omitted means the backend decides |
127
- | `exportRows` | `(params, signal) => Promise<{ count, results }>` | cursor paging; **every row needs a numeric `id`** |
134
+ | `exportRows` | `(params) => Promise<{ count, results }>` | cursor paging; **every row needs a numeric `id`** |
128
135
  | `beforeExport` | `() => void \| Promise<void>` | runs before the task is created; throw to abort |
129
136
  | `afterExport` | `() => void` | fires once when the task ends (completed / failed / canceled) |
137
+ | `onModalClose` | `() => void` | fires once after the modal closes |
130
138
 
131
139
  The cancel button is disabled while the file is generated: ExcelJS parses and writes in one synchronous block, so an abort only takes effect after it finishes.
132
140
 
@@ -137,7 +145,6 @@ The cancel button is disabled while the file is generated: ExcelJS parses and wr
137
145
  | `title` | `string` | used to build `title_timestamp.xlsx` |
138
146
  | `fieldSchemas` | `FieldSchema[]` | field definitions |
139
147
  | `rows` | `object[]` | rows already in memory |
140
- | `maxRows` | `number` | per-export limit, defaults to 20,000 rows |
141
148
 
142
149
  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.
143
150
 
@@ -156,13 +163,36 @@ Returns `Promise<Blob>`. Throws a ready-to-display error when `rows` is empty or
156
163
 
157
164
  Beyond returning the array, any error thrown by `importRows` pauses the whole task (except when canceled), regardless of the status code. The message is taken from, in order: the backend `detail` → a readable text for the HTTP status → `error.message`.
158
165
 
166
+ ### What `beforeImport` receives
167
+
168
+ `beforeImport(rows)` runs **after parsing and before the preview opens**, receiving the parsed and per-cell validated rows:
169
+
170
+ | Content | Included |
171
+ | --- | --- |
172
+ | parsed rows | ✅ |
173
+ | per-cell validation | ✅ in `errors` |
174
+ | user edits | ❌ the preview has not opened yet |
175
+ | rows the user deleted | ❌ same reason |
176
+
177
+ Throwing aborts the flow: **the preview never opens**. Typical use is a row limit or an admission check:
178
+
179
+ ```tsx
180
+ beforeImport={(rows) => {
181
+ if (rows.length > 20000) {
182
+ throw new Error(`too many rows: ${rows.length}, limit 20,000`);
183
+ }
184
+ }}
185
+ ```
186
+
187
+ `rows` may still contain failing rows (`errors` non-empty); those are skipped on submit. Filter them if you need the exact submitted count.
188
+
159
189
  ### Export contract
160
190
 
161
191
  `exportRows` fetches one page at a time and returns:
162
192
 
163
193
  | Field | Type | Notes |
164
194
  | --- | --- | --- |
165
- | `count` | `number` | total rows under the current filters, used for progress and the row limit |
195
+ | `count` | `number` | total rows under the current filters, used for progress |
166
196
  | `results` | `object[]` | rows of this page; **every row needs a numeric `id`** for the cursor |
167
197
 
168
198
  Paging is driven by the package, so `exportRows` only ever receives:
@@ -172,9 +202,10 @@ Paging is driven by the package, so `exportRows` only ever receives:
172
202
  | first page | `{}` |
173
203
  | following pages | `{ cursor_id: id of the last row of the previous page }` |
174
204
 
175
- With `batchSize` set, both calls also carry `page_size`.
176
205
 
177
- An empty `results` array ends the task. Page size is up to the backend; the package does not send `page_size`.
206
+ The package only sends the cursor, no paging parameter — the batch size is up to the backend, or add it yourself inside `exportRows`.
207
+
208
+ An empty `results` array ends the task.
178
209
 
179
210
  ### How status codes are detected
180
211
 
@@ -187,19 +218,17 @@ The package does not know your HTTP client; it reads the status from the error y
187
218
 
188
219
  axios errors already match the first shape. With fetch, wrap the `Response` into one of these shapes before throwing, otherwise it is treated as a generic error and shows a generic message instead of "session expired".
189
220
 
190
- ### What `signal` means
221
+ ### When cancel and pause take effect
191
222
 
192
- `importRows` / `exportRows` receive the same `AbortSignal`, but it fires at different moments:
223
+ Cancel and pause take effect **after the current request resolves**; in-flight requests are never aborted:
193
224
 
194
- | Moment | Fires |
225
+ | Action | Behavior |
195
226
  | --- | --- |
196
- | modal closed, page unmounted | ✅ |
197
- | logout via `resetTasks()` | ✅ |
198
- | export canceled | ✅ |
199
- | import canceled | ❌ by design |
200
- | import paused | ❌ by design |
227
+ | export canceled | finishes after the current page resolves |
228
+ | import canceled / paused | finishes after in-flight batches resolve |
229
+ | modal closed, logout | same — the task is dropped, in-flight requests finish on their own |
201
230
 
202
- Import writes data: after aborting an in-flight batch there is no way to know whether the server committed it. Cancel and pause therefore only stop claiming new batches and wait for in-flight ones to settle. Export is read-only, so canceling aborts immediately.
231
+ Import writes data, and aborting an in-flight batch leaves its server-side outcome unknown. Both directions therefore behave the same: **stop claiming new batches only**.
203
232
 
204
233
  ### Two prerequisites
205
234
 
@@ -6,17 +6,15 @@ export interface ExportButtonProps {
6
6
  fieldSchemas: FieldSchema[];
7
7
  /** 按钮文案, 默认「导出」 */
8
8
  buttonText?: string;
9
- /** 单次导出上限, 默认 2 万行 */
10
- maxRows?: number;
11
- /** 每页请求的条数, 以 page_size 传给接口; 不传由后端决定 */
12
- batchSize?: number;
13
9
  disabled?: boolean;
14
10
  /** 拉取一页待导出的数据; 分页参数由包传入, 筛选条件在这里合并 */
15
- exportRows: (params: Record<string, unknown>, signal: AbortSignal) => Promise<PagedData<object>>;
11
+ exportRows: (params: Record<string, unknown>) => Promise<PagedData<object>>;
16
12
  /** 创建任务前触发, 可做二次确认或自定义校验; 抛错则中止, 不创建任务 */
17
13
  beforeExport?: () => void | Promise<void>;
18
14
  /** 导出任务结束(成功/失败/取消)时回调一次 */
19
15
  afterExport?: () => void;
16
+ /** 弹窗关闭后触发, 无论任务是否结束 */
17
+ onModalClose?: () => void;
20
18
  }
21
19
  declare const ExportButton: React.FC<ExportButtonProps>;
22
20
  export default ExportButton;
@@ -1,21 +1,22 @@
1
1
  import React from "react";
2
2
  import type { ImportRowErrorBody } from "../core/types";
3
+ import type { ImportRow } from "../core/excel/importRow";
3
4
  import type { FieldSchema } from "../core/schema";
4
5
  export interface ImportButtonProps {
5
6
  title: string;
6
7
  fieldSchemas: FieldSchema[];
7
8
  /** 导入按钮文案, 默认「导入」; 模板按钮文案固定 */
8
9
  buttonText?: string;
9
- /** 单次导入上限, 默认 2 万行 */
10
- maxRows?: number;
11
10
  /** 每批提交的行数, 默认 20, 范围 1-200 */
12
11
  batchSize?: number;
13
12
  /** 提交一批待导入的行, 返回等长的逐行结果; 空对象表示成功 */
14
- importRows: (rows: Record<string, unknown>[], signal: AbortSignal) => Promise<ImportRowErrorBody[]>;
15
- /** 开始提交前触发, 可做二次确认或自定义校验; 抛错则中止, 不创建任务 */
16
- beforeImport?: () => void | Promise<void>;
13
+ importRows: (rows: Record<string, unknown>[]) => Promise<ImportRowErrorBody[]>;
14
+ /** 解析完成、打开预览前触发, 拿到解析并校验过的行; 可做条数校验或准入判断, 抛错则中止 */
15
+ beforeImport?: (rows: ImportRow[]) => void | Promise<void>;
17
16
  /** 导入任务结束(成功/失败/取消)时回调一次, 通常用来刷新列表 */
18
17
  afterImport: () => void;
18
+ /** 弹窗关闭后触发, 无论是导入完成、取消还是中途关闭 */
19
+ onModalClose?: () => void;
19
20
  }
20
21
  declare const ImportButton: React.FC<ImportButtonProps>;
21
22
  export default ImportButton;
@@ -5,12 +5,10 @@ export interface ExportRowsToFileOptions {
5
5
  title: string;
6
6
  fieldSchemas: FieldSchema[];
7
7
  rows: object[];
8
- /** 单次导出上限, 默认 2 万行 */
9
- maxRows?: number;
10
8
  }
11
9
  /**
12
- * 导出内存中的一批行: 校验条数上限、按约定生成文件名并下载。
10
+ * 导出内存中的一批行: 按约定生成文件名并下载。
13
11
  * 只负责数据到文件, 不弹提示也不管理 loading;
14
- * 没有数据或超出上限时抛出可直接展示的错误, 由调用方决定如何反馈。
12
+ * 没有数据时抛出可直接展示的错误, 由调用方决定如何反馈。
15
13
  */
16
14
  export declare function exportRowsToFile(options: ExportRowsToFileOptions): Promise<Blob>;
@@ -1,9 +1,2 @@
1
- /** 单次导入/导出的默认行数上限 */
2
- export declare const MAX_IMPORT_ROWS = 20000;
3
- export declare const MAX_EXPORT_ROWS = 20000;
4
1
  /** 单个导入文件大小上限 */
5
2
  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;
@@ -52,11 +52,7 @@ export interface ExportTaskOptions {
52
52
  title: string;
53
53
  fileName: string;
54
54
  fieldSchemas: FieldSchema[];
55
- exportRows: (params: Record<string, unknown>, signal: AbortSignal) => Promise<PagedData<object>>;
56
- /** 单次导出上限, 默认 2 万行; 每页返回后都会校验 */
57
- maxRows?: number;
58
- /** 每页请求的条数, 以 page_size 传给接口; 不传由后端决定 */
59
- batchSize?: number;
55
+ exportRows: (params: Record<string, unknown>) => Promise<PagedData<object>>;
60
56
  /** 任务结束(成功/失败/取消)时回调一次, 用于埋点或清理 */
61
57
  onFinished?: () => void;
62
58
  }
@@ -71,9 +67,7 @@ export interface ImportTaskOptions {
71
67
  fieldSchemas: FieldSchema[];
72
68
  /** 文件里实际存在的列; 更新时未包含的列表示不修改 */
73
69
  includedKeys: string[];
74
- importRows: (rows: ImportRow[], signal: AbortSignal) => Promise<ImportRowResult[]>;
75
- /** 单次导入上限, 默认 2 万行 */
76
- maxRows?: number;
70
+ importRows: (rows: ImportRow[]) => Promise<ImportRowResult[]>;
77
71
  /** 每批行数; 批越小请求返回越快, 默认 20 */
78
72
  batchSize?: number;
79
73
  /** 同时执行的批次数量, 默认 3 */