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:
@@ -0,0 +1,183 @@
|
||||
import { Button, Col, Divider, InputNumber, Modal, Row, Space } from 'antd'
|
||||
import { ShoppingCartOutlined } from '@ant-design/icons'
|
||||
import type { RockStats } from '../../api'
|
||||
|
||||
export interface PurchaseTokenModalProps {
|
||||
open: boolean
|
||||
stats: RockStats | null
|
||||
purchaseCount: number
|
||||
purchasing: boolean
|
||||
maxPurchasable: number
|
||||
upstreamPoints: number
|
||||
estimatedCost: number
|
||||
isPointsInsufficient: boolean
|
||||
onPurchaseCountChange: (value: number) => void
|
||||
onCancel: () => void
|
||||
onConfirm: (count: number) => void
|
||||
}
|
||||
|
||||
export function PurchaseTokenModal({
|
||||
open,
|
||||
stats,
|
||||
purchaseCount,
|
||||
purchasing,
|
||||
maxPurchasable,
|
||||
upstreamPoints,
|
||||
estimatedCost,
|
||||
isPointsInsufficient,
|
||||
onPurchaseCountChange,
|
||||
onCancel,
|
||||
onConfirm,
|
||||
}: PurchaseTokenModalProps) {
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<Space>
|
||||
<ShoppingCartOutlined style={{ color: '#2563eb' }} />
|
||||
<span>手动采购通用黑色 Token (0666.pro)</span>
|
||||
</Space>
|
||||
}
|
||||
open={open}
|
||||
onCancel={onCancel}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={onCancel}>
|
||||
取消
|
||||
</Button>,
|
||||
<Button
|
||||
key="submit"
|
||||
type="primary"
|
||||
icon={<ShoppingCartOutlined />}
|
||||
loading={purchasing}
|
||||
disabled={isPointsInsufficient || purchaseCount <= 0}
|
||||
onClick={() => onConfirm(purchaseCount)}
|
||||
style={{
|
||||
background: isPointsInsufficient
|
||||
? undefined
|
||||
: 'linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%)',
|
||||
}}
|
||||
>
|
||||
确认采购 {purchaseCount} 个 ({estimatedCost} 点)
|
||||
</Button>,
|
||||
]}
|
||||
destroyOnClose
|
||||
width={500}
|
||||
>
|
||||
<div style={{ marginTop: 16 }}>
|
||||
{/* 账户与资产概览 */}
|
||||
<div
|
||||
style={{
|
||||
background: '#f8fafc',
|
||||
border: '1px solid #e2e8f0',
|
||||
borderRadius: 8,
|
||||
padding: '12px 16px',
|
||||
marginBottom: 18,
|
||||
}}
|
||||
>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<div style={{ fontSize: 12, color: '#64748b' }}>0666.pro 采购商户</div>
|
||||
<div style={{ fontSize: 15, fontWeight: 600, color: '#0f172a', marginTop: 2 }}>
|
||||
{stats?.username || '正常商户'}
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<div style={{ fontSize: 12, color: '#64748b' }}>当前实时积分余额</div>
|
||||
<div style={{ fontSize: 15, fontWeight: 700, color: '#7c3aed', marginTop: 2 }}>
|
||||
{upstreamPoints.toFixed(1)} 点
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Divider style={{ margin: '10px 0' }} />
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 12, color: '#64748b' }}>
|
||||
<span>采购单价:<strong style={{ color: '#0f172a' }}>21 点 / 个</strong></span>
|
||||
<span>最大可采购:<strong style={{ color: '#2563eb' }}>{maxPurchasable} 个</strong></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 采购数量输入 */}
|
||||
<div style={{ marginBottom: 14 }}>
|
||||
<div style={{ fontWeight: 600, marginBottom: 8, color: '#0f172a' }}>
|
||||
采购数量:
|
||||
</div>
|
||||
<InputNumber
|
||||
min={1}
|
||||
max={maxPurchasable > 0 ? maxPurchasable : 10000}
|
||||
value={purchaseCount}
|
||||
onChange={(val) => onPurchaseCountChange(val || 1)}
|
||||
style={{ width: '100%' }}
|
||||
addonAfter="个 Token"
|
||||
size="large"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 快捷数量选择胶囊 */}
|
||||
<div style={{ marginBottom: 18 }}>
|
||||
<div style={{ fontSize: 12, color: '#64748b', marginBottom: 8 }}>快捷选择:</div>
|
||||
<Space wrap size={[8, 8]}>
|
||||
{[10, 20, 50, 100].map((num) => (
|
||||
<Button
|
||||
key={num}
|
||||
size="small"
|
||||
type={purchaseCount === num ? 'primary' : 'default'}
|
||||
onClick={() => onPurchaseCountChange(num)}
|
||||
disabled={maxPurchasable > 0 && num > maxPurchasable}
|
||||
>
|
||||
{num} 个
|
||||
</Button>
|
||||
))}
|
||||
{maxPurchasable > 0 && (
|
||||
<Button
|
||||
size="small"
|
||||
type={purchaseCount === maxPurchasable ? 'primary' : 'dashed'}
|
||||
onClick={() => onPurchaseCountChange(maxPurchasable)}
|
||||
style={{ color: '#2563eb', borderColor: '#bfdbfe' }}
|
||||
>
|
||||
全部可购 ({maxPurchasable} 个)
|
||||
</Button>
|
||||
)}
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
{/* 实时消耗与结余试算 */}
|
||||
<div
|
||||
style={{
|
||||
background: isPointsInsufficient ? '#fef2f2' : '#f0fdf4',
|
||||
border: `1px solid ${isPointsInsufficient ? '#fecaca' : '#bbf7d0'}`,
|
||||
borderRadius: 8,
|
||||
padding: '12px 16px',
|
||||
fontSize: 13,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<span style={{ color: isPointsInsufficient ? '#991b1b' : '#166534' }}>
|
||||
本次采购消耗积分:
|
||||
</span>
|
||||
<strong style={{ color: isPointsInsufficient ? '#dc2626' : '#16a34a', fontSize: 16 }}>
|
||||
{estimatedCost} 点
|
||||
</strong>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
marginTop: 6,
|
||||
fontSize: 12,
|
||||
}}
|
||||
>
|
||||
<span style={{ color: isPointsInsufficient ? '#b91c1c' : '#15803d' }}>
|
||||
{isPointsInsufficient
|
||||
? '⚠️ 账户积分不足,请先充值或减少采购数量'
|
||||
: '采购后预计剩余积分:'}
|
||||
</span>
|
||||
{!isPointsInsufficient && (
|
||||
<span style={{ color: '#64748b' }}>
|
||||
{(upstreamPoints - estimatedCost).toFixed(1)} 点
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user