新增任务管理与报警管理前端,并接入车队健康数据。
运营菜单下挂地图监控/任务/报警入口,车辆卡片与任务列表同步展示运行态。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import http from './http'
|
||||
import type { DeliveryTask } from '@/types/delivery'
|
||||
import type { CreateDeliveryPayload, DeliveryTask } from '@/types/delivery'
|
||||
|
||||
const MOCK = import.meta.env.VITE_USE_MOCK === 'true'
|
||||
|
||||
@@ -20,17 +20,72 @@ export async function listDeliveries(opts?: {
|
||||
return Array.isArray(data) ? data : []
|
||||
}
|
||||
|
||||
export async function cancelDelivery(id: number): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${id}/cancel`)
|
||||
/** CDM 任务快照订阅结果:来自平台库 cdm_tasks(SimpleLite 关闭时仍可读,含完整历史)。 */
|
||||
export interface CdmTaskFeed {
|
||||
online: boolean
|
||||
lastSyncAt: string | null
|
||||
tasks: DeliveryTask[]
|
||||
}
|
||||
|
||||
export async function resendDelivery(id: number): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${id}/resend`)
|
||||
/**
|
||||
* 任务页数据源:优先读平台快照库 /fleet/tasks(离线可读 + 历史保留);
|
||||
* 若平台端点不可用则回退到实时投影 /sl/projection/deliveries。
|
||||
*/
|
||||
export async function fetchCdmTaskFeed(limit = 1000): Promise<CdmTaskFeed> {
|
||||
if (MOCK) {
|
||||
const { mockDeliveries } = await import('@/mock/data/deliveries')
|
||||
return { online: true, lastSyncAt: new Date().toISOString(), tasks: await mockDeliveries() }
|
||||
}
|
||||
try {
|
||||
const { data } = await http.get<CdmTaskFeed>('/fleet/tasks', { params: { limit } })
|
||||
return {
|
||||
online: !!data?.online,
|
||||
lastSyncAt: data?.lastSyncAt ?? null,
|
||||
tasks: Array.isArray(data?.tasks) ? data.tasks : []
|
||||
}
|
||||
} catch {
|
||||
const tasks = await listDeliveries({ includeFinished: true, includeAborted: true })
|
||||
return { online: true, lastSyncAt: new Date().toISOString(), tasks }
|
||||
}
|
||||
}
|
||||
|
||||
export async function forceCompleteDelivery(id: number): Promise<void> {
|
||||
export async function cancelDelivery(id: string): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${id}/force-complete`)
|
||||
await http.post(`${BASE}/${encodeURIComponent(id)}/cancel`)
|
||||
}
|
||||
|
||||
export async function resendDelivery(id: string): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${encodeURIComponent(id)}/resend`)
|
||||
}
|
||||
|
||||
export async function forceCompleteDelivery(id: string): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${encodeURIComponent(id)}/force-complete`)
|
||||
}
|
||||
|
||||
export async function pauseDelivery(id: string): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${encodeURIComponent(id)}/pause`)
|
||||
}
|
||||
|
||||
export async function resumeDelivery(id: string): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${encodeURIComponent(id)}/resume`)
|
||||
}
|
||||
|
||||
export async function changeCarDelivery(id: string): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${encodeURIComponent(id)}/change-car`)
|
||||
}
|
||||
|
||||
export async function setDeliveryPriority(id: string, value: number): Promise<void> {
|
||||
if (MOCK) return
|
||||
await http.post(`${BASE}/${encodeURIComponent(id)}/priority`, { value })
|
||||
}
|
||||
|
||||
export async function createDelivery(payload: CreateDeliveryPayload): Promise<{ id: string }> {
|
||||
if (MOCK) return { id: `MOCK-${Date.now()}` }
|
||||
const { data } = await http.post<{ success: boolean; id: string }>(BASE, payload)
|
||||
return { id: data?.id ?? '' }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user