Files
admin-web/src/modules/overseas-warehouse/api/dispatchVehicleDocuments.ts
T

26 lines
1.9 KiB
TypeScript
Raw Normal View History

2026-10-21 16:40:10 +08:00
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export type FuelSlot = 'FUEL_START' | 'FUEL_END'
export interface VehiclePhoto { slot: FuelSlot; fileId: string; fileName: string; contentType: string; savedAt: string | null }
export interface VehicleDocuments { dispatchNo: string; recordVersion: string; editable: boolean; photos: VehiclePhoto[] }
export interface BindVehiclePhoto { recordVersion: string; idempotencyKey: string; fileId: string }
const path = (no: string) => `/platform/v1/last-leg/dispatches/${encodeURIComponent(no)}/vehicle-documents`
export async function getVehicleDocuments(no: string) {
return unwrapApiResponse(await http.get<ApiEnvelope<VehicleDocuments>, ApiEnvelope<VehicleDocuments>>(path(no)))
}
export async function uploadVehiclePhoto(no: string, slot: FuelSlot, file: File, key: string) {
const form = new FormData(); form.append('file', file); form.append('idempotencyKey', key)
return unwrapApiResponse(await http.post<ApiEnvelope<VehiclePhoto>, ApiEnvelope<VehiclePhoto>>(`${path(no)}/${slot}/uploads`, form))
}
export async function recoverVehiclePhoto(no: string, key: string) {
return unwrapApiResponse(await http.get<ApiEnvelope<VehiclePhoto>, ApiEnvelope<VehiclePhoto>>(`${path(no)}/uploads/${encodeURIComponent(key)}`))
}
export async function bindVehiclePhoto(no: string, slot: FuelSlot, body: BindVehiclePhoto) {
return unwrapApiResponse(await http.put<ApiEnvelope<VehicleDocuments>, ApiEnvelope<VehicleDocuments>>(`${path(no)}/${slot}`, body))
}
export async function readVehiclePhoto(no: string, photo: VehiclePhoto) {
const blob = await http.get<Blob, Blob>(`${path(no)}/${photo.slot}/files/${encodeURIComponent(photo.fileId)}/content`, { responseType: 'blob' })
if (!(blob instanceof Blob) || !['image/jpeg', 'image/png'].includes(blob.type) || !blob.size) throw new Error('图片读取失败,请重新核对')
return blob
}