antd-import-export 1.0.12 → 1.0.13

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.
Files changed (65) hide show
  1. package/README.md +125 -23
  2. package/README_EN.md +125 -23
  3. package/dist/components/EditableImportCell.d.cts +12 -0
  4. package/dist/components/EditableImportCell.d.ts +2 -2
  5. package/dist/components/ExportButton.d.cts +20 -0
  6. package/dist/components/ExportButton.d.ts +2 -2
  7. package/dist/components/ExportTaskModal.d.cts +7 -0
  8. package/dist/components/ImportButton.d.cts +25 -0
  9. package/dist/components/ImportButton.d.ts +6 -6
  10. package/dist/components/ImportCheckContent.d.cts +10 -0
  11. package/dist/components/ImportPreviewModal.d.cts +19 -0
  12. package/dist/components/ImportPreviewModal.d.ts +2 -2
  13. package/dist/components/importBatchResult.d.cts +7 -0
  14. package/dist/components/importBatchResult.d.ts +4 -6
  15. package/dist/components/importPreviewStatus.d.cts +20 -0
  16. package/dist/components/importPreviewStatus.d.ts +2 -2
  17. package/dist/core/dateTime.d.cts +56 -0
  18. package/dist/core/dateTime.d.ts +56 -0
  19. package/dist/core/excel/exportFile.d.cts +14 -0
  20. package/dist/core/excel/exportFile.d.ts +1 -1
  21. package/dist/core/excel/importEditor.d.cts +7 -0
  22. package/dist/core/excel/importEditor.d.ts +2 -2
  23. package/dist/core/excel/importRow.d.cts +28 -0
  24. package/dist/core/excel/importRow.d.ts +13 -10
  25. package/dist/core/excel/parseSheet.d.cts +31 -0
  26. package/dist/core/excel/parseSheet.d.ts +18 -5
  27. package/dist/core/excel/runtime.d.cts +18 -0
  28. package/dist/core/excel/runtime.d.ts +8 -3
  29. package/dist/core/excel/worksheet.d.cts +8 -0
  30. package/dist/core/excel/worksheet.d.ts +2 -7
  31. package/dist/core/httpError.d.cts +34 -0
  32. package/dist/core/limits.d.cts +2 -0
  33. package/dist/core/schema/defaultValue.d.cts +17 -0
  34. package/dist/core/schema/defaultValue.d.ts +17 -0
  35. package/dist/core/schema/index.d.cts +91 -0
  36. package/dist/core/schema/index.d.ts +4 -1
  37. package/dist/core/schema/multiValue.d.cts +4 -0
  38. package/dist/core/schema/optionMap.d.cts +10 -0
  39. package/dist/core/schema/optionMap.d.ts +10 -0
  40. package/dist/core/schema/validate.d.cts +21 -0
  41. package/dist/core/schema/validate.d.ts +2 -2
  42. package/dist/core/task/exportRunner.d.cts +4 -0
  43. package/dist/core/task/exportRunner.d.ts +1 -1
  44. package/dist/core/task/importRunner.d.cts +21 -0
  45. package/dist/core/task/importRunner.d.ts +4 -4
  46. package/dist/core/task/index.d.cts +12 -0
  47. package/dist/core/task/index.d.ts +6 -6
  48. package/dist/core/task/stats.d.cts +16 -0
  49. package/dist/core/task/stats.d.ts +3 -3
  50. package/dist/core/task/store.d.cts +17 -0
  51. package/dist/core/task/store.d.ts +1 -1
  52. package/dist/core/task/types.d.cts +106 -0
  53. package/dist/core/task/types.d.ts +10 -5
  54. package/dist/core/types.d.cts +16 -0
  55. package/dist/index.cjs +9 -6
  56. package/dist/index.d.cts +15 -0
  57. package/dist/index.d.ts +15 -14
  58. package/dist/index.mjs +1122 -1012
  59. package/dist/react/useActiveTask.d.cts +5 -0
  60. package/dist/react/useActiveTask.d.ts +1 -1
  61. package/dist/react/useDebouncedValue.d.cts +2 -0
  62. package/dist/react/useTaskDetail.d.cts +2 -0
  63. package/dist/react/useTaskDetail.d.ts +1 -1
  64. package/dist/react/useThrottledValue.d.cts +2 -0
  65. package/package.json +18 -8
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
- import type { ImportRow } from "../core/excel/importRow";
3
- import type { FieldSchema } from "../core/schema";
2
+ import type { ImportRow } from "../core/excel/importRow.js";
3
+ import type { FieldSchema } from "../core/schema/index.js";
4
4
  interface ImportPreviewModalProps {
5
5
  open: boolean;
6
6
  title: string;
@@ -0,0 +1,7 @@
1
+ import type { ImportRowErrorBody, ImportRowResult } from "../core/types.cjs";
2
+ /**
3
+ * 把接口返回的单行错误体转成任务行结果。
4
+ * 错误体 key 在 FieldSchema 中 = 字段错误; 不在 = 整行错误(消息保留 key, 便于排查)。
5
+ * 不依赖 detail / non_field_errors 等具体后端约定, 任意后端在 importRows 里转换成这个形状即可。
6
+ */
7
+ export declare function parseImportBatchResult(result: ImportRowErrorBody, fieldKeys: ReadonlySet<string>): ImportRowResult;
@@ -1,9 +1,7 @@
1
- import type { ImportRowErrorBody, ImportRowResult } from "../core/types";
2
- /** DRF 的列表类型技术错误对用户没有意义, 统一成可读提示 */
3
- export declare function normalizeImportErrorMessage(message: string): string;
1
+ import type { ImportRowErrorBody, ImportRowResult } from "../core/types.js";
4
2
  /**
5
3
  * 把接口返回的单行错误体转成任务行结果。
6
- * 只有 fieldKeys 里的键才按字段级错误处理; 其余键(后端新增字段、关联对象错误等)
7
- * 在预览表格里没有对应单元格, 统一并入整体错误, 避免错误被静默吞掉。
4
+ * 错误体 key 在 FieldSchema 中 = 字段错误; 不在 = 整行错误(消息保留 key, 便于排查)。
5
+ * 不依赖 detail / non_field_errors 等具体后端约定, 任意后端在 importRows 里转换成这个形状即可。
8
6
  */
9
- export declare function parseImportBatchResult(result: ImportRowErrorBody, fieldKeys: Set<string>): ImportRowResult;
7
+ export declare function parseImportBatchResult(result: ImportRowErrorBody, fieldKeys: ReadonlySet<string>): ImportRowResult;
@@ -0,0 +1,20 @@
1
+ import type { ImportRow } from "../core/excel/importRow.cjs";
2
+ import type { TaskItem } from "../core/task/index.cjs";
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,5 +1,5 @@
1
- import type { ImportRow } from "../core/excel/importRow";
2
- import type { TaskItem } from "../core/task";
1
+ import type { ImportRow } from "../core/excel/importRow.js";
2
+ import type { TaskItem } from "../core/task/index.js";
3
3
  export type DataStatusKey = "valid" | "invalid";
4
4
  export type ImportStatusKey = "pending" | "running" | "completed" | "failed" | "canceled";
5
5
  export declare function getTaskMeta(task: TaskItem): {
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 日期与时间的唯一实现: 输入解析、真实日期校验、规范化输出、ExcelJS Date 转换与导出展示都在这里。
3
+ * 校验(validate)、导入解析(parseSheet)、导出展示(worksheet)必须复用本模块, 不要另写格式化规则。
4
+ *
5
+ * 约定:
6
+ * - date: 严格 YYYY-MM-DD (4-2-2), 且必须是真实存在的日期
7
+ * - time: H:mm / HH:mm / H:mm:ss / HH:mm:ss, 小时可 1 位, 分秒必须 2 位
8
+ * - datetime: YYYY-MM-DD 后接空白和 time
9
+ * - 输出统一补零; 秒为 0 时不带秒
10
+ * - ExcelJS 的日期单元格按 UTC 还原; 导出侧的 Date 也按 UTC 解释, 保证导入导出与浏览器时区无关
11
+ */
12
+ export interface DateParts {
13
+ year: number;
14
+ month: number;
15
+ day: number;
16
+ }
17
+ export interface TimeParts {
18
+ hour: number;
19
+ minute: number;
20
+ second: number;
21
+ }
22
+ /** 两位补零: 日期/时间的年月日时分秒在拼文本时都必须补齐 */
23
+ export declare function pad2(value: number): string;
24
+ /** 解析日期文本; 非法或非字符串返回 null。只接受 4-2-2 且真实存在的日期 */
25
+ export declare function parseDateText(text: unknown): DateParts | null;
26
+ /** 解析时间文本; 非法或非字符串返回 null。小时可 1 位, 分秒必须 2 位, 缺秒按 0 处理 */
27
+ export declare function parseTimeText(text: unknown): TimeParts | null;
28
+ /** 解析日期时间文本; 日期与时间之间允许任意空白, 非法或非字符串返回 null */
29
+ export declare function parseDateTimeText(text: unknown): {
30
+ date: DateParts;
31
+ time: TimeParts;
32
+ } | null;
33
+ export declare function formatDateParts({ year, month, day }: DateParts): string;
34
+ /** 时间统一补零; 秒为 0 时不带秒 */
35
+ export declare function formatTimeParts({ hour, minute, second }: TimeParts): string;
36
+ export declare function formatDateTimeParts(date: DateParts, time: TimeParts): string;
37
+ /** ExcelJS 的日期单元格按 UTC 还原, 这里使用 UTC getter 与之保持一致 */
38
+ export declare function datePartsFromDate(date: Date): DateParts;
39
+ export declare function timePartsFromDate(date: Date): TimeParts;
40
+ export declare function formatDateFromDate(date: Date): string;
41
+ export declare function formatTimeFromDate(date: Date): string;
42
+ export declare function formatDateTimeFromDate(date: Date): string;
43
+ /**
44
+ * Excel 日期序列号(1900 系统) 转 Date; 只在日期/时间字段上使用。
45
+ * 25569 是 1970-01-01 的 Excel 序列号; ExcelJS 也按 UTC 还原日期。
46
+ */
47
+ export declare function excelSerialToDate(serial: number): Date | null;
48
+ /** 导出展示: 接口值 -> date 文本; 无法识别返回 null, 由调用方原样输出 */
49
+ export declare function normalizeExportDate(value: unknown): string | null;
50
+ /** 导出展示: 接口值 -> time 文本; 无法识别返回 null, 由调用方原样输出 */
51
+ export declare function normalizeExportTime(value: unknown): string | null;
52
+ /**
53
+ * 导出展示: 接口值 -> datetime 文本; 无法识别返回 null, 由调用方原样输出。
54
+ * 纯日期字符串按当天 00:00 展示, 与历史行为一致。
55
+ */
56
+ export declare function normalizeExportDateTime(value: unknown): string | null;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 日期与时间的唯一实现: 输入解析、真实日期校验、规范化输出、ExcelJS Date 转换与导出展示都在这里。
3
+ * 校验(validate)、导入解析(parseSheet)、导出展示(worksheet)必须复用本模块, 不要另写格式化规则。
4
+ *
5
+ * 约定:
6
+ * - date: 严格 YYYY-MM-DD (4-2-2), 且必须是真实存在的日期
7
+ * - time: H:mm / HH:mm / H:mm:ss / HH:mm:ss, 小时可 1 位, 分秒必须 2 位
8
+ * - datetime: YYYY-MM-DD 后接空白和 time
9
+ * - 输出统一补零; 秒为 0 时不带秒
10
+ * - ExcelJS 的日期单元格按 UTC 还原; 导出侧的 Date 也按 UTC 解释, 保证导入导出与浏览器时区无关
11
+ */
12
+ export interface DateParts {
13
+ year: number;
14
+ month: number;
15
+ day: number;
16
+ }
17
+ export interface TimeParts {
18
+ hour: number;
19
+ minute: number;
20
+ second: number;
21
+ }
22
+ /** 两位补零: 日期/时间的年月日时分秒在拼文本时都必须补齐 */
23
+ export declare function pad2(value: number): string;
24
+ /** 解析日期文本; 非法或非字符串返回 null。只接受 4-2-2 且真实存在的日期 */
25
+ export declare function parseDateText(text: unknown): DateParts | null;
26
+ /** 解析时间文本; 非法或非字符串返回 null。小时可 1 位, 分秒必须 2 位, 缺秒按 0 处理 */
27
+ export declare function parseTimeText(text: unknown): TimeParts | null;
28
+ /** 解析日期时间文本; 日期与时间之间允许任意空白, 非法或非字符串返回 null */
29
+ export declare function parseDateTimeText(text: unknown): {
30
+ date: DateParts;
31
+ time: TimeParts;
32
+ } | null;
33
+ export declare function formatDateParts({ year, month, day }: DateParts): string;
34
+ /** 时间统一补零; 秒为 0 时不带秒 */
35
+ export declare function formatTimeParts({ hour, minute, second }: TimeParts): string;
36
+ export declare function formatDateTimeParts(date: DateParts, time: TimeParts): string;
37
+ /** ExcelJS 的日期单元格按 UTC 还原, 这里使用 UTC getter 与之保持一致 */
38
+ export declare function datePartsFromDate(date: Date): DateParts;
39
+ export declare function timePartsFromDate(date: Date): TimeParts;
40
+ export declare function formatDateFromDate(date: Date): string;
41
+ export declare function formatTimeFromDate(date: Date): string;
42
+ export declare function formatDateTimeFromDate(date: Date): string;
43
+ /**
44
+ * Excel 日期序列号(1900 系统) 转 Date; 只在日期/时间字段上使用。
45
+ * 25569 是 1970-01-01 的 Excel 序列号; ExcelJS 也按 UTC 还原日期。
46
+ */
47
+ export declare function excelSerialToDate(serial: number): Date | null;
48
+ /** 导出展示: 接口值 -> date 文本; 无法识别返回 null, 由调用方原样输出 */
49
+ export declare function normalizeExportDate(value: unknown): string | null;
50
+ /** 导出展示: 接口值 -> time 文本; 无法识别返回 null, 由调用方原样输出 */
51
+ export declare function normalizeExportTime(value: unknown): string | null;
52
+ /**
53
+ * 导出展示: 接口值 -> datetime 文本; 无法识别返回 null, 由调用方原样输出。
54
+ * 纯日期字符串按当天 00:00 展示, 与历史行为一致。
55
+ */
56
+ export declare function normalizeExportDateTime(value: unknown): string | null;
@@ -0,0 +1,14 @@
1
+ import type { FieldSchema } from "../schema/index.cjs";
2
+ /** 生成 `标题_20261123153300` 形式的文件名(不含扩展名) */
3
+ export declare function makeExportFileName(title: string): string;
4
+ export interface ExportRowsToFileOptions {
5
+ title: string;
6
+ fieldSchemas: FieldSchema[];
7
+ rows: object[];
8
+ }
9
+ /**
10
+ * 导出内存中的一批行: 按约定生成文件名并下载。
11
+ * 只负责数据到文件, 不弹提示也不管理 loading;
12
+ * 没有数据时抛出可直接展示的错误, 由调用方决定如何反馈。
13
+ */
14
+ export declare function exportRowsToFile(options: ExportRowsToFileOptions): Promise<void>;
@@ -1,4 +1,4 @@
1
- import type { FieldSchema } from "../schema";
1
+ import type { FieldSchema } from "../schema/index.js";
2
2
  /** 生成 `标题_20261123153300` 形式的文件名(不含扩展名) */
3
3
  export declare function makeExportFileName(title: string): string;
4
4
  export interface ExportRowsToFileOptions {
@@ -0,0 +1,7 @@
1
+ import type { FieldSchema } from "../schema/index.cjs";
2
+ /** 接口值 -> 表格/表单里的展示值 */
3
+ export declare function toEditorValue(field: FieldSchema, value: unknown): string | (string | undefined)[] | undefined;
4
+ /** 原始单元格文本 -> 编辑器值; 只用于校验失败、尚未规范化的字段 */
5
+ export declare function toRawEditorValue(field: FieldSchema, value: string | null): string | string[];
6
+ /** 表格/表单里的展示值 -> 交给 validateField 的文本 */
7
+ export declare function toEditorText(field: FieldSchema, value: unknown): string;
@@ -1,6 +1,6 @@
1
- import type { FieldSchema } from "../schema";
1
+ import type { FieldSchema } from "../schema/index.js";
2
2
  /** 接口值 -> 表格/表单里的展示值 */
3
- export declare function toEditorValue(field: FieldSchema, value: unknown): string | number | (string | undefined)[] | undefined;
3
+ export declare function toEditorValue(field: FieldSchema, value: unknown): string | (string | undefined)[] | undefined;
4
4
  /** 原始单元格文本 -> 编辑器值; 只用于校验失败、尚未规范化的字段 */
5
5
  export declare function toRawEditorValue(field: FieldSchema, value: string | null): string | string[];
6
6
  /** 表格/表单里的展示值 -> 交给 validateField 的文本 */
@@ -0,0 +1,28 @@
1
+ import type { FieldSchema } from "../schema/index.cjs";
2
+ /**
3
+ * 导入行唯一数据源: values 保存用户在表格里看到/编辑的值, errors 保存当前校验错误.
4
+ * 提交给接口的 payload 在真正导入时由 values 派生, 不再另外维护一份 payload.
5
+ */
6
+ export interface ImportRow {
7
+ key: string;
8
+ rowNumber: number;
9
+ values: Record<string, unknown>;
10
+ errors: Record<string, string>;
11
+ taskIndex?: number;
12
+ }
13
+ /**
14
+ * 校验模式:
15
+ * - parse: 输入是 Excel 单元格文本, 失败时转成编辑器值保留原始输入
16
+ * - editor: 输入/输出都是编辑器值
17
+ * - payload: 输出接口值, 任一字段失败直接抛错
18
+ */
19
+ export type ImportValueMode = "parse" | "editor" | "payload";
20
+ interface ValidateImportValuesResult {
21
+ values: Record<string, unknown>;
22
+ errors: Record<string, string>;
23
+ }
24
+ /** 导入链路唯一的字段校验入口: 缺列跳过、空值取默认值、校验并转换 */
25
+ export declare function validateImportValues(values: Record<string, unknown>, fieldSchemas: FieldSchema[], includedKeys: string[], mode: ImportValueMode): ValidateImportValuesResult;
26
+ /** 从唯一数据源生成接口 payload; 缺列字段跳过, 保持"不修改"语义 */
27
+ export declare function buildImportPayload(row: ImportRow, fieldSchemas: FieldSchema[], includedKeys: string[]): Record<string, unknown>;
28
+ export {};
@@ -1,4 +1,4 @@
1
- import type { FieldSchema } from "../schema";
1
+ import type { FieldSchema } from "../schema/index.js";
2
2
  /**
3
3
  * 导入行唯一数据源: values 保存用户在表格里看到/编辑的值, errors 保存当前校验错误.
4
4
  * 提交给接口的 payload 在真正导入时由 values 派生, 不再另外维护一份 payload.
@@ -10,16 +10,19 @@ export interface ImportRow {
10
10
  errors: Record<string, string>;
11
11
  taskIndex?: number;
12
12
  }
13
- /** 从唯一数据源生成接口 payload; 缺列字段跳过, 保持"不修改"语义 */
14
- export declare function buildImportPayload(row: ImportRow, fieldSchemas: FieldSchema[], includedKeys: string[]): Record<string, unknown>;
15
13
  /**
16
- * 重新校验一批行, 供 beforeImport 返回加工后的数据时使用:
17
- * values 会按字段规则规范化, errors 与之一致, 不会残留加工前的旧错误.
14
+ * 校验模式:
15
+ * - parse: 输入是 Excel 单元格文本, 失败时转成编辑器值保留原始输入
16
+ * - editor: 输入/输出都是编辑器值
17
+ * - payload: 输出接口值, 任一字段失败直接抛错
18
18
  */
19
- export declare function revalidateImportRows(rows: ImportRow[], fieldSchemas: FieldSchema[], includedKeys: string[]): {
20
- key: string;
19
+ export type ImportValueMode = "parse" | "editor" | "payload";
20
+ interface ValidateImportValuesResult {
21
21
  values: Record<string, unknown>;
22
22
  errors: Record<string, string>;
23
- rowNumber: number;
24
- taskIndex?: number;
25
- }[];
23
+ }
24
+ /** 导入链路唯一的字段校验入口: 缺列跳过、空值取默认值、校验并转换 */
25
+ export declare function validateImportValues(values: Record<string, unknown>, fieldSchemas: FieldSchema[], includedKeys: string[], mode: ImportValueMode): ValidateImportValuesResult;
26
+ /** 从唯一数据源生成接口 payload; 缺列字段跳过, 保持"不修改"语义 */
27
+ export declare function buildImportPayload(row: ImportRow, fieldSchemas: FieldSchema[], includedKeys: string[]): Record<string, unknown>;
28
+ export {};
@@ -0,0 +1,31 @@
1
+ import type ExcelJS from "exceljs";
2
+ import type { FieldSchema } from "../schema/index.cjs";
3
+ import type { ImportRow } from "./importRow.cjs";
4
+ /** ExcelJS 的动态加载方从已加载的模块传入, 避免静态 import 进主包 */
5
+ type ExcelValueType = (typeof import("exceljs"))["ValueType"];
6
+ export interface UnknownColumn {
7
+ /** Excel 列字母, 如 A/B/AA */
8
+ column: string;
9
+ /** 表头第一行文本 */
10
+ title: string;
11
+ }
12
+ export interface ImportParseResult {
13
+ /** 文件级问题: 多个工作表、没有工作表等, 出现即整份文件不可导入 */
14
+ headerMessages: string[];
15
+ /** 缺少的必填列表头 */
16
+ missingColumns: string[];
17
+ /** 公式没有缓存结果: 无法取值, 需要用户用 Excel 打开并保存 */
18
+ formulaMessages: string[];
19
+ /** 表头存在但不在字段定义里的列; 出现即整份文件不可导入 */
20
+ unknownColumns: UnknownColumn[];
21
+ /** 解析后的唯一数据源;表格编辑、提交 payload、任务快照都使用这一份 */
22
+ rows: ImportRow[];
23
+ /**
24
+ * 文件里实际存在的列(fieldSchemas.key)。
25
+ * 未包含的列不会提交给后端; 更新时表示不修改该字段, 预览里也不展示该列。
26
+ */
27
+ includedKeys: string[];
28
+ }
29
+ /** 解析并校验一张工作表: 表头错整份拒绝, 行错写进对应行的 errors */
30
+ export declare function parseWorksheet(worksheet: ExcelJS.Worksheet, fieldSchemas: FieldSchema[], valueType: ExcelValueType): ImportParseResult;
31
+ export {};
@@ -1,11 +1,23 @@
1
- import ExcelJS from "exceljs";
2
- import type { FieldSchema } from "../schema";
3
- import type { ImportRow } from "./importRow";
1
+ import type ExcelJS from "exceljs";
2
+ import type { FieldSchema } from "../schema/index.js";
3
+ import type { ImportRow } from "./importRow.js";
4
+ /** ExcelJS 的动态加载方从已加载的模块传入, 避免静态 import 进主包 */
5
+ type ExcelValueType = (typeof import("exceljs"))["ValueType"];
6
+ export interface UnknownColumn {
7
+ /** Excel 列字母, 如 A/B/AA */
8
+ column: string;
9
+ /** 表头第一行文本 */
10
+ title: string;
11
+ }
4
12
  export interface ImportParseResult {
5
- /** 表头级问题: 缺必填列等, 出现即整份文件不可导入 */
13
+ /** 文件级问题: 多个工作表、没有工作表等, 出现即整份文件不可导入 */
6
14
  headerMessages: string[];
15
+ /** 缺少的必填列表头 */
16
+ missingColumns: string[];
7
17
  /** 公式没有缓存结果: 无法取值, 需要用户用 Excel 打开并保存 */
8
18
  formulaMessages: string[];
19
+ /** 表头存在但不在字段定义里的列; 出现即整份文件不可导入 */
20
+ unknownColumns: UnknownColumn[];
9
21
  /** 解析后的唯一数据源;表格编辑、提交 payload、任务快照都使用这一份 */
10
22
  rows: ImportRow[];
11
23
  /**
@@ -15,4 +27,5 @@ export interface ImportParseResult {
15
27
  includedKeys: string[];
16
28
  }
17
29
  /** 解析并校验一张工作表: 表头错整份拒绝, 行错写进对应行的 errors */
18
- export declare function parseWorksheet(worksheet: ExcelJS.Worksheet, fieldSchemas: FieldSchema[]): ImportParseResult;
30
+ export declare function parseWorksheet(worksheet: ExcelJS.Worksheet, fieldSchemas: FieldSchema[], valueType: ExcelValueType): ImportParseResult;
31
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { FieldSchema } from "../schema/index.cjs";
2
+ import type { ImportParseResult } from "./parseSheet.cjs";
3
+ /** 统一按 .xlsx 下载; 文件名由调用方拼好 */
4
+ export declare function saveWorkbook(blob: Blob, fileName: string): void;
5
+ /**
6
+ * 让浏览器先渲染一帧再开始同步计算。
7
+ * ExcelJS 的 xlsx.load / writeBuffer 内部整段同步执行, 没有让出的机会,
8
+ * 不先等一下, 调用方设置的 loading 状态要等计算结束才会显示出来。
9
+ */
10
+ export declare function nextPaint(): Promise<void>;
11
+ /** 导出: 生成 xlsx 内容, 由调用方决定何时下载 */
12
+ export declare function buildExportBlob(data: object[], fieldSchemas: FieldSchema[], signal?: AbortSignal): Promise<Blob>;
13
+ /** 导出: 把列表数据渲染成 Excel 并下载 */
14
+ export declare function exportExcel(data: object[], fieldSchemas: FieldSchema[], fileName: string): Promise<void>;
15
+ /** 导入模板: 列名与填写要求写在表头单元格里, 不写示例行 */
16
+ export declare function downloadImportTemplate(fieldSchemas: FieldSchema[], fileName: string): Promise<void>;
17
+ /** 导入: 解析并按字段定义校验 Excel, 返回可提交的数据与逐行问题 */
18
+ export declare function parseImportFile(file: File, fieldSchemas: FieldSchema[]): Promise<ImportParseResult>;
@@ -1,8 +1,13 @@
1
- import type { FieldSchema } from "../schema";
2
- import type { ImportParseResult } from "./parseSheet";
3
- export { autoAdjustColumnWidths } from "./worksheet";
1
+ import type { FieldSchema } from "../schema/index.js";
2
+ import type { ImportParseResult } from "./parseSheet.js";
4
3
  /** 统一按 .xlsx 下载; 文件名由调用方拼好 */
5
4
  export declare function saveWorkbook(blob: Blob, fileName: string): void;
5
+ /**
6
+ * 让浏览器先渲染一帧再开始同步计算。
7
+ * ExcelJS 的 xlsx.load / writeBuffer 内部整段同步执行, 没有让出的机会,
8
+ * 不先等一下, 调用方设置的 loading 状态要等计算结束才会显示出来。
9
+ */
10
+ export declare function nextPaint(): Promise<void>;
6
11
  /** 导出: 生成 xlsx 内容, 由调用方决定何时下载 */
7
12
  export declare function buildExportBlob(data: object[], fieldSchemas: FieldSchema[], signal?: AbortSignal): Promise<Blob>;
8
13
  /** 导出: 把列表数据渲染成 Excel 并下载 */
@@ -0,0 +1,8 @@
1
+ import type ExcelJS from "exceljs";
2
+ import type { FieldSchema } from "../schema/index.cjs";
3
+ /** 按 fieldSchemas 写表头与数据行: 列序 = 定义顺序, 不写任何隐藏列 */
4
+ export declare function writeExportSheet(worksheet: ExcelJS.Worksheet, data: Record<string, unknown>[], fieldSchemas: FieldSchema[]): void;
5
+ /** 按 fieldSchemas 写导入模板: 列名 + 每列的填写要求写在同一个表头单元格里, 不写示例行 */
6
+ export declare function writeImportTemplateSheet(worksheet: ExcelJS.Worksheet, fieldSchemas: FieldSchema[]): void;
7
+ /** 自动调整列宽(支持多行文本) */
8
+ export declare function autoAdjustColumnWidths(worksheet: ExcelJS.Worksheet, minWidth?: number, maxWidth?: number): void;
@@ -1,13 +1,8 @@
1
1
  import type ExcelJS from "exceljs";
2
- import type { FieldSchema } from "../schema";
2
+ import type { FieldSchema } from "../schema/index.js";
3
3
  /** 按 fieldSchemas 写表头与数据行: 列序 = 定义顺序, 不写任何隐藏列 */
4
4
  export declare function writeExportSheet(worksheet: ExcelJS.Worksheet, data: Record<string, unknown>[], fieldSchemas: FieldSchema[]): void;
5
5
  /** 按 fieldSchemas 写导入模板: 列名 + 每列的填写要求写在同一个表头单元格里, 不写示例行 */
6
6
  export declare function writeImportTemplateSheet(worksheet: ExcelJS.Worksheet, fieldSchemas: FieldSchema[]): void;
7
- /**
8
- * 自动调整列宽(支持多行文本)
9
- * @param worksheet Excel 工作表
10
- * @param minWidth 最小列宽, 默认 20
11
- * @param maxWidth 最大列宽, 默认 60
12
- */
7
+ /** 自动调整列宽(支持多行文本) */
13
8
  export declare function autoAdjustColumnWidths(worksheet: ExcelJS.Worksheet, minWidth?: number, maxWidth?: number): void;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * HTTP 错误的最小形状, 不绑定具体请求库:
3
+ * - axios / 多数 fetch 封装: `response.status` + `response.data`
4
+ * - 直接抛出的自定义错误: `status` / `statusCode` + `data`
5
+ * 认不出的错误由调用方按普通异常处理。
6
+ */
7
+ export interface HttpErrorShape {
8
+ isAxiosError?: boolean;
9
+ response?: {
10
+ status?: number;
11
+ data?: unknown;
12
+ };
13
+ status?: number;
14
+ statusCode?: number;
15
+ data?: unknown;
16
+ }
17
+ /** HTTP 失败的大类; 具体文案由调用方决定 */
18
+ export type HttpFailureKind = "network" | "unauthorized" | "forbidden" | "notFound" | "badRequest" | "server" | "unknown";
19
+ /** 是否像一次 HTTP 请求失败: 带状态码, 或请求库明确标记过 */
20
+ export declare function isHttpError(error: unknown): error is HttpErrorShape;
21
+ /** 取 HTTP 状态码; 网络中断这类没有响应的错误返回 undefined */
22
+ export declare function httpStatusOf(error: unknown): number | undefined;
23
+ /** 取响应体, 用于展示后端返回的具体错误 */
24
+ export declare function httpResponseData(error: unknown): unknown;
25
+ /**
26
+ * 把错误归成 HTTP 大类, 供各调用方拼自己的文案。
27
+ * 返回 undefined 表示不是 HTTP 失败, 调用方应按普通异常处理。
28
+ */
29
+ export declare function classifyHttpFailure(error: unknown): HttpFailureKind | undefined;
30
+ /**
31
+ * HTTP 失败的提示文案; 不是 HTTP 失败时返回 undefined, 由调用方兜底。
32
+ * `direction` 用于区分导入/导出, `tail` 是业务侧的动作说明。
33
+ */
34
+ export declare function describeHttpFailure(error: unknown, direction: "导入" | "导出", tail: string): string | undefined;
@@ -0,0 +1,2 @@
1
+ /** 单个导入文件大小上限 */
2
+ export declare const MAX_IMPORT_FILE_SIZE: number;
@@ -0,0 +1,17 @@
1
+ import type { FieldSchema } from "./index.cjs";
2
+ interface DefaultTextResult {
3
+ /** 交给 validateField 的文本; null 表示没有默认值或默认值为空 */
4
+ text: string | null;
5
+ /** 默认值本身不合法时的可读错误 */
6
+ error?: string;
7
+ }
8
+ /**
9
+ * 默认值统一使用接口值:
10
+ * - boolean 是 true/false, 展示时才换成 true_label/false_label
11
+ * - choice 是 option_map 的 key(接口内部值), 这里用 key 查成选项文案, 以便复用文本校验
12
+ * - list 是 string[]
13
+ *
14
+ * 返回的 text 可以直接交给 validateField, 由它完成类型校验和规范化.
15
+ */
16
+ export declare function resolveDefaultText(field: FieldSchema): DefaultTextResult;
17
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { FieldSchema } from "./index.js";
2
+ interface DefaultTextResult {
3
+ /** 交给 validateField 的文本; null 表示没有默认值或默认值为空 */
4
+ text: string | null;
5
+ /** 默认值本身不合法时的可读错误 */
6
+ error?: string;
7
+ }
8
+ /**
9
+ * 默认值统一使用接口值:
10
+ * - boolean 是 true/false, 展示时才换成 true_label/false_label
11
+ * - choice 是 option_map 的 key(接口内部值), 这里用 key 查成选项文案, 以便复用文本校验
12
+ * - list 是 string[]
13
+ *
14
+ * 返回的 text 可以直接交给 validateField, 由它完成类型校验和规范化.
15
+ */
16
+ export declare function resolveDefaultText(field: FieldSchema): DefaultTextResult;
17
+ export {};
@@ -0,0 +1,91 @@
1
+ /** 字段定义的公共部分 */
2
+ interface FieldSchemaBase {
3
+ key: string;
4
+ title: string;
5
+ /** 是否参与导入(模板与解析): 导出固定用全部列, 标记为 false 的列只出现在导出里 */
6
+ importable?: boolean;
7
+ }
8
+ export interface TextFieldSchema extends FieldSchemaBase {
9
+ type: "text";
10
+ property: {
11
+ required: boolean;
12
+ max_length: number;
13
+ default_value?: string | null;
14
+ };
15
+ }
16
+ export interface NumberFieldSchema extends FieldSchemaBase {
17
+ type: "number";
18
+ property: {
19
+ required: boolean;
20
+ precision: number;
21
+ /** 总位数上限, 对应数据库 DecimalField.max_digits */
22
+ max_digits?: number;
23
+ min_value?: number;
24
+ max_value?: number;
25
+ /** 数字字段的接口值是精确十进制字符串, 默认值可以用 number 或同样的字符串 */
26
+ default_value?: number | string | null;
27
+ };
28
+ }
29
+ export interface BooleanFieldSchema extends FieldSchemaBase {
30
+ type: "boolean";
31
+ property: {
32
+ required: boolean;
33
+ true_label: string;
34
+ false_label: string;
35
+ default_value?: boolean | null;
36
+ };
37
+ }
38
+ export interface DateFieldSchema extends FieldSchemaBase {
39
+ type: "date";
40
+ property: {
41
+ required: boolean;
42
+ default_value?: string | null;
43
+ };
44
+ }
45
+ export interface TimeFieldSchema extends FieldSchemaBase {
46
+ type: "time";
47
+ property: {
48
+ required: boolean;
49
+ default_value?: string | null;
50
+ };
51
+ }
52
+ export interface DateTimeFieldSchema extends FieldSchemaBase {
53
+ type: "datetime";
54
+ property: {
55
+ required: boolean;
56
+ default_value?: string | null;
57
+ };
58
+ }
59
+ export interface ListFieldSchema extends FieldSchemaBase {
60
+ type: "list";
61
+ property: {
62
+ required: boolean;
63
+ list_max_length: number;
64
+ text_max_length: number;
65
+ /** 数组元素是对象时, 取该键的值拼成文本(导出展示用) */
66
+ item_key?: string;
67
+ default_value?: string[] | [];
68
+ };
69
+ }
70
+ export interface SingleChoiceFieldSchema extends FieldSchemaBase {
71
+ type: "single_choice";
72
+ property: {
73
+ required: boolean;
74
+ /** key 是接口内部值(必须唯一), value 是 Excel/界面展示文案(也必须唯一) */
75
+ option_map: Record<string, string>;
76
+ default_value?: string | null;
77
+ };
78
+ }
79
+ export interface MultipleChoiceFieldSchema extends FieldSchemaBase {
80
+ type: "multiple_choice";
81
+ property: {
82
+ required: boolean;
83
+ /** key 是接口内部值(必须唯一), value 是 Excel/界面展示文案(也必须唯一) */
84
+ option_map: Record<string, string>;
85
+ default_value?: string[] | [];
86
+ };
87
+ }
88
+ export type FieldSchema = TextFieldSchema | NumberFieldSchema | BooleanFieldSchema | DateFieldSchema | TimeFieldSchema | DateTimeFieldSchema | ListFieldSchema | SingleChoiceFieldSchema | MultipleChoiceFieldSchema;
89
+ /** 导入模板与解析用: 去掉只供导出的列 */
90
+ export declare function importableFields(fieldSchemas: FieldSchema[]): FieldSchema[];
91
+ export {};
@@ -22,7 +22,8 @@ export interface NumberFieldSchema extends FieldSchemaBase {
22
22
  max_digits?: number;
23
23
  min_value?: number;
24
24
  max_value?: number;
25
- default_value?: number | null;
25
+ /** 数字字段的接口值是精确十进制字符串, 默认值可以用 number 或同样的字符串 */
26
+ default_value?: number | string | null;
26
27
  };
27
28
  }
28
29
  export interface BooleanFieldSchema extends FieldSchemaBase {
@@ -70,6 +71,7 @@ export interface SingleChoiceFieldSchema extends FieldSchemaBase {
70
71
  type: "single_choice";
71
72
  property: {
72
73
  required: boolean;
74
+ /** key 是接口内部值(必须唯一), value 是 Excel/界面展示文案(也必须唯一) */
73
75
  option_map: Record<string, string>;
74
76
  default_value?: string | null;
75
77
  };
@@ -78,6 +80,7 @@ export interface MultipleChoiceFieldSchema extends FieldSchemaBase {
78
80
  type: "multiple_choice";
79
81
  property: {
80
82
  required: boolean;
83
+ /** key 是接口内部值(必须唯一), value 是 Excel/界面展示文案(也必须唯一) */
81
84
  option_map: Record<string, string>;
82
85
  default_value?: string[] | [];
83
86
  };
@@ -0,0 +1,4 @@
1
+ /** 导出统一用英文分号; 导入兼容中英文分号 */
2
+ export declare const MULTI_VALUE_SEPARATOR = ";";
3
+ export declare function joinMultiValues(values: unknown[]): string;
4
+ export declare function splitMultiValues(value: string): string[];
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 选项映射方向: **key = 接口内部值(唯一), value = Excel/界面展示文案**。
3
+ * 两个方向的查找集中在这里, 避免各模块各写一套反查逻辑。
4
+ */
5
+ /** 接口内部值 -> 展示文案; 未命中返回 undefined */
6
+ export declare function optionLabelOf(optionMap: Record<string, string>, value: unknown): string | undefined;
7
+ /** 展示文案 -> 接口内部值; 文案重复时取对象属性顺序里的第一个(配置应保证文案唯一) */
8
+ export declare function optionValueOf(optionMap: Record<string, string>, label: string): string | undefined;
9
+ /** 展示文案列表(按对象属性顺序; 整数形 key 会按数值升序) */
10
+ export declare function optionLabels(optionMap: Record<string, string>): string[];