71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
|
|
// 平台总后台 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<string, number>;
|
||
|
|
|
||
|
|
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||
|
|
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<DashboardOverview>('/dashboard/overview'),
|
||
|
|
listOrgGasStation: () => request<OrgGasStation[]>('/org/gas-station'),
|
||
|
|
createOrgGasStation: (body: Pick<OrgGasStation, 'stationCode' | 'name' | 'principal' | 'serviceArea'>) =>
|
||
|
|
request<OrgGasStation>('/org/gas-station', { method: 'POST', body: JSON.stringify(body) }),
|
||
|
|
listOrgDeliveryPoint: () => request<OrgDeliveryPoint[]>('/org/delivery-point'),
|
||
|
|
listOrgServicePerson: () => request<OrgServicePerson[]>('/org/service-person'),
|
||
|
|
listIdnAccount: () => request<IdnAccount[]>('/idn/account'),
|
||
|
|
listSafEvent: () => request<SafEvent[]>('/saf/event'),
|
||
|
|
};
|