Files
shanxia2.0/mobile-h5/src/api/vehicleOptionsApi.ts
T
zlwuandCursor a8f59183df feat(mobile-h5): add CRM/PL option APIs and select-only pickers
Provide customer/product/vehicle pickers that search portal master data without create-on-type.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-03 22:39:36 +08:00

46 lines
1.3 KiB
TypeScript

import api from '@/utils/http'
export interface VehicleOption {
id: string
licensePlate: string
vehicleType?: string
}
function extractList<T>(res: unknown): T[] {
const data = (res as { list?: T[]; rows?: T[]; items?: T[] }) || {}
return data.list || data.rows || data.items || (Array.isArray(res) ? (res as T[]) : [])
}
/** 登录态:运输车辆(自有 + 三方),只读搜索 */
export async function fetchVehicleOptions(q?: string): Promise<VehicleOption[]> {
const res = await api.get<{ list?: VehicleOption[]; total?: number }>({
url: '/transport/vehicle',
params: {
...(q?.trim() ? { q: q.trim() } : {}),
page: 1,
pageSize: 100
}
})
return extractList<VehicleOption>(res)
}
/** 免登:现场页车牌 options(依赖 Task 6 公共接口) */
export async function fetchPublicVehiclePlates(params: {
q?: string
inventoryId?: string
planId?: string
}): Promise<Array<{ licensePlate: string; vehicleType?: string }>> {
const res = await api.get<Array<{ licensePlate: string; vehicleType?: string }> | {
list?: Array<{ licensePlate: string; vehicleType?: string }>
}>({
url: '/public/db/vehicle-plates',
params: {
q: params.q,
inventoryId: params.inventoryId,
planId: params.planId
}
})
if (Array.isArray(res)) return res
return extractList(res)
}