// 平台总后台 API 客户端,仅封装首期 M0 + M1 接口。 const apiBaseURL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8080/api/v1'; export type OrgGasStation = { identity: string; stationCode: string; name: string; principal: string; serviceArea: string; status: string; createdAt: string; }; export type OrgDeliveryPoint = { identity: string; deliveryCode: string; name: string; gasStationName: string; serviceArea: string; status: string; }; export type OrgServicePerson = { identity: string; name: string; phoneMasked: string; roles: string; workStatus: string; credentialStatus: string; }; export type IdnAccount = { identity: string; phoneMasked: string; accountType: string; status: string; serviceArea: string; }; export type SafEvent = { identity: string; eventCode: string; level: number; title: string; status: string; createdAt: string; }; export type DashboardOverview = Record; async function request(path: string, init?: RequestInit): Promise { const response = await fetch(`${apiBaseURL}${path}`, { headers: { 'Content-Type': 'application/json', ...(init?.headers ?? {}) }, ...init, }); const payload = (await response.json()) as { data?: T; error?: string }; if (!response.ok || payload.error) throw new Error(payload.error || '请求失败'); return payload.data as T; } export const platformAPI = { getDashboard: () => request('/dashboard/overview'), listOrgGasStation: () => request('/org/gas-station'), createOrgGasStation: (body: Pick) => request('/org/gas-station', { method: 'POST', body: JSON.stringify(body) }), listOrgDeliveryPoint: () => request('/org/delivery-point'), listOrgServicePerson: () => request('/org/service-person'), listIdnAccount: () => request('/idn/account'), listSafEvent: () => request('/saf/event'), };