128 lines
3.3 KiB
TypeScript
128 lines
3.3 KiB
TypeScript
import { request } from '@/utils/request';
|
|
|
|
import type { WorkbenchActivity } from './workbench';
|
|
|
|
export type DashboardStatus = 'UP' | 'WARNING' | 'DOWN' | 'DISABLED';
|
|
|
|
export interface DashboardServiceStatus {
|
|
code: string;
|
|
label: string;
|
|
status: DashboardStatus;
|
|
detail: string;
|
|
}
|
|
|
|
export interface DashboardSystem {
|
|
overallStatus: DashboardStatus;
|
|
currentVersion: string;
|
|
uptimeSeconds: number;
|
|
services: DashboardServiceStatus[];
|
|
}
|
|
|
|
export interface DashboardMetric {
|
|
code: string;
|
|
label: string;
|
|
kind: 'COUNT' | 'MONEY';
|
|
value: string;
|
|
unit: string;
|
|
available: boolean;
|
|
targetRoute?: string;
|
|
}
|
|
|
|
export interface DashboardTrendPoint {
|
|
period: string;
|
|
receivedAmount: string;
|
|
paidAmount: string;
|
|
invoicedAmount: string;
|
|
}
|
|
|
|
export interface DashboardTrend {
|
|
currency: string;
|
|
receiptsAvailable: boolean;
|
|
paymentsAvailable: boolean;
|
|
invoicesAvailable: boolean;
|
|
points: DashboardTrendPoint[];
|
|
}
|
|
|
|
export interface DashboardDistribution {
|
|
code: string;
|
|
label: string;
|
|
value: number;
|
|
available: boolean;
|
|
targetRoute?: string;
|
|
}
|
|
|
|
export interface DashboardRisk {
|
|
code: string;
|
|
label: string;
|
|
severity: 'DANGER' | 'WARNING' | 'INFO';
|
|
count: number;
|
|
detail: string;
|
|
available: boolean;
|
|
targetRoute?: string;
|
|
}
|
|
|
|
export interface DashboardRegion {
|
|
regionCode: string;
|
|
regionName: string;
|
|
projectCount: number;
|
|
amount: string;
|
|
currency: string;
|
|
}
|
|
|
|
export interface DashboardGeography {
|
|
available: boolean;
|
|
message: string;
|
|
regions: DashboardRegion[];
|
|
}
|
|
|
|
export interface DashboardOverview {
|
|
title: string;
|
|
refreshedAt: string;
|
|
currency: string;
|
|
system: DashboardSystem;
|
|
metrics: DashboardMetric[];
|
|
trend: DashboardTrend;
|
|
lifecycle: DashboardDistribution[];
|
|
risks: DashboardRisk[];
|
|
geography: DashboardGeography;
|
|
activities: WorkbenchActivity[];
|
|
}
|
|
|
|
const array = <T>(value: T[] | null | undefined): T[] => (Array.isArray(value) ? value : []);
|
|
|
|
export function normalizeDashboard(view: Partial<DashboardOverview> | null | undefined): DashboardOverview {
|
|
return {
|
|
title: String(view?.title || '系统经营仪表盘'),
|
|
refreshedAt: String(view?.refreshedAt || ''),
|
|
currency: String(view?.currency || 'CNY'),
|
|
system: {
|
|
overallStatus: view?.system?.overallStatus || 'WARNING',
|
|
currentVersion: String(view?.system?.currentVersion || '-'),
|
|
uptimeSeconds: Number(view?.system?.uptimeSeconds || 0),
|
|
services: array(view?.system?.services),
|
|
},
|
|
metrics: array(view?.metrics),
|
|
trend: {
|
|
currency: String(view?.trend?.currency || view?.currency || 'CNY'),
|
|
receiptsAvailable: Boolean(view?.trend?.receiptsAvailable),
|
|
paymentsAvailable: Boolean(view?.trend?.paymentsAvailable),
|
|
invoicesAvailable: Boolean(view?.trend?.invoicesAvailable),
|
|
points: array(view?.trend?.points),
|
|
},
|
|
lifecycle: array(view?.lifecycle),
|
|
risks: array(view?.risks),
|
|
geography: {
|
|
available: Boolean(view?.geography?.available),
|
|
message: String(view?.geography?.message || '暂无地域数据'),
|
|
regions: array(view?.geography?.regions),
|
|
},
|
|
activities: array(view?.activities),
|
|
};
|
|
}
|
|
|
|
export function getDashboardOverview(currency = 'CNY', signal?: AbortSignal) {
|
|
return request
|
|
.get<DashboardOverview>({ url: '/dashboard/overview', params: { currency }, signal })
|
|
.then(normalizeDashboard);
|
|
}
|