import { useEffect, useState, type ReactNode } from 'react'
import { Card, Col, Progress, Row, Space, Statistic, Typography, Spin, message } from 'antd'
import {
ApiOutlined,
CheckCircleOutlined,
ClockCircleOutlined,
CloseCircleOutlined,
DatabaseOutlined,
DollarOutlined,
PercentageOutlined,
ShopOutlined,
ShoppingOutlined,
TeamOutlined,
WalletOutlined,
} from '@ant-design/icons'
import { dashboardApi } from '../api'
import type { DashboardStats } from '../types'
const numberText = (value?: number) => (value ?? 0).toLocaleString('zh-CN')
function ratio(part: number, total: number) {
if (total <= 0) return 0
return Math.round((part / total) * 100)
}
function MetricCard({
title,
value,
icon,
suffix,
color,
}: {
title: string
value: number
icon: ReactNode
suffix?: string
color?: string
}) {
return (
numberText(value)}
prefix={icon}
suffix={suffix}
valueStyle={color ? { color } : undefined}
/>
)
}
function StatusLine({
label,
value,
total,
color,
}: {
label: string
value: number
total: number
color: string
}) {
return (
{label}
{numberText(value)}
)
}
export default function Dashboard() {
const [stats, setStats] = useState(null)
const [loading, setLoading] = useState(true)
useEffect(() => {
dashboardApi
.stats()
.then(setStats)
.catch((e) => message.error(e.message))
.finally(() => setLoading(false))
}, [])
if (loading) {
return (
)
}
return (
数据概览
{stats?.scope === 'platform' ? '平台全局运营数据' : '当前商户运营数据'}
}
/>
}
/>
} />
} />
} />
}
color={(stats?.paid_order_count ?? 0) > 0 ? '#cf1322' : undefined}
/>
积分与费用
} suffix="积分" />
} suffix="积分" />
} suffix="积分" />
} suffix="积分" />
}
suffix={`/ ${numberText(stats?.api_client_count)}`}
/>
} />
} />
}
valueStyle={(stats?.failed_callback_count ?? 0) > 0 ? { color: '#cf1322' } : undefined}
/>
)
}