- 新增 doctor_web/ React前端 (dashboard/患者/问诊/报告/随访) - 后端新增 doctor_endpoints (14个医生API) + ConsultationHub (SignalR) - Flutter端 SignalR 替换轮询实现实时聊天
30 lines
892 B
TypeScript
30 lines
892 B
TypeScript
const BASE_URL = 'http://localhost:5000';
|
|
|
|
async function request<T>(method: string, path: string, body?: unknown): Promise<T> {
|
|
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
|
|
const res = await fetch(`${BASE_URL}${path}`, {
|
|
method,
|
|
headers,
|
|
body: body ? JSON.stringify(body) : undefined,
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const text = await res.text();
|
|
throw new Error(text || `HTTP ${res.status}`);
|
|
}
|
|
|
|
const json = await res.json();
|
|
if (json.code !== 0) {
|
|
throw new Error(json.message || `Error code ${json.code}`);
|
|
}
|
|
return json.data as T;
|
|
}
|
|
|
|
export const api = {
|
|
get: <T>(path: string) => request<T>('GET', path),
|
|
post: <T>(path: string, body?: unknown) => request<T>('POST', path, body),
|
|
put: <T>(path: string, body?: unknown) => request<T>('PUT', path, body),
|
|
del: <T>(path: string) => request<T>('DELETE', path),
|
|
};
|