feat(frontend): 更新 TS 类型定义与 API 服务层,对接后端重构接口
types/api.ts: - TaskSummary/TaskResponse 新增 is_rework, reject_reason, received_at, completed_at 字段 - 新增 TASK_STATUS 常量 (PENDING/WIP/COMPLETED/REJECTED/ARCHIVED) - 新增 TaskTransferResponse, TaskRejectPayload, TaskTransferPayload 类型 - ProductScanResponse 新增 current_location_id, task_tree 字段 types/admin.ts: - ProductResponse 新增 current_location_id 字段 services/taskApi.ts: - 新增 getTaskTree(serialNumber) — 产品全景任务树 - 新增 receiveTask(taskId) — 确认接收 - 新增 rejectTask(taskId, reason) — 品质驳回 - 新增 transferTask(taskId, assignees, name, note?) — 完工裂变转交
This commit is contained in:
@ -2,7 +2,11 @@ import api from "./api";
|
||||
import type {
|
||||
TaskResponse,
|
||||
TaskCompleteResponse,
|
||||
TaskTransferResponse,
|
||||
TaskListResponse,
|
||||
ProductScanResponse,
|
||||
TaskRejectPayload,
|
||||
TaskTransferPayload,
|
||||
} from "../types/api";
|
||||
|
||||
// ============================================================
|
||||
@ -51,7 +55,7 @@ export async function createSubtask(
|
||||
return data;
|
||||
}
|
||||
|
||||
/** 完成任务 + 转交 */
|
||||
/** 完成任务 + 转交(旧版单步) */
|
||||
export async function completeTask(
|
||||
taskId: string,
|
||||
payload: TaskCompletePayload
|
||||
@ -62,3 +66,65 @@ export async function completeTask(
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 新版核心业务 API(重构后)
|
||||
// ============================================================
|
||||
|
||||
/**
|
||||
* 获取产品全景任务树 — 用于十字矩阵树状图。
|
||||
* 对应后端 GET /api/v1/products/scan/{serialNumber}
|
||||
*/
|
||||
export async function getTaskTree(
|
||||
serialNumber: string
|
||||
): Promise<ProductScanResponse> {
|
||||
const { data } = await api.get<ProductScanResponse>(
|
||||
`/products/scan/${encodeURIComponent(serialNumber)}`
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认接收任务 — PENDING → WIP。
|
||||
* 对应后端 POST /api/v1/tasks/{taskId}/receive
|
||||
*/
|
||||
export async function receiveTask(taskId: string): Promise<TaskResponse> {
|
||||
const { data } = await api.post<TaskResponse>(`/tasks/${taskId}/receive`);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 品质驳回 — → REJECTED,后端自动创建返工任务。
|
||||
* 对应后端 POST /api/v1/tasks/{taskId}/reject
|
||||
*/
|
||||
export async function rejectTask(
|
||||
taskId: string,
|
||||
reason: string
|
||||
): Promise<TaskResponse> {
|
||||
const { data } = await api.post<TaskResponse>(
|
||||
`/tasks/${taskId}/reject`,
|
||||
{ reason } satisfies TaskRejectPayload
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 完工裂变转交 — → COMPLETED,批量创建下家任务。
|
||||
* 对应后端 POST /api/v1/tasks/{taskId}/transfer
|
||||
*/
|
||||
export async function transferTask(
|
||||
taskId: string,
|
||||
nextAssignees: string[],
|
||||
nextTaskName: string,
|
||||
note?: string
|
||||
): Promise<TaskTransferResponse> {
|
||||
const { data } = await api.post<TaskTransferResponse>(
|
||||
`/tasks/${taskId}/transfer`,
|
||||
{
|
||||
next_assignees: nextAssignees,
|
||||
next_task_name: nextTaskName,
|
||||
note,
|
||||
} satisfies TaskTransferPayload
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ export interface ProductResponse {
|
||||
order_no?: string;
|
||||
material_id: string | null;
|
||||
parent_product_id: string | null;
|
||||
current_location_id: string | null;
|
||||
status: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
@ -1,5 +1,19 @@
|
||||
/** 后端 API 响应类型 */
|
||||
|
||||
// ============================================================
|
||||
// 任务状态常量
|
||||
// ============================================================
|
||||
|
||||
export const TASK_STATUS = {
|
||||
PENDING: "PENDING",
|
||||
WIP: "WIP",
|
||||
COMPLETED: "COMPLETED",
|
||||
REJECTED: "REJECTED",
|
||||
ARCHIVED: "ARCHIVED",
|
||||
} as const;
|
||||
|
||||
export type TaskStatus = (typeof TASK_STATUS)[keyof typeof TASK_STATUS];
|
||||
|
||||
// ============================================================
|
||||
// 任务
|
||||
// ============================================================
|
||||
@ -10,8 +24,12 @@ export interface TaskSummary {
|
||||
parent_task_id: string | null;
|
||||
task_name: string;
|
||||
assignee_id: string | null;
|
||||
status: string;
|
||||
status: TaskStatus | string;
|
||||
notify_parent_on_complete: boolean;
|
||||
is_rework: boolean;
|
||||
reject_reason: string | null;
|
||||
received_at: string | null;
|
||||
completed_at: string | null;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
@ -19,17 +37,37 @@ export interface TaskResponse extends TaskSummary {
|
||||
child_tasks: TaskResponse[];
|
||||
}
|
||||
|
||||
// ---- 操作响应 ----
|
||||
|
||||
export interface TaskCompleteResponse {
|
||||
completed_task: TaskResponse;
|
||||
next_task: TaskResponse | null;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface TaskTransferResponse {
|
||||
completed_task: TaskResponse;
|
||||
created_tasks: TaskResponse[];
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface TaskListResponse {
|
||||
tasks: TaskResponse[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
// ---- 请求体 ----
|
||||
|
||||
export interface TaskRejectPayload {
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export interface TaskTransferPayload {
|
||||
next_assignees: string[];
|
||||
next_task_name: string;
|
||||
note?: string;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 产品
|
||||
// ============================================================
|
||||
@ -41,7 +79,10 @@ export interface ProductScanResponse {
|
||||
order_no: string;
|
||||
material_id: string | null;
|
||||
parent_product_id: string | null;
|
||||
current_location_id: string | null;
|
||||
status: string;
|
||||
created_at: string;
|
||||
top_level_tasks: TaskSummary[];
|
||||
/** 完整递归任务树 — 供十字矩阵树状图渲染 */
|
||||
task_tree: TaskResponse[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user