feat(dashboard): add boss dashboard H5 and APIs

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>
This commit is contained in:
danaisuiyuan
2026-05-11 13:07:40 +08:00
parent 693c66c258
commit 403ffe0fde
40 changed files with 6767 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'
import { AppProviders } from './app/providers/AppProviders'
import { MobileLayout } from './app/layouts/MobileLayout'
import { BossDashboardPage } from './features/boss-dashboard/pages/BossDashboardPage'
import { DailyReportPage, ProfilePage, RiskCenterPage, TodaySnapshotPage } from './features/boss-dashboard/pages/OperationsPages'
function App() {
return (
<AppProviders>
<BrowserRouter>
<Routes>
<Route path="/" element={<Navigate to="/h5/dashboard/boss" replace />} />
<Route element={<MobileLayout />}>
<Route path="/h5/dashboard/boss" element={<BossDashboardPage />} />
<Route path="/h5/dashboard/daily-report" element={<DailyReportPage />} />
<Route path="/h5/dashboard/today-snapshot" element={<TodaySnapshotPage />} />
<Route path="/h5/dashboard/risk-center" element={<RiskCenterPage />} />
<Route path="/h5/dashboard/profile" element={<ProfilePage />} />
</Route>
<Route path="*" element={<Navigate to="/h5/dashboard/boss" replace />} />
</Routes>
</BrowserRouter>
</AppProviders>
)
}
export default App

View File

@@ -0,0 +1,34 @@
import { AppOutline, BellOutline, FileOutline, HistogramOutline, UserOutline } from 'antd-mobile-icons'
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
import { SafeArea, TabBar } from 'antd-mobile'
const tabs = [
{ key: '/h5/dashboard/boss', title: '首页', icon: <AppOutline /> },
{ key: '/h5/dashboard/daily-report', title: '日报', icon: <FileOutline /> },
{ key: '/h5/dashboard/today-snapshot', title: '快报', icon: <HistogramOutline /> },
{ key: '/h5/dashboard/risk-center', title: '风险', icon: <BellOutline /> },
{ key: '/h5/dashboard/profile', title: '我的', icon: <UserOutline /> },
]
export function MobileLayout() {
const location = useLocation()
const navigate = useNavigate()
const activeKey = tabs.find((tab) => location.pathname.startsWith(tab.key))?.key ?? tabs[0].key
return (
<div className="mobile-shell">
<main className="mobile-main">
<Outlet />
</main>
<nav className="bottom-nav" aria-label="Dashboard mobile navigation">
<TabBar activeKey={activeKey} onChange={(key) => navigate(key)}>
{tabs.map((tab) => (
<TabBar.Item key={tab.key} icon={tab.icon} title={tab.title} />
))}
</TabBar>
<SafeArea position="bottom" />
</nav>
</div>
)
}

View File

@@ -0,0 +1,26 @@
import { ConfigProvider } from 'antd-mobile'
import zhCN from 'antd-mobile/es/locales/zh-CN'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import type { ReactNode } from 'react'
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 60 * 1000,
retry: 1,
refetchOnWindowFocus: false,
},
},
})
type AppProvidersProps = {
children: ReactNode
}
export function AppProviders({ children }: AppProvidersProps) {
return (
<ConfigProvider locale={zhCN}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</ConfigProvider>
)
}

View File

@@ -0,0 +1,76 @@
import * as echarts from 'echarts/core'
import { GridComponent, TooltipComponent } from 'echarts/components'
import { BarChart, LineChart } from 'echarts/charts'
import { CanvasRenderer } from 'echarts/renderers'
import { useEffect, useMemo, useRef } from 'react'
import type { TrendPoint } from '../../features/boss-dashboard/types'
echarts.use([GridComponent, TooltipComponent, LineChart, BarChart, CanvasRenderer])
type MiniTrendChartProps = {
data: TrendPoint[]
}
export function MiniTrendChart({ data }: MiniTrendChartProps) {
const chartRef = useRef<HTMLDivElement | null>(null)
const option = useMemo(
() => ({
color: ['#ff5b36', '#ffb000'],
grid: { left: 8, right: 8, top: 24, bottom: 18, containLabel: true },
tooltip: {
trigger: 'axis',
confine: true,
valueFormatter: (value: number | string) => Number(value).toLocaleString('zh-CN'),
},
xAxis: {
type: 'category',
data: data.map((item) => item.date),
axisLine: { show: false },
axisTick: { show: false },
},
yAxis: [
{ type: 'value', show: false },
{ type: 'value', show: false },
],
series: [
{
name: '成交额',
type: 'line',
smooth: true,
yAxisIndex: 0,
data: data.map((item) => item.amount),
symbol: 'circle',
symbolSize: 5,
lineStyle: { width: 3 },
areaStyle: { opacity: 0.08 },
},
{
name: '订单数',
type: 'bar',
yAxisIndex: 1,
data: data.map((item) => item.orders),
barWidth: 8,
borderRadius: 6,
},
],
}),
[data],
)
useEffect(() => {
if (!chartRef.current) return undefined
const chart = echarts.init(chartRef.current)
chart.setOption(option)
const resize = () => chart.resize()
window.addEventListener('resize', resize)
return () => {
window.removeEventListener('resize', resize)
chart.dispose()
}
}, [option])
return <div className="mini-trend-chart" ref={chartRef} aria-label="近 7 天交易趋势图" />
}

View File

@@ -0,0 +1,32 @@
import { Skeleton } from 'antd-mobile'
import { formatMetricValue, formatTrend } from '../../utils/format'
import type { KpiMetric } from '../../features/boss-dashboard/types'
type KpiCardProps = {
metric: KpiMetric
loading?: boolean
}
export function KpiCard({ metric, loading }: KpiCardProps) {
if (loading) {
return (
<article className="kpi-card">
<Skeleton.Title animated />
<Skeleton.Paragraph lineCount={1} animated />
</article>
)
}
return (
<article className={`kpi-card kpi-card--${metric.status} ${metric.featured ? 'kpi-card--featured' : ''}`}>
<p className="kpi-title">{metric.title}</p>
<strong className="kpi-value">{formatMetricValue(metric.value, metric.unit)}</strong>
{(metric.trendLabel || metric.trendValue !== undefined) && (
<p className="kpi-trend">
{metric.trendLabel}
{metric.trendValue !== undefined && <span>{formatTrend(metric.trendValue)}</span>}
</p>
)}
</article>
)
}

View File

@@ -0,0 +1,18 @@
import { useQuery } from '@tanstack/react-query'
import { getApiData, getBlob } from '../../services/http/client'
import type { DashboardOverview } from './types'
export const dashboardQueryKeys = {
overview: (date?: string) => ['dashboard', 'overview', date ?? 'default'] as const,
}
export function useDashboardOverview(date?: string) {
return useQuery({
queryKey: dashboardQueryKeys.overview(date),
queryFn: () => getApiData<DashboardOverview>(date ? `/dashboard/overview?date=${date}` : '/dashboard/overview'),
})
}
export function downloadDailyReportArchive(date?: string) {
return getBlob(date ? `/dashboard/daily-report/archive?date=${date}` : '/dashboard/daily-report/archive')
}

View File

@@ -0,0 +1,38 @@
import { RightOutline } from 'antd-mobile-icons'
import { formatMoney, formatNumber } from '../../../utils/format'
import type { RankItem } from '../types'
type RankListProps = {
title: string
items: RankItem[]
valueType?: 'money' | 'number'
}
export function RankList({ title, items, valueType = 'money' }: RankListProps) {
return (
<section className="section-block">
<div className="section-title-row">
<div>
<p className="section-kicker">Top 3</p>
<h2>{title}</h2>
</div>
<button className="text-button" type="button">
<RightOutline />
</button>
</div>
<div className="rank-list">
{items.map((item, index) => (
<button className="rank-item" key={item.id} type="button">
<span className="rank-index">{index + 1}</span>
<span className="rank-content">
<strong>{item.name}</strong>
<small>{item.description}</small>
</span>
<span className="rank-value">{valueType === 'money' ? formatMoney(item.value) : formatNumber(item.value)}</span>
</button>
))}
</div>
</section>
)
}

View File

@@ -0,0 +1,42 @@
import { Tag } from 'antd-mobile'
import type { RiskAlert, RiskLevel } from '../types'
type RiskAlertSectionProps = {
risks: RiskAlert[]
}
const levelMeta: Record<RiskLevel, { color: 'danger' | 'warning' | 'default'; label: string }> = {
red: { color: 'danger', label: '红色' },
yellow: { color: 'warning', label: '黄色' },
gray: { color: 'default', label: '灰色' },
}
export function RiskAlertSection({ risks }: RiskAlertSectionProps) {
return (
<section className="section-block">
<div className="section-title-row">
<div>
<p className="section-kicker">Risk</p>
<h2></h2>
</div>
<span className="risk-count">{risks.length} </span>
</div>
<div className="risk-list">
{risks.map((risk) => {
const meta = levelMeta[risk.level]
return (
<button className="risk-item" key={risk.id} type="button">
<div className="risk-header">
<Tag color={meta.color}>{meta.label}</Tag>
<span>{risk.type}</span>
<time>{risk.discoveredAt}</time>
</div>
<strong>{risk.title}</strong>
<p>{risk.description}</p>
</button>
)
})}
</div>
</section>
)
}

View File

@@ -0,0 +1,64 @@
import { CapsuleTabs, Tag } from 'antd-mobile'
import { useState } from 'react'
import { formatMoney, formatNumber } from '../../../utils/format'
import type { SnapshotSlot, TodaySnapshot } from '../types'
type TodaySnapshotSectionProps = {
snapshots: TodaySnapshot[]
}
const statusMap = {
pending: { color: 'default', label: '待生成' },
success: { color: 'success', label: '已生成' },
failed: { color: 'danger', label: '生成失败' },
temporary: { color: 'warning', label: '临时数据' },
} as const
export function TodaySnapshotSection({ snapshots }: TodaySnapshotSectionProps) {
const [activeSlot, setActiveSlot] = useState<SnapshotSlot>('1015')
const activeSnapshot = snapshots.find((snapshot) => snapshot.slot === activeSlot) ?? snapshots[0]
const status = statusMap[activeSnapshot.status]
return (
<section className="section-block snapshot-section">
<div className="section-title-row">
<div>
<p className="section-kicker"></p>
<h2> / </h2>
</div>
<Tag color={status.color}>{status.label}</Tag>
</div>
<CapsuleTabs activeKey={activeSlot} onChange={(key) => setActiveSlot(key as SnapshotSlot)}>
{snapshots.map((snapshot) => (
<CapsuleTabs.Tab title={snapshot.title.replace(' ', '')} key={snapshot.slot} />
))}
</CapsuleTabs>
<div className="snapshot-card">
<p className="snapshot-message">{activeSnapshot.message}</p>
{activeSnapshot.generatedAt && <p className="snapshot-time">{activeSnapshot.generatedAt}</p>}
<div className="snapshot-grid">
<span>
<strong>{formatNumber(activeSnapshot.purchaseUsers)}</strong>
</span>
<span>
<strong>{formatNumber(activeSnapshot.orderCount)}</strong>
</span>
<span>
<strong>{formatMoney(activeSnapshot.dealAmount)}</strong>
</span>
<span>
<strong>{formatMoney(activeSnapshot.paidAmount)}</strong>
</span>
<span>
<strong>{formatNumber(activeSnapshot.newMerchandiseCount)}</strong>
</span>
<span>
<strong>{formatMoney(Number(activeSnapshot.selfBonusChange) + Number(activeSnapshot.shareBonusChange))}</strong>
</span>
</div>
</div>
</section>
)
}

View File

@@ -0,0 +1,104 @@
import type { DashboardOverview } from './types'
export const dashboardMock: DashboardOverview = {
businessDate: '2026-05-10',
generatedAt: '2026-05-11 00:10:12',
summary: '昨日成交保持稳定,采购用户略有增长;资金风险主要集中在大额待提现和积分比例异常。',
kpis: [
{ key: 'dealAmount', title: '昨日成交额', value: 1289360.42, unit: '元', trendLabel: '较前日', trendValue: 8.6, status: 'success', featured: true },
{ key: 'orderCount', title: '昨日订单数', value: 1842, unit: '单', trendLabel: '较前日', trendValue: 4.1, status: 'success' },
{ key: 'purchaseUsers', title: '采购用户', value: 936, unit: '人', trendLabel: '较前日', trendValue: 2.7, status: 'success' },
{ key: 'newUsers', title: '新增用户', value: 318, unit: '人', trendLabel: '较前日', trendValue: -3.2, status: 'warning' },
{ key: 'newMerchandise', title: '新增寄售商品', value: 472, unit: '件', trendLabel: '较前日', trendValue: 12.4, status: 'success' },
{ key: 'selfBonus', title: '个人奖金发放', value: 168230.36, unit: '元', trendLabel: '较前日', trendValue: 6.8, status: 'normal' },
{ key: 'shareBonus', title: '推广奖金发放', value: 82460.18, unit: '元', trendLabel: '较前日', trendValue: 1.9, status: 'normal' },
{ key: 'pendingAmount', title: '待支付/待结算', value: 95620.11, unit: '元', trendLabel: '需关注', status: 'warning' },
],
fundPool: [
{ key: 'balance', title: '余额总额', value: 728903.22, unit: '元', status: 'normal' },
{ key: 'coupon', title: '优惠券总额', value: 391082.88, unit: '元', status: 'normal' },
{ key: 'selfBonusPool', title: '个人奖金总额', value: 836942.14, unit: '元', status: 'warning' },
{ key: 'shareBonusPool', title: '推广奖金总额', value: 295402.77, unit: '元', status: 'normal' },
{ key: 'integral', title: '积分总额', value: 418471.07, unit: '分', status: 'normal' },
{ key: 'withdrawPending', title: '待审核提现', value: 63200, unit: '元', status: 'danger' },
],
snapshots: [
{
slot: '1015',
title: '10:15 上午快报',
status: 'success',
generatedAt: '2026-05-11 10:15:08',
message: '上午抢购节点已完成,上一日寄卖商品消化情况良好,采购用户和成交额略高于昨日同节点。',
purchaseUsers: 421,
orderCount: 756,
dealAmount: 526880.2,
paidAmount: 498320.5,
newMerchandiseCount: 185,
selfBonusChange: 64230.3,
shareBonusChange: 31820.1,
},
{
slot: '1455',
title: '14:55 下午快报',
status: 'pending',
message: '下午寄卖/转卖节点尚未生成,预计 14:55 后可查看用户抢购商品的再次上架情况。',
purchaseUsers: 0,
orderCount: 0,
dealAmount: 0,
paidAmount: 0,
newMerchandiseCount: 0,
selfBonusChange: 0,
shareBonusChange: 0,
},
],
trends: [
{ date: '05-04', amount: 948000, orders: 1390, newUsers: 226, bonus: 186000 },
{ date: '05-05', amount: 1024000, orders: 1512, newUsers: 251, bonus: 194000 },
{ date: '05-06', amount: 1119000, orders: 1604, newUsers: 287, bonus: 205000 },
{ date: '05-07', amount: 1086000, orders: 1542, newUsers: 243, bonus: 198000 },
{ date: '05-08', amount: 1198000, orders: 1731, newUsers: 302, bonus: 221000 },
{ date: '05-09', amount: 1187200, orders: 1769, newUsers: 329, bonus: 229000 },
{ date: '05-10', amount: 1289360, orders: 1842, newUsers: 318, bonus: 250690 },
],
userRanks: [
{ id: 'u1', name: '刘先生', value: 96520, description: '个人奖金 + 推广奖金 + 积分折算', badge: '高价值' },
{ id: 'u2', name: '陈女士', value: 81230, description: '昨日采购 12 单', badge: '活跃' },
{ id: 'u3', name: '周先生', value: 75880, description: '团队新增 18 人' },
],
teamRanks: [
{ id: 't1', name: '华东一队', value: 386200, description: '成交额第一,团队收益 4.8 万', badge: 'TOP1' },
{ id: 't2', name: '苏州团队', value: 318760, description: '采购用户 182 人' },
{ id: 't3', name: '扬州团队', value: 287500, description: '新增成员 36 人' },
],
productRanks: [
{ id: 'p1', name: '高端礼盒 A 款', value: 128800, description: '上架 7 天未成交', badge: '滞销' },
{ id: 'p2', name: '精选组合 B 款', value: 98600, description: '高货值待成交' },
{ id: 'p3', name: '会员专享 C 款', value: 83500, description: '浏览高,成交低' },
],
risks: [
{
id: 'r1',
level: 'red',
type: '资金',
title: '大额待审核提现',
description: '当前待审核提现 6.32 万,建议今日处理。',
discoveredAt: '11:00',
},
{
id: 'r2',
level: 'yellow',
type: '积分',
title: '积分与个人奖金比例异常',
description: '发现 3 名用户积分未接近个人奖金的 1/2。',
discoveredAt: '10:40',
},
{
id: 'r3',
level: 'gray',
type: '数据',
title: '用户资料不一致',
description: 'wa_users 与 eb_user 有 5 条手机号不一致。',
discoveredAt: '09:55',
},
],
}

View File

@@ -0,0 +1,105 @@
import { Button, DotLoading, ErrorBlock } from 'antd-mobile'
import { KpiCard } from '../../../components/kpi/KpiCard'
import { MiniTrendChart } from '../../../components/charts/MiniTrendChart'
import { formatMoney } from '../../../utils/format'
import { useDashboardOverview } from '../api'
import { RankList } from '../components/RankList'
import { RiskAlertSection } from '../components/RiskAlertSection'
import { TodaySnapshotSection } from '../components/TodaySnapshotSection'
export function BossDashboardPage() {
const { data, isLoading, isError, refetch } = useDashboardOverview()
if (isLoading) {
return (
<section className="loading-page">
<DotLoading color="primary" />
<p>...</p>
</section>
)
}
if (isError || !data) {
return (
<section className="error-page">
<ErrorBlock status="default" title="驾驶舱加载失败" description="后端接口暂不可用,请确认服务、登录态或接口权限后重试。" />
<Button color="primary" onClick={() => void refetch()}>
</Button>
</section>
)
}
const coreKpis = data.kpis.slice(0, 4)
const moreKpis = data.kpis.slice(4)
return (
<section className="dashboard-page">
<header className="dashboard-hero">
<div className="hero-topline">
<span></span>
<button type="button"></button>
</div>
<p className="eyebrow"> {data.businessDate}</p>
<h1></h1>
<p className="hero-summary">{data.summary}</p>
<div className="hero-metric">
<span></span>
<strong>{formatMoney(data.kpis[0]?.value)}</strong>
<small>{data.generatedAt}</small>
</div>
</header>
<section className="kpi-grid" aria-label="核心经营指标">
{coreKpis.map((metric) => (
<KpiCard key={metric.key} metric={metric} />
))}
</section>
<section className="section-block compact-section">
<div className="section-title-row">
<div>
<p className="section-kicker">More</p>
<h2></h2>
</div>
</div>
<div className="kpi-grid kpi-grid--compact">
{moreKpis.map((metric) => (
<KpiCard key={metric.key} metric={metric} />
))}
</div>
</section>
<TodaySnapshotSection snapshots={data.snapshots} />
<section className="section-block">
<div className="section-title-row">
<div>
<p className="section-kicker">Trend</p>
<h2> 7 </h2>
</div>
</div>
<MiniTrendChart data={data.trends} />
</section>
<section className="section-block compact-section">
<div className="section-title-row">
<div>
<p className="section-kicker">Fund</p>
<h2></h2>
</div>
</div>
<div className="kpi-grid kpi-grid--compact">
{data.fundPool.map((metric) => (
<KpiCard key={metric.key} metric={metric} />
))}
</div>
</section>
<RankList title="高价值用户" items={data.userRanks} />
<RankList title="团队贡献排行" items={data.teamRanks} />
<RankList title="高货值未成交商品" items={data.productRanks} />
<RiskAlertSection risks={data.risks} />
</section>
)
}

View File

@@ -0,0 +1,468 @@
import { Button, CapsuleTabs, DotLoading, ErrorBlock, Tag, Toast } from 'antd-mobile'
import { useMemo, useState } from 'react'
import { MiniTrendChart } from '../../../components/charts/MiniTrendChart'
import { KpiCard } from '../../../components/kpi/KpiCard'
import { formatMoney, formatNumber } from '../../../utils/format'
import { downloadDailyReportArchive, useDashboardOverview } from '../api'
import type { DashboardOverview, RiskLevel, SnapshotSlot, TodaySnapshot } from '../types'
const snapshotStatusMeta = {
pending: { color: 'default', label: '待生成' },
success: { color: 'success', label: '已生成' },
failed: { color: 'danger', label: '失败' },
temporary: { color: 'warning', label: '临时' },
} as const
const riskLevelMeta: Record<RiskLevel, { color: 'danger' | 'warning' | 'default'; label: string }> = {
red: { color: 'danger', label: '红色' },
yellow: { color: 'warning', label: '黄色' },
gray: { color: 'default', label: '灰色' },
}
const snapshotSlotMeta: Record<
SnapshotSlot,
{
title: string
subtitle: string
metricLabels: {
primaryUsers: string
primaryOrders: string
amount: string
paidAmount: string
merchandise: string
bonus: string
}
checklist: string[]
}
> = {
'1015': {
title: '上午抢购快报',
subtitle: '用户集中抢购上一天用户寄卖的商品,重点看成交、付款和采购用户是否达标。',
metricLabels: {
primaryUsers: '抢购用户',
primaryOrders: '抢购订单',
amount: '抢购成交额',
paidAmount: '已支付金额',
merchandise: '成交商品',
bonus: '相关奖金',
},
checklist: ['抢购成交额是否低于昨日同节点', '采购用户是否异常回落', '付款金额与成交额是否明显偏离', '高货值寄卖商品是否完成消化'],
},
'1455': {
title: '下午寄卖/转卖快报',
subtitle: '用户把上午抢到的商品继续寄卖或转卖,重点看新增寄售供给和奖金变化是否正常。',
metricLabels: {
primaryUsers: '寄卖用户',
primaryOrders: '转卖订单',
amount: '转卖成交额',
paidAmount: '回款金额',
merchandise: '新增寄售',
bonus: '奖金变化',
},
checklist: ['抢购商品是否按预期转入寄卖', '新增寄售商品是否满足下午供给', '个人奖金与推广奖金是否同步变化', '转卖回款是否出现异常延迟'],
},
}
function QueryState({
isLoading,
isError,
refetch,
title,
}: {
isLoading: boolean
isError: boolean
refetch: () => void
title: string
}) {
if (isLoading) {
return (
<section className="loading-page">
<DotLoading color="primary" />
<p>{title}...</p>
</section>
)
}
if (isError) {
return (
<section className="error-page">
<ErrorBlock status="default" title={`${title}加载失败`} description="后端接口暂不可用,请确认服务、登录态或接口权限后重试。" />
<Button color="primary" onClick={refetch}>
</Button>
</section>
)
}
return null
}
function OperationsHeader({
kicker,
title,
description,
extra,
}: {
kicker: string
title: string
description: string
extra?: string
}) {
return (
<header className="operations-header">
<p className="eyebrow">{kicker}</p>
<h1>{title}</h1>
<p>{description}</p>
{extra && <span>{extra}</span>}
</header>
)
}
function SnapshotDetailCard({ snapshot }: { snapshot: TodaySnapshot }) {
const status = snapshotStatusMeta[snapshot.status]
const slotMeta = snapshotSlotMeta[snapshot.slot]
return (
<article className="snapshot-detail-card">
<div className="section-title-row">
<div>
<p className="section-kicker">{snapshot.slot}</p>
<h2>{slotMeta.title}</h2>
</div>
<Tag color={status.color}>{status.label}</Tag>
</div>
<p className="snapshot-detail-subtitle">{slotMeta.subtitle}</p>
<p className="snapshot-detail-message">{snapshot.message}</p>
{snapshot.generatedAt && <p className="snapshot-time">{snapshot.generatedAt}</p>}
<div className="snapshot-grid snapshot-grid--wide">
<span>
{slotMeta.metricLabels.primaryUsers}
<strong>{formatNumber(snapshot.purchaseUsers)}</strong>
</span>
<span>
{slotMeta.metricLabels.primaryOrders}
<strong>{formatNumber(snapshot.orderCount)}</strong>
</span>
<span>
{slotMeta.metricLabels.amount}
<strong>{formatMoney(snapshot.dealAmount)}</strong>
</span>
<span>
{slotMeta.metricLabels.paidAmount}
<strong>{formatMoney(snapshot.paidAmount)}</strong>
</span>
<span>
{slotMeta.metricLabels.merchandise}
<strong>{formatNumber(snapshot.newMerchandiseCount)}</strong>
</span>
<span>
{slotMeta.metricLabels.bonus}
<strong>{formatMoney(Number(snapshot.selfBonusChange) + Number(snapshot.shareBonusChange))}</strong>
</span>
</div>
</article>
)
}
function buildDailyReports(data: DashboardOverview) {
return data.trends
.slice(-4)
.reverse()
.map((trend, index) => ({
...trend,
status: index === 0 ? '已生成' : '历史快照',
bonusRate: Number(trend.amount) > 0 ? (Number(trend.bonus) / Number(trend.amount)) * 100 : 0,
}))
}
export function DailyReportPage() {
const { data, isLoading, isError, refetch } = useDashboardOverview()
const [isArchiving, setIsArchiving] = useState(false)
const state = <QueryState isLoading={isLoading} isError={isError || !data} refetch={() => void refetch()} title="经营日报" />
if (!data) return state
const reports = buildDailyReports(data)
const handleArchive = async () => {
try {
setIsArchiving(true)
const blob = await downloadDailyReportArchive(data.businessDate)
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = `dashboard-daily-report-${data.businessDate}.html`
document.body.appendChild(link)
link.click()
link.remove()
URL.revokeObjectURL(url)
Toast.show({ icon: 'success', content: '归档 HTML 已生成' })
} catch {
Toast.show({ icon: 'fail', content: '归档生成失败,请稍后重试' })
} finally {
setIsArchiving(false)
}
}
return (
<section className="operations-page">
<OperationsHeader
kicker="Daily Report"
title="经营日报"
description="按日沉淀成交、订单、用户与奖金变化,方便老板回看最近经营节奏。"
extra={`最新数据:${data.businessDate}`}
/>
<section className="section-block compact-section">
<div className="section-title-row">
<div>
<p className="section-kicker">Workday</p>
<h2></h2>
</div>
<Tag color="success"></Tag>
</div>
<div className="kpi-grid kpi-grid--compact">
{data.kpis.slice(0, 4).map((metric) => (
<KpiCard key={metric.key} metric={metric} />
))}
</div>
</section>
<section className="section-block">
<div className="section-title-row">
<div>
<p className="section-kicker">Trend</p>
<h2> 7 </h2>
</div>
</div>
<MiniTrendChart data={data.trends} />
</section>
<section className="section-block">
<div className="section-title-row">
<div>
<p className="section-kicker">Archive</p>
<h2></h2>
</div>
<button className="text-button" type="button" disabled={isArchiving} onClick={() => void handleArchive()}>
{isArchiving ? '生成中...' : '生成归档'}
</button>
</div>
<div className="report-list">
{reports.map((report) => (
<button className="report-item" key={report.date} type="button">
<span>
<strong>{report.date}</strong>
<small>{report.status}</small>
</span>
<span>
<strong>{formatMoney(report.amount)}</strong>
<small>
{formatNumber(report.orders)} / {formatNumber(report.bonusRate, 1)}%
</small>
</span>
</button>
))}
</div>
</section>
</section>
)
}
export function TodaySnapshotPage() {
const { data, isLoading, isError, refetch } = useDashboardOverview()
const state = <QueryState isLoading={isLoading} isError={isError || !data} refetch={() => void refetch()} title="今日快报" />
if (!data) return state
return (
<section className="operations-page">
<OperationsHeader
kicker="Today Snapshot"
title="今日快报"
description="10:15 看上一日寄卖商品的抢购结果14:55 看抢到商品的寄卖/转卖承接情况。"
extra="节点状态随 Mock 场景切换"
/>
<section className="section-block snapshot-page-section">
<div className="section-title-row">
<div>
<p className="section-kicker">Timeline</p>
<h2></h2>
</div>
</div>
<div className="snapshot-stack">
{data.snapshots.map((snapshot) => (
<SnapshotDetailCard key={snapshot.slot} snapshot={snapshot} />
))}
</div>
</section>
<section className="section-block">
<div className="section-title-row">
<div>
<p className="section-kicker">Checklist</p>
<h2></h2>
</div>
</div>
<div className="check-list">
{data.snapshots.flatMap((snapshot) =>
snapshotSlotMeta[snapshot.slot].checklist.map((item) => (
<span key={`${snapshot.slot}-${item}`}>
<strong>{snapshot.slot === '1015' ? '上午' : '下午'}</strong>
{item}
</span>
)),
)}
</div>
</section>
</section>
)
}
export function RiskCenterPage() {
const { data, isLoading, isError, refetch } = useDashboardOverview()
const [activeLevel, setActiveLevel] = useState<RiskLevel | 'all'>('all')
const state = <QueryState isLoading={isLoading} isError={isError || !data} refetch={() => void refetch()} title="风险中心" />
const filteredRisks = useMemo(() => {
if (!data) return []
if (activeLevel === 'all') return data.risks
return data.risks.filter((risk) => risk.level === activeLevel)
}, [activeLevel, data])
if (!data) return state
const dangerousFunds = data.fundPool.filter((metric) => metric.status === 'warning' || metric.status === 'danger')
return (
<section className="operations-page">
<OperationsHeader
kicker="Risk Center"
title="风险中心"
description="把资金、积分与数据一致性风险集中处理,优先看红色和黄色事项。"
extra={`${data.risks.length} 条待关注`}
/>
<section className="risk-summary-grid" aria-label="风险概览">
{(['red', 'yellow', 'gray'] as const).map((level) => {
const meta = riskLevelMeta[level]
const count = data.risks.filter((risk) => risk.level === level).length
return (
<button className={`risk-summary-card risk-summary-card--${level}`} key={level} type="button" onClick={() => setActiveLevel(level)}>
<Tag color={meta.color}>{meta.label}</Tag>
<strong>{count}</strong>
<span></span>
</button>
)
})}
</section>
<section className="section-block">
<CapsuleTabs activeKey={activeLevel} onChange={(key) => setActiveLevel(key as RiskLevel | 'all')}>
<CapsuleTabs.Tab title="全部" key="all" />
<CapsuleTabs.Tab title="红色" key="red" />
<CapsuleTabs.Tab title="黄色" key="yellow" />
<CapsuleTabs.Tab title="灰色" key="gray" />
</CapsuleTabs>
<div className="risk-list">
{filteredRisks.map((risk) => {
const meta = riskLevelMeta[risk.level]
return (
<button className="risk-item" key={risk.id} type="button">
<div className="risk-header">
<Tag color={meta.color}>{meta.label}</Tag>
<span>{risk.type}</span>
<time>{risk.discoveredAt}</time>
</div>
<strong>{risk.title}</strong>
<p>{risk.description}</p>
</button>
)
})}
</div>
</section>
<section className="section-block compact-section">
<div className="section-title-row">
<div>
<p className="section-kicker">Fund Watch</p>
<h2></h2>
</div>
</div>
<div className="kpi-grid kpi-grid--compact">
{dangerousFunds.map((metric) => (
<KpiCard key={metric.key} metric={metric} />
))}
</div>
</section>
</section>
)
}
export function ProfilePage() {
const { data, isLoading, isError, refetch } = useDashboardOverview()
const state = <QueryState isLoading={isLoading} isError={isError || !data} refetch={() => void refetch()} title="我的" />
if (!data) return state
return (
<section className="operations-page">
<OperationsHeader
kicker="Profile"
title="我的"
description="展示当前驾驶舱权限、数据环境与演示版本,方便联调时确认口径。"
extra="老板驾驶舱 H5"
/>
<section className="profile-card">
<div className="profile-avatar" aria-hidden="true">
</div>
<div>
<h2></h2>
<p></p>
</div>
</section>
<section className="section-block">
<div className="section-title-row">
<div>
<p className="section-kicker">Environment</p>
<h2></h2>
</div>
<Tag color="warning">Mock</Tag>
</div>
<div className="info-list">
<span>
<small></small>
<strong>{data.businessDate}</strong>
</span>
<span>
<small></small>
<strong>{data.generatedAt}</strong>
</span>
<span>
<small>API </small>
<strong>{import.meta.env.VITE_MOCK_ENABLED === 'false' ? '真实接口' : 'Mock 演示'}</strong>
</span>
</div>
</section>
<section className="section-block">
<div className="section-title-row">
<div>
<p className="section-kicker">Permissions</p>
<h2></h2>
</div>
</div>
<div className="check-list">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</section>
</section>
)
}

View File

@@ -0,0 +1,72 @@
export type MetricStatus = 'normal' | 'success' | 'warning' | 'danger'
export type SnapshotStatus = 'pending' | 'success' | 'failed' | 'temporary'
export type SnapshotSlot = '1015' | '1455'
export type KpiMetric = {
key: string
title: string
value: number | string | null
unit?: string
trendLabel?: string
trendValue?: number | string
status: MetricStatus
featured?: boolean
}
export type TodaySnapshot = {
slot: SnapshotSlot
title: string
status: SnapshotStatus
generatedAt?: string
message: string
purchaseUsers: number
orderCount: number
dealAmount: number | string
paidAmount: number | string
newMerchandiseCount: number
selfBonusChange: number | string
shareBonusChange: number | string
}
export type TrendPoint = {
date: string
amount: number | string
orders: number
newUsers: number
bonus: number | string
}
export type RankItem = {
id: string
name: string
value: number | string
description: string
badge?: string
}
export type RiskLevel = 'red' | 'yellow' | 'gray'
export type RiskAlert = {
id: string
level: RiskLevel
type: string
title: string
description: string
discoveredAt: string
}
export type DashboardOverview = {
businessDate: string
generatedAt: string
summary: string
kpis: KpiMetric[]
fundPool: KpiMetric[]
snapshots: TodaySnapshot[]
trends: TrendPoint[]
userRanks: RankItem[]
teamRanks: RankItem[]
productRanks: RankItem[]
risks: RiskAlert[]
}

View File

@@ -0,0 +1,18 @@
import { Empty } from 'antd-mobile'
type PlaceholderPageProps = {
title: string
description: string
}
export function PlaceholderPage({ title, description }: PlaceholderPageProps) {
return (
<section className="placeholder-page">
<div className="mobile-page-header">
<p className="eyebrow"></p>
<h1>{title}</h1>
</div>
<Empty description={description} />
</section>
)
}

View File

@@ -0,0 +1,589 @@
:root {
--bg: #fff6f1;
--surface: #ffffff;
--surface-soft: #f6f9fb;
--text: #132033;
--muted: #6b7a90;
--border: rgba(19, 32, 51, 0.08);
--primary: #ff5b36;
--primary-deep: #f04a2a;
--primary-soft: #fff0eb;
--success: #14a46c;
--warning: #ffb000;
--danger: #dc2626;
--shadow: 0 16px 40px rgba(255, 91, 54, 0.14);
--radius-xl: 28px;
--radius-lg: 20px;
--radius-md: 14px;
font-family:
ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
--adm-color-primary: var(--primary);
color: var(--text);
background: var(--bg);
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-width: 320px;
background:
radial-gradient(circle at top left, rgba(255, 91, 54, 0.2), transparent 28rem),
var(--bg);
}
button {
font: inherit;
}
button:focus-visible {
outline: 2px solid rgba(255, 91, 54, 0.72);
outline-offset: 2px;
}
#root {
width: min(100%, 430px);
min-height: 100svh;
margin: 0 auto;
background: var(--bg);
box-shadow: 0 0 0 1px rgba(19, 32, 51, 0.04);
}
.mobile-shell {
min-height: 100svh;
position: relative;
}
.mobile-main {
min-height: 100svh;
padding-bottom: calc(74px + env(safe-area-inset-bottom));
}
.bottom-nav {
position: fixed;
right: 0;
bottom: 0;
left: 0;
z-index: 20;
width: min(100%, 430px);
margin: 0 auto;
background: rgba(255, 255, 255, 0.94);
border-top: 1px solid var(--border);
backdrop-filter: blur(16px);
}
.dashboard-page {
padding: 14px 14px 24px;
}
.dashboard-hero {
position: relative;
overflow: hidden;
padding: 20px;
color: #fff;
background:
linear-gradient(145deg, rgba(255, 91, 54, 0.98), rgba(255, 139, 82, 0.92)),
radial-gradient(circle at 90% 10%, rgba(255, 176, 0, 0.42), transparent 18rem);
border-radius: 0 0 var(--radius-xl) var(--radius-xl);
box-shadow: var(--shadow);
}
.hero-topline,
.section-title-row,
.risk-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.hero-topline span,
.eyebrow,
.section-kicker {
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hero-topline button {
min-height: 34px;
padding: 0 14px;
color: #fff;
background: rgba(255, 255, 255, 0.16);
border: 1px solid rgba(255, 255, 255, 0.24);
border-radius: 999px;
}
.dashboard-hero h1 {
margin: 18px 0 8px;
font-size: 30px;
line-height: 1.1;
}
.hero-summary {
margin: 0;
color: rgba(255, 255, 255, 0.78);
font-size: 14px;
line-height: 1.6;
}
.hero-metric {
margin-top: 20px;
padding: 16px;
background: rgba(255, 255, 255, 0.14);
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: var(--radius-lg);
}
.hero-metric span,
.hero-metric small {
display: block;
color: rgba(255, 255, 255, 0.72);
font-size: 12px;
}
.hero-metric strong {
display: block;
margin: 6px 0;
font-size: 32px;
line-height: 1;
}
.kpi-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
margin-top: 12px;
}
.kpi-card {
min-height: 112px;
padding: 14px;
text-align: left;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
box-shadow: 0 10px 28px rgba(22, 47, 80, 0.08);
}
.kpi-card--featured {
grid-column: span 2;
}
.kpi-title,
.kpi-trend,
.section-kicker,
.snapshot-time,
.rank-content small,
.risk-item p {
margin: 0;
color: var(--muted);
}
.kpi-value {
display: block;
margin-top: 8px;
color: var(--text);
font-size: 22px;
line-height: 1.08;
word-break: break-all;
}
.kpi-trend {
margin-top: 8px;
font-size: 12px;
}
.kpi-trend span {
margin-left: 6px;
color: var(--primary);
font-weight: 700;
}
.kpi-card--success .kpi-trend span {
color: var(--success);
}
.kpi-card--warning .kpi-trend span {
color: var(--warning);
}
.kpi-card--danger .kpi-value,
.kpi-card--danger .kpi-trend span {
color: var(--danger);
}
.section-block {
margin-top: 14px;
padding: 16px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-xl);
box-shadow: 0 10px 28px rgba(22, 47, 80, 0.08);
}
.section-title-row h2 {
margin: 2px 0 0;
font-size: 18px;
}
.compact-section .kpi-grid {
margin-top: 12px;
}
.snapshot-section .adm-capsule-tabs {
margin: 14px 0;
}
.snapshot-card {
padding: 14px;
background: var(--surface-soft);
border-radius: var(--radius-lg);
}
.snapshot-message {
margin: 0 0 8px;
font-weight: 700;
line-height: 1.5;
}
.snapshot-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
margin-top: 14px;
}
.snapshot-grid span {
min-height: 64px;
padding: 10px;
color: var(--muted);
font-size: 12px;
background: #fff;
border-radius: var(--radius-md);
}
.snapshot-grid strong {
display: block;
margin-top: 5px;
color: var(--text);
font-size: 15px;
}
.mini-trend-chart {
width: 100%;
height: 240px;
}
.text-button,
.rank-item,
.risk-item {
appearance: none;
border: 0;
background: none;
}
.text-button {
display: inline-flex;
align-items: center;
min-height: 36px;
color: var(--primary);
font-size: 13px;
font-weight: 700;
}
.text-button:disabled {
color: var(--muted);
cursor: not-allowed;
}
.rank-list,
.risk-list {
display: grid;
gap: 10px;
margin-top: 14px;
}
.rank-item,
.risk-item {
width: 100%;
min-height: 58px;
padding: 12px;
text-align: left;
background: var(--surface-soft);
border-radius: var(--radius-md);
}
.rank-item {
display: grid;
grid-template-columns: 28px 1fr auto;
align-items: center;
gap: 10px;
}
.rank-index {
display: inline-grid;
width: 26px;
height: 26px;
place-items: center;
color: #fff;
font-weight: 800;
background: var(--text);
border-radius: 10px;
}
.rank-content strong,
.rank-content small {
display: block;
}
.rank-value {
color: var(--primary);
font-size: 13px;
font-weight: 800;
}
.risk-count {
color: var(--danger);
font-weight: 800;
}
.risk-header {
justify-content: flex-start;
color: var(--muted);
font-size: 12px;
}
.risk-header time {
margin-left: auto;
}
.risk-item strong {
display: block;
margin: 10px 0 4px;
font-size: 15px;
}
.risk-item p {
line-height: 1.5;
}
.placeholder-page,
.loading-page,
.error-page {
padding: 24px 16px;
}
.mobile-page-header h1 {
margin: 4px 0 24px;
}
.operations-page {
padding: 14px 14px 24px;
}
.operations-header {
position: relative;
overflow: hidden;
padding: 20px;
color: #fff;
background:
linear-gradient(145deg, rgba(255, 91, 54, 0.98), rgba(255, 139, 82, 0.92)),
radial-gradient(circle at 90% 10%, rgba(255, 176, 0, 0.42), transparent 18rem);
border-radius: 0 0 var(--radius-xl) var(--radius-xl);
box-shadow: var(--shadow);
}
.operations-header h1 {
margin: 12px 0 8px;
font-size: 28px;
line-height: 1.12;
}
.operations-header p {
margin: 0;
color: rgba(255, 255, 255, 0.76);
line-height: 1.6;
}
.operations-header .eyebrow {
color: rgba(255, 255, 255, 0.68);
}
.operations-header span {
display: inline-flex;
margin-top: 16px;
padding: 7px 12px;
color: rgba(255, 255, 255, 0.86);
font-size: 12px;
font-weight: 700;
background: rgba(255, 255, 255, 0.14);
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 999px;
}
.report-list,
.check-list,
.info-list {
display: grid;
gap: 10px;
margin-top: 14px;
}
.report-item {
display: grid;
grid-template-columns: 82px 1fr;
gap: 12px;
width: 100%;
padding: 13px;
text-align: left;
background: var(--surface-soft);
border: 0;
border-radius: var(--radius-md);
}
.report-item span,
.info-list span {
display: grid;
gap: 4px;
}
.report-item small,
.info-list small,
.profile-card p {
color: var(--muted);
line-height: 1.45;
}
.snapshot-stack {
display: grid;
gap: 12px;
margin-top: 14px;
}
.snapshot-detail-card {
padding: 14px;
background: var(--surface-soft);
border-radius: var(--radius-lg);
}
.snapshot-detail-subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.snapshot-detail-message {
margin: 10px 0 8px;
font-weight: 700;
line-height: 1.55;
}
.snapshot-grid--wide {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.check-list span,
.info-list span {
padding: 12px;
background: var(--surface-soft);
border-radius: var(--radius-md);
}
.check-list span {
color: var(--text);
font-weight: 700;
}
.check-list strong {
margin-right: 8px;
color: var(--primary);
}
.risk-summary-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
margin-top: 12px;
}
.risk-summary-card {
display: grid;
min-height: 104px;
padding: 12px;
text-align: left;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
box-shadow: 0 10px 28px rgba(22, 47, 80, 0.08);
}
.risk-summary-card strong {
margin-top: 8px;
font-size: 28px;
line-height: 1;
}
.risk-summary-card span:last-child {
color: var(--muted);
font-size: 12px;
}
.risk-summary-card--red strong {
color: var(--danger);
}
.risk-summary-card--yellow strong {
color: var(--warning);
}
.risk-summary-card--gray strong {
color: var(--muted);
}
.profile-card {
display: grid;
grid-template-columns: 58px 1fr;
align-items: center;
gap: 14px;
margin-top: 14px;
padding: 16px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius-xl);
box-shadow: 0 10px 28px rgba(22, 47, 80, 0.08);
}
.profile-card h2,
.profile-card p {
margin: 0;
}
.profile-avatar {
display: grid;
width: 58px;
height: 58px;
place-items: center;
color: #fff;
font-size: 22px;
font-weight: 800;
background: linear-gradient(145deg, var(--primary), var(--warning));
border-radius: 22px;
}
.loading-page,
.error-page {
display: grid;
min-height: 60svh;
place-content: center;
gap: 14px;
text-align: center;
}

View File

@@ -0,0 +1,20 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import 'antd-mobile/es/global'
import './index.css'
import App from './App.tsx'
const startApp = async () => {
if (import.meta.env.VITE_MOCK_ENABLED !== 'false') {
const { worker } = await import('./services/mock/browser')
await worker.start({ onUnhandledRequest: 'bypass' })
}
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
}
void startApp()

View File

@@ -0,0 +1,26 @@
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
}

View File

@@ -0,0 +1,4 @@
import { setupWorker } from 'msw/browser'
import { handlers } from './handlers'
export const worker = setupWorker(...handlers)

View File

@@ -0,0 +1,58 @@
import { http, HttpResponse } from 'msw'
import { dashboardMock } from '../../features/boss-dashboard/mock'
function buildArchiveHtml() {
return `<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>经营日报归档 - ${dashboardMock.businessDate}</title>
<style>
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #132033; background: #fff6f1; }
main { max-width: 820px; margin: 0 auto; padding: 28px 18px 40px; }
header { color: #fff; padding: 26px; border-radius: 0 0 28px 28px; background: linear-gradient(145deg, #ff5b36, #ff8b52); }
section { margin-top: 16px; padding: 18px; background: #fff; border-radius: 24px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
article { padding: 14px; border-radius: 18px; background: #f6f9fb; }
small { color: #6b7a90; }
</style>
</head>
<body>
<main>
<header>
<p>Daily Report Archive</p>
<h1>经营日报归档</h1>
<p>${dashboardMock.summary}</p>
<small>数据日期:${dashboardMock.businessDate} / 生成时间:${dashboardMock.generatedAt}</small>
</header>
<section>
<h2>核心经营指标</h2>
<div class="grid">
${dashboardMock.kpis
.map((metric) => `<article><small>${metric.title}</small><h3>${metric.value}${metric.unit ?? ''}</h3><small>${metric.trendLabel ?? ''}</small></article>`)
.join('')}
</div>
</section>
</main>
</body>
</html>`
}
export const handlers = [
http.get('/api/admin/dashboard/overview', () => {
return HttpResponse.json({
code: 0,
msg: 'success',
data: dashboardMock,
})
}),
http.get('/api/admin/dashboard/daily-report/archive', () => {
return new HttpResponse(buildArchiveHtml(), {
headers: {
'Content-Type': 'text/html; charset=utf-8',
'Content-Disposition': `attachment; filename="dashboard-daily-report-${dashboardMock.businessDate}.html"`,
},
})
}),
]

View File

@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest'
import { formatMetricValue, formatMoney, formatNumber, formatTrend } from './format'
describe('format helpers', () => {
it('formats money with yuan symbol and two decimals', () => {
expect(formatMoney(1289360.4)).toBe('¥1,289,360.40')
})
it('formats metric values based on unit', () => {
expect(formatMetricValue(418471.07, '分')).toBe('418,471.070')
expect(formatMetricValue(936, '人')).toBe('936人')
})
it('uses placeholder for empty values', () => {
expect(formatNumber(null)).toBe('--')
})
it('adds plus sign for positive trend values', () => {
expect(formatTrend(8.6)).toBe('+8.6%')
expect(formatTrend(-3.2)).toBe('-3.2%')
})
})

View File

@@ -0,0 +1,33 @@
export function formatMoney(value: number | string | null | undefined): string {
if (value === null || value === undefined || value === '') return '--'
const numberValue = Number(value)
if (Number.isNaN(numberValue)) return String(value)
return `¥${numberValue.toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`
}
export function formatNumber(value: number | string | null | undefined, digits = 0): string {
if (value === null || value === undefined || value === '') return '--'
const numberValue = Number(value)
if (Number.isNaN(numberValue)) return String(value)
return numberValue.toLocaleString('zh-CN', {
minimumFractionDigits: digits,
maximumFractionDigits: digits,
})
}
export function formatMetricValue(value: number | string | null, unit?: string): string {
if (unit === '元') return formatMoney(value)
if (unit === '分') return formatNumber(value, 3)
return `${formatNumber(value)}${unit ?? ''}`
}
export function formatTrend(value?: number | string): string {
if (value === undefined || value === '') return ''
const numberValue = Number(value)
if (Number.isNaN(numberValue)) return String(value)
const prefix = numberValue > 0 ? '+' : ''
return `${prefix}${numberValue.toFixed(1)}%`
}