antd-import-export 0.0.0-stage → 1.0.0

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.
@@ -0,0 +1,88 @@
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
+ default_value?: number | null;
26
+ };
27
+ }
28
+ export interface BooleanFieldSchema extends FieldSchemaBase {
29
+ type: "boolean";
30
+ property: {
31
+ required: boolean;
32
+ true_label: string;
33
+ false_label: string;
34
+ default_value?: boolean | null;
35
+ };
36
+ }
37
+ export interface DateFieldSchema extends FieldSchemaBase {
38
+ type: "date";
39
+ property: {
40
+ required: boolean;
41
+ default_value?: string | null;
42
+ };
43
+ }
44
+ export interface TimeFieldSchema extends FieldSchemaBase {
45
+ type: "time";
46
+ property: {
47
+ required: boolean;
48
+ default_value?: string | null;
49
+ };
50
+ }
51
+ export interface DateTimeFieldSchema extends FieldSchemaBase {
52
+ type: "datetime";
53
+ property: {
54
+ required: boolean;
55
+ default_value?: string | null;
56
+ };
57
+ }
58
+ export interface ListFieldSchema extends FieldSchemaBase {
59
+ type: "list";
60
+ property: {
61
+ required: boolean;
62
+ list_max_length: number;
63
+ text_max_length: number;
64
+ /** 数组元素是对象时, 取该键的值拼成文本(导出展示用) */
65
+ item_key?: string;
66
+ default_value?: string[] | [];
67
+ };
68
+ }
69
+ export interface SingleChoiceFieldSchema extends FieldSchemaBase {
70
+ type: "single_choice";
71
+ property: {
72
+ required: boolean;
73
+ option_map: Record<string, string>;
74
+ default_value?: string | null;
75
+ };
76
+ }
77
+ export interface MultipleChoiceFieldSchema extends FieldSchemaBase {
78
+ type: "multiple_choice";
79
+ property: {
80
+ required: boolean;
81
+ option_map: Record<string, string>;
82
+ default_value?: string[] | [];
83
+ };
84
+ }
85
+ export type FieldSchema = TextFieldSchema | NumberFieldSchema | BooleanFieldSchema | DateFieldSchema | TimeFieldSchema | DateTimeFieldSchema | ListFieldSchema | SingleChoiceFieldSchema | MultipleChoiceFieldSchema;
86
+ /** 导入模板与解析用: 去掉只供导出的列 */
87
+ export declare function importableFields(fieldSchemas: FieldSchema[]): FieldSchema[];
88
+ export {};
@@ -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,21 @@
1
+ import type { BooleanFieldSchema, FieldSchema, ListFieldSchema, MultipleChoiceFieldSchema, NumberFieldSchema, SingleChoiceFieldSchema, TextFieldSchema } from "./index";
2
+ interface ValidateSuccess {
3
+ validateSuccess: true;
4
+ validateValue: unknown;
5
+ }
6
+ interface ValidateFail {
7
+ validateSuccess: false;
8
+ validateMessage: string;
9
+ }
10
+ type ValidateResult = ValidateSuccess | ValidateFail;
11
+ export declare function validateTextField(value: string, fieldSchema: TextFieldSchema): ValidateResult;
12
+ export declare function validateNumberField(value: string, fieldSchema: NumberFieldSchema): ValidateResult;
13
+ export declare function validateBooleanField(value: string, fieldSchema: BooleanFieldSchema): ValidateResult;
14
+ export declare function validateDateField(value: string): ValidateResult;
15
+ export declare function validateTimeField(value: string): ValidateResult;
16
+ export declare function validateDateTimeField(value: string): ValidateResult;
17
+ export declare function validateListField(value: string, fieldSchema: ListFieldSchema): ValidateResult;
18
+ export declare function validateSingleChoiceField(value: string, fieldSchema: SingleChoiceFieldSchema): ValidateResult;
19
+ export declare function validateMultipleChoiceField(value: string, fieldSchema: MultipleChoiceFieldSchema): ValidateResult;
20
+ export declare function validateField(value: string | null, fieldSchema: FieldSchema): ValidateResult;
21
+ export {};
@@ -0,0 +1,123 @@
1
+ import type { ImportRow } from "./excel/importRow";
2
+ import type { FieldSchema } from "./schema";
3
+ import type { ImportRowFieldError, ImportRowResult, PagedData } from "./types";
4
+ /**
5
+ * 导入/导出任务执行器
6
+ *
7
+ * 任务只属于当前弹窗: 负责分批/游标执行、生成 Excel 和触发下载。
8
+ * 导入/导出弹窗通过 useTaskDetail 订阅指定任务, 关闭弹窗时释放任务数据。
9
+ *
10
+ * 任务只存在内存: 刷新/关闭页面即丢失, 不做刷新恢复。
11
+ */
12
+ export type TaskStatus = "running" | "paused" | "completed" | "failed" | "canceled";
13
+ type TaskType = "export" | "import";
14
+ interface TaskSample {
15
+ time: number;
16
+ processed: number;
17
+ }
18
+ export type ImportRowStatus = "queued" | "running" | "completed" | "failed" | "canceled" | "deleted";
19
+ interface ImportRowState {
20
+ status: ImportRowStatus;
21
+ message?: string;
22
+ fieldErrors?: ImportRowFieldError[];
23
+ validationErrors?: Record<string, string>;
24
+ }
25
+ interface ImportFailure {
26
+ index: number;
27
+ rowNumber: number;
28
+ message: string;
29
+ fieldErrors?: ImportRowFieldError[];
30
+ }
31
+ export interface TaskItem {
32
+ id: string;
33
+ type: TaskType;
34
+ title: string;
35
+ status: TaskStatus;
36
+ pausing?: boolean;
37
+ total: number;
38
+ processed: number;
39
+ errorMessage?: string;
40
+ fileName?: string;
41
+ blob?: Blob;
42
+ failures?: ImportFailure[];
43
+ rowStates?: ImportRowState[];
44
+ /** 导入成功行数; 导出任务不使用 */
45
+ successCount?: number;
46
+ /** 导入失败行数; 导出任务不使用 */
47
+ failureCount?: number;
48
+ /** 导入中因前端校验待修复的行数 */
49
+ validationFailedCount?: number;
50
+ /** 导出任务正在生成文件/触发下载 */
51
+ finalizing?: boolean;
52
+ /** 导入任务正在取消, 在途行结束前保持该状态 */
53
+ canceling?: boolean;
54
+ samples: TaskSample[];
55
+ }
56
+ export interface ExportTaskOptions {
57
+ title: string;
58
+ fileName: string;
59
+ fieldSchemas: FieldSchema[];
60
+ fetchPage: (params: Record<string, unknown>, signal: AbortSignal) => Promise<PagedData<object>>;
61
+ }
62
+ /** 导入行遇到权限/系统错误时立即暂停任务, 不按普通行级失败继续执行 */
63
+ export declare class ImportPauseError extends Error {
64
+ constructor(message: string);
65
+ }
66
+ export interface ImportTaskOptions {
67
+ title: string;
68
+ /** 唯一数据源: 行值、校验错误、行号都在这里, 提交时再派生接口 payload */
69
+ rows: ImportRow[];
70
+ fieldSchemas: FieldSchema[];
71
+ /** 文件里实际存在的列; 更新时未包含的列表示不修改 */
72
+ includedKeys: string[];
73
+ importRows: (rows: ImportRow[], signal: AbortSignal) => Promise<ImportRowResult[]>;
74
+ /** 每批行数; 批越小请求返回越快, 默认 20 */
75
+ batchSize?: number;
76
+ /** 同时执行的批次数量, 默认 3 */
77
+ concurrency?: number;
78
+ onFinished?: () => void;
79
+ }
80
+ /** 供框架层订阅任务变化; store 本身不依赖 React */
81
+ export declare function subscribeTasks(listener: () => void): () => void;
82
+ /** 供框架层读取当前任务快照; 没有变化时返回同一引用 */
83
+ export declare function getTasksSnapshot(): TaskItem[];
84
+ /** 新增并立即执行导出任务 */
85
+ export declare function enqueueExport(options: ExportTaskOptions): string;
86
+ /** 新增并立即执行导入任务; 任务内部按配置的并发数逐行执行 */
87
+ export declare function enqueueImport(options: ImportTaskOptions): string;
88
+ /**
89
+ * 继续导入: 从头扫一遍, 只执行非已完成行, 让暂停/失败后编辑过的行重新提交.
90
+ */
91
+ export declare function continueTask(taskId: string): void;
92
+ /** 暂停导入: 当前请求/当前行结束后停下, 不 abort 已发出的导入写请求 */
93
+ export declare function pauseTask(taskId: string): void;
94
+ /** 暂停时保存待导入行的编辑结果, 继续任务时使用新数据 */
95
+ export declare function updateImportRowData(taskId: string, rowIndex: number, row: ImportRow): void;
96
+ /** 校验失败行仍留在任务里, 只标记跳过并保存校验错误; 修复后取消标记即可, 不移动数组 */
97
+ export declare function setImportRowValidation(taskId: string, rowIndex: number, validationErrors: Record<string, string>): void;
98
+ /** 暂停时删除尚未导入的行: 从后续调度中跳过, 已完成/失败/进行中的行不允许删除 */
99
+ export declare function deleteImportRows(taskId: string, rowIndexes: number[]): void;
100
+ /** 编辑失败行某个字段后, 清掉该字段上一次的后端错误 */
101
+ export declare function clearImportRowFieldError(taskId: string, rowIndex: number, field: string): void;
102
+ /** 取消: 停止任务但保留任务和预览, 由用户关闭/清除 */
103
+ export declare function cancelTask(taskId: string): void;
104
+ /** 移除任务; 执行中的任务先中断, 完成任务的 Blob 也会随引用释放 */
105
+ export declare function dismissTask(taskId: string): void;
106
+ /** 重复下载已完成的导出文件 */
107
+ export declare function downloadTask(taskId: string): boolean;
108
+ /** 退出登录/切换账号时清空当前用户的任务, 同时中断所有在途请求 */
109
+ export declare function resetTasks(): void;
110
+ /**
111
+ * 剩余时间估算: 采样只覆盖最近 15 秒, 取首尾两点算近期速度, 再按剩余行数外推.
112
+ * 任务刚起步、采样不足或速度算不出来时返回 null, 调用方显示"计算中".
113
+ */
114
+ export declare function getTaskRemainingSeconds(task: TaskItem): number | null;
115
+ /** 导入任务的完成数只看成功导入的行; 失败/跳过/校验失败都不算完成 */
116
+ export declare function getTaskSuccessCount(task: TaskItem): number;
117
+ /** 显示用百分比: 未完成时直接截断, 不四舍五入成 100% */
118
+ export declare function getTaskDisplayPercent(task: TaskItem): number;
119
+ /** 百分比展示固定一位小数; 传入值已经截断, 这里不会再发生进位 */
120
+ export declare function formatTaskPercent(percent: number): string;
121
+ /** 剩余时间转中文文案; null 表示采样点还不够, 算不出速度 */
122
+ export declare function formatTaskRemainingSeconds(remainingSeconds: number | null): string;
123
+ export {};
@@ -0,0 +1,16 @@
1
+ /** 分页数据: 导入导出只依赖这个最小结构, 具体请求库由使用方决定 */
2
+ export interface PagedData<Row extends object = Record<string, unknown>> {
3
+ count: number;
4
+ results: Row[];
5
+ }
6
+ export type ImportRowFieldError = Record<string, string>;
7
+ /** 批量导入接口返回的单行原始错误 body; 空对象表示成功 */
8
+ export type ImportRowErrorBody = Record<string, unknown>;
9
+ /** 单行导入结果: 成功行是空对象, 失败行带行级错误 */
10
+ export type ImportRowResult = {
11
+ success: true;
12
+ } | {
13
+ success: false;
14
+ message?: string;
15
+ fieldErrors?: ImportRowFieldError[];
16
+ };
@@ -0,0 +1,21 @@
1
+ export type { BooleanFieldSchema, DateFieldSchema, DateTimeFieldSchema, FieldSchema, ListFieldSchema, MultipleChoiceFieldSchema, NumberFieldSchema, SingleChoiceFieldSchema, TextFieldSchema, TimeFieldSchema, } from "./core/schema";
2
+ export { importableFields } from "./core/schema";
3
+ export { MULTI_VALUE_SEPARATOR, joinMultiValues, splitMultiValues } from "./core/schema/multiValue";
4
+ export { validateBooleanField, validateDateField, validateDateTimeField, validateField, validateListField, validateMultipleChoiceField, validateNumberField, validateSingleChoiceField, validateTextField, validateTimeField, } from "./core/schema/validate";
5
+ export { MAX_EXPORT_ROWS, MAX_IMPORT_FILE_SIZE, MAX_IMPORT_ROWS } from "./core/limits";
6
+ export type { ImportRow } from "./core/excel/importRow";
7
+ export { buildImportPayload } from "./core/excel/importRow";
8
+ export type { ImportParseResult } from "./core/excel/parseSheet";
9
+ export { autoAdjustColumnWidths, buildExportBlob, downloadImportTemplate, exportExcel, parseImportFile, } from "./core/excel/runtime";
10
+ export type { ImportRowFieldError, ImportRowResult, PagedData } from "./core/types";
11
+ export type { ExportTaskOptions, ImportRowStatus, ImportTaskOptions, TaskItem, TaskStatus } from "./core/taskManager";
12
+ export { ImportPauseError, cancelTask, clearImportRowFieldError, continueTask, deleteImportRows, dismissTask, downloadTask, enqueueExport, enqueueImport, formatTaskPercent, formatTaskRemainingSeconds, getTaskDisplayPercent, getTaskRemainingSeconds, getTaskSuccessCount, getTasksSnapshot, pauseTask, resetTasks, setImportRowValidation, subscribeTasks, updateImportRowData, } from "./core/taskManager";
13
+ export { useTaskDetail } from "./react/useTaskDetail";
14
+ export type { BatchExportButtonProps } from "./components/BatchExportButton";
15
+ export { default as BatchExportButton } from "./components/BatchExportButton";
16
+ export type { ExcelExportButtonProps } from "./components/ExcelExportButton";
17
+ export { default as ExcelExportButton } from "./components/ExcelExportButton";
18
+ export type { ExcelImportButtonProps } from "./components/ExcelImportButton";
19
+ export { default as ExcelImportButton } from "./components/ExcelImportButton";
20
+ export type { ExportTaskModalProps } from "./components/ExportTaskModal";
21
+ export { default as ExportTaskModal } from "./components/ExportTaskModal";