- ErrorBoundary 组件:全局错误捕获与优雅降级 - 提取 5 个自定义 hooks:useCountUp, useDarkMode, useDebouncedValue, usePaginatedData, useApiRequest - 从 11 个 API 文件提取 PaginatedResponse 共享类型到 api/types.ts - 统一 API 错误处理(api/errors.ts) - client.ts 迁移到 axios adapter 模式(替代废弃的 CancelToken) - 添加 react-i18next 国际化基础设施 + zh-CN 语言包
90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
import client from './client';
|
|
import type { PaginatedResponse } from './types';
|
|
|
|
export interface NodeDef {
|
|
id: string;
|
|
type: 'StartEvent' | 'EndEvent' | 'UserTask' | 'ServiceTask' | 'ExclusiveGateway' | 'ParallelGateway';
|
|
name: string;
|
|
assignee_id?: string;
|
|
candidate_groups?: string[];
|
|
service_type?: string;
|
|
position?: { x: number; y: number };
|
|
}
|
|
|
|
export interface EdgeDef {
|
|
id: string;
|
|
source: string;
|
|
target: string;
|
|
condition?: string;
|
|
label?: string;
|
|
}
|
|
|
|
export interface ProcessDefinitionInfo {
|
|
id: string;
|
|
name: string;
|
|
key: string;
|
|
version: number;
|
|
category?: string;
|
|
description?: string;
|
|
nodes: NodeDef[];
|
|
edges: EdgeDef[];
|
|
status: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
}
|
|
|
|
export interface CreateProcessDefinitionRequest {
|
|
name: string;
|
|
key: string;
|
|
category?: string;
|
|
description?: string;
|
|
nodes: NodeDef[];
|
|
edges: EdgeDef[];
|
|
}
|
|
|
|
export interface UpdateProcessDefinitionRequest {
|
|
name?: string;
|
|
category?: string;
|
|
description?: string;
|
|
nodes?: NodeDef[];
|
|
edges?: EdgeDef[];
|
|
}
|
|
|
|
export async function listProcessDefinitions(page = 1, pageSize = 20) {
|
|
const { data } = await client.get<{ success: boolean; data: PaginatedResponse<ProcessDefinitionInfo> }>(
|
|
'/workflow/definitions',
|
|
{ params: { page, page_size: pageSize } },
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function getProcessDefinition(id: string) {
|
|
const { data } = await client.get<{ success: boolean; data: ProcessDefinitionInfo }>(
|
|
`/workflow/definitions/${id}`,
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function createProcessDefinition(req: CreateProcessDefinitionRequest) {
|
|
const { data } = await client.post<{ success: boolean; data: ProcessDefinitionInfo }>(
|
|
'/workflow/definitions',
|
|
req,
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function updateProcessDefinition(id: string, req: UpdateProcessDefinitionRequest) {
|
|
const { data } = await client.put<{ success: boolean; data: ProcessDefinitionInfo }>(
|
|
`/workflow/definitions/${id}`,
|
|
req,
|
|
);
|
|
return data.data;
|
|
}
|
|
|
|
export async function publishProcessDefinition(id: string) {
|
|
const { data } = await client.post<{ success: boolean; data: ProcessDefinitionInfo }>(
|
|
`/workflow/definitions/${id}/publish`,
|
|
);
|
|
return data.data;
|
|
}
|