Implement the mobile dashboard frontend, admin overview APIs, report archive export, and local dev proxy so the boss dashboard can run against real backend data while preserving MSW demos. Co-authored-by: Cursor <cursoragent@cursor.com>
27 lines
707 B
TypeScript
27 lines
707 B
TypeScript
import axios from 'axios'
|
|
|
|
export const httpClient = axios.create({
|
|
baseURL: import.meta.env.VITE_API_BASE_URL ?? '',
|
|
timeout: 8000,
|
|
})
|
|
|
|
export type ApiResponse<T> = {
|
|
code: number
|
|
message?: string
|
|
msg?: string
|
|
data: T
|
|
}
|
|
|
|
export async function getApiData<T>(url: string): Promise<T> {
|
|
const response = await httpClient.get<ApiResponse<T>>(url)
|
|
if (response.data.code !== 0 && response.data.code !== 200) {
|
|
throw new Error(response.data.msg ?? response.data.message ?? '接口请求失败')
|
|
}
|
|
return response.data.data
|
|
}
|
|
|
|
export async function getBlob(url: string): Promise<Blob> {
|
|
const response = await httpClient.get<Blob>(url, { responseType: 'blob' })
|
|
return response.data
|
|
}
|