feat(plugin): P2-4 数据导入导出 — 后端 export/import API + 前端 UI + TS 修复
- data_service: export 方法查询匹配行(上限10000),import 方法逐行校验+插入 - data_handler: export_plugin_data / import_plugin_data 处理函数 - module: 注册 GET /export + POST /import 路由 - pluginData.ts: exportPluginData / importPluginData API 函数 - PluginCRUDPage: 根据 entity importable/exportable 标志显示导出/导入按钮 - PluginMarket: 修复 TS 错误 (unused imports, type narrowing) - PluginSettingsForm: 修复 TS 错误 (Rule type, Divider orientation)
This commit is contained in:
@@ -209,3 +209,54 @@ export async function getPluginEntityRegistry(): Promise<PublicEntity[]> {
|
||||
);
|
||||
return data.data;
|
||||
}
|
||||
|
||||
// ─── 数据导入导出 API ──────────────────────────────────────────────────
|
||||
|
||||
export interface ExportOptions {
|
||||
filter?: Record<string, string>;
|
||||
search?: string;
|
||||
sort_by?: string;
|
||||
sort_order?: 'asc' | 'desc';
|
||||
format?: 'csv' | 'json';
|
||||
}
|
||||
|
||||
export async function exportPluginData(
|
||||
pluginId: string,
|
||||
entity: string,
|
||||
options?: ExportOptions,
|
||||
): Promise<Record<string, unknown>[]> {
|
||||
const params: Record<string, string> = {};
|
||||
if (options?.filter) params.filter = JSON.stringify(options.filter);
|
||||
if (options?.search) params.search = options.search;
|
||||
if (options?.sort_by) params.sort_by = options.sort_by;
|
||||
if (options?.sort_order) params.sort_order = options.sort_order;
|
||||
|
||||
const { data } = await client.get<{ success: boolean; data: Record<string, unknown>[] }>(
|
||||
`/plugins/${pluginId}/${entity}/export`,
|
||||
{ params },
|
||||
);
|
||||
return data.data;
|
||||
}
|
||||
|
||||
export interface ImportRowError {
|
||||
row: number;
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
export interface ImportResult {
|
||||
success_count: number;
|
||||
error_count: number;
|
||||
errors: ImportRowError[];
|
||||
}
|
||||
|
||||
export async function importPluginData(
|
||||
pluginId: string,
|
||||
entity: string,
|
||||
rows: Record<string, unknown>[],
|
||||
): Promise<ImportResult> {
|
||||
const { data } = await client.post<{ success: boolean; data: ImportResult }>(
|
||||
`/plugins/${pluginId}/${entity}/import`,
|
||||
{ rows },
|
||||
);
|
||||
return data.data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user