export type GetApiApiV1DashboardChartArgs = {id: number, endpoint: Array, metric: Array, start: string, end?: string | undefined, aggregate?: string | undefined}; export type GetApiApiV1DashboardChartOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * 页面通用接口 : 获取chart数据 * * GET /api/v1/dashboard/chart */ export const getApiApiV1DashboardChart = async (args: GetApiApiV1DashboardChartArgs, options: GetApiApiV1DashboardChartOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.id != null) query.append("id", String(args.id)) for (const item of args.endpoint ?? []) query.append("endpoint", String(item)) for (const item of args.metric ?? []) query.append("metric", String(item)) if (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (args.aggregate != null) query.append("aggregate", String(args.aggregate)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/dashboard/chart${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };