refactor(web): 拆分 PlatformRock 大屏为容器 + 9 个子组件(1306 → 最大 335 行)

- PlatformRock.tsx 335 行:保留全部 state、loadData/loadTokens、useEffect、
  handler 与顶层布局;默认导出名不变,App.tsx 的 lazy 导入未改
- platformRock/ 子目录:tokenColumns 329、RockStrategyCard 267、
  PurchaseTokenModal 183、RockTokenTable 156、RockMetricCards 124、
  VoucherPreviewModal 95、RockTokenFilterBar 76、UidEditModal 47、types.ts 6

state 归属与更新时机、请求次数与参数、useEffect 依赖语义均未改变;子组件 props
显式声明类型,无 any;行级异步 handler 随表格下沉,state setter 经显式类型 props 传入。

验证:
- SSR 快照 renderToString 拆分前后字节一致(40920 bytes)
- jsdom 交互差分:拆分前后 23 个检查点的 DOM 快照与 API 调用日志完全一致
  (覆盖采购、UID 修正、解冻、释放、熔断、筛选/搜索/翻页、保存配置、连通性测试)
- 原文件应保留的 230 行代码逐字命中
This commit is contained in:
yml2213
2026-10-06 19:43:29 +08:00
parent c9e35d5d90
commit b1089f37b2
10 changed files with 1367 additions and 1055 deletions
@@ -0,0 +1,124 @@
import { Col, Row, Tag } from 'antd'
import {
CheckCircleOutlined,
ExclamationCircleOutlined,
FireOutlined,
ShoppingCartOutlined,
} from '@ant-design/icons'
import type { RockStats } from '../../api'
export interface RockMetricCardsProps {
stats: RockStats | null
availableStock: number
warningStock: number
isStockLow: boolean
hasMismatch: boolean
upstreamPoints: number
maxPurchasable: number
onOpenPurchase: (count: number) => void
}
export function RockMetricCards({
stats,
availableStock,
warningStock,
isStockLow,
hasMismatch,
upstreamPoints,
maxPurchasable,
onOpenPurchase,
}: RockMetricCardsProps) {
return (
<Row gutter={[16, 16]} style={{ marginBottom: 20 }}>
<Col xs={24} sm={12} lg={6}>
<div className="metric-card-box">
<div className="metric-card-header">
<span className="metric-card-title">可用通用库存 (Available)</span>
<div className={`metric-card-icon ${isStockLow ? 'metric-card-icon--rose' : ''}`}>
<ShoppingCartOutlined />
</div>
</div>
<div className="metric-card-value" style={{ color: isStockLow ? '#e11d48' : '#0f172a' }}>
{availableStock}
<span style={{ fontSize: 13, fontWeight: 500, marginLeft: 4, color: '#64748b' }}>个</span>
</div>
<div className="metric-card-footer">
<span>警戒水位: {warningStock} 个</span>
{isStockLow ? (
<Tag color="error" style={{ margin: 0, borderRadius: 4 }}>库存紧缺</Tag>
) : (
<span style={{ color: '#10b981', fontWeight: 600 }}>储备充足</span>
)}
</div>
</div>
</Col>
<Col xs={24} sm={12} lg={6}>
<div className="metric-card-box">
<div className="metric-card-header">
<span className="metric-card-title">绑定错误阻断 (Mismatch)</span>
<div className={`metric-card-icon ${hasMismatch ? 'metric-card-icon--rose' : ''}`}>
<ExclamationCircleOutlined />
</div>
</div>
<div className="metric-card-value" style={{ color: hasMismatch ? '#e11d48' : '#0f172a' }}>
{stats?.mismatch_stock ?? 0}
<span style={{ fontSize: 13, fontWeight: 500, marginLeft: 4, color: '#64748b' }}>个</span>
</div>
<div className="metric-card-footer">
<span>{hasMismatch ? 'UID强一致校验拦截保护' : '暂无异常阻断'}</span>
{hasMismatch ? (
<Tag color="error" style={{ margin: 0, borderRadius: 4 }}>需核对处理</Tag>
) : (
<span style={{ color: '#10b981', fontWeight: 600 }}>状态正常</span>
)}
</div>
</div>
</Col>
<Col xs={24} sm={12} lg={6}>
<div className="metric-card-box">
<div className="metric-card-header">
<span className="metric-card-title">已履约交付 (Redeemed)</span>
<div className="metric-card-icon metric-card-icon--emerald">
<CheckCircleOutlined />
</div>
</div>
<div className="metric-card-value">
{stats?.redeemed_stock ?? 0}
<span style={{ fontSize: 13, fontWeight: 500, marginLeft: 4, color: '#64748b' }}>个</span>
</div>
<div className="metric-card-footer">
<span>当前扫码中</span>
<span style={{ fontWeight: 600, color: '#2563eb' }}>{stats?.using_stock ?? 0} 个</span>
</div>
</div>
</Col>
<Col xs={24} sm={12} lg={6}>
<div className="metric-card-box">
<div className="metric-card-header">
<span className="metric-card-title">0666.pro 账号积分</span>
<div className="metric-card-icon metric-card-icon--purple">
<FireOutlined />
</div>
</div>
<div className="metric-card-value" style={{ color: '#7c3aed' }}>
{upstreamPoints.toFixed(1)}
<span style={{ fontSize: 13, fontWeight: 500, marginLeft: 4, color: '#64748b' }}>点</span>
</div>
<div className="metric-card-footer">
<span>账号: {stats?.username || '未同步'}</span>
<a
onClick={() => onOpenPurchase(maxPurchasable > 0 ? Math.min(50, maxPurchasable) : 10)}
style={{ fontWeight: 600, color: '#2563eb', cursor: 'pointer' }}
title="点击快速打开手动采购弹窗"
>
约可采购 {maxPurchasable} 个 ➔
</a>
</div>
</div>
</Col>
</Row>
)
}