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,267 @@
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Col,
|
||||
Divider,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
Row,
|
||||
Space,
|
||||
Switch,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from 'antd'
|
||||
import type { FormInstance } from 'antd'
|
||||
import {
|
||||
ControlOutlined,
|
||||
ExclamationCircleOutlined,
|
||||
KeyOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
ThunderboltOutlined,
|
||||
} from '@ant-design/icons'
|
||||
|
||||
const { Text } = Typography
|
||||
|
||||
export interface RockStrategyCardProps {
|
||||
form: FormInstance
|
||||
autoDelivery: boolean
|
||||
testingConn: boolean
|
||||
savingConfig: boolean
|
||||
onToggleAutoDelivery: (checked: boolean) => void
|
||||
onTestConnection: () => void
|
||||
onSaveConfig: () => void
|
||||
}
|
||||
|
||||
export function RockStrategyCard({
|
||||
form,
|
||||
autoDelivery,
|
||||
testingConn,
|
||||
savingConfig,
|
||||
onToggleAutoDelivery,
|
||||
onTestConnection,
|
||||
onSaveConfig,
|
||||
}: RockStrategyCardProps) {
|
||||
return (
|
||||
<Card
|
||||
style={{
|
||||
marginBottom: 20,
|
||||
borderRadius: 12,
|
||||
border: '1px solid #e2e8f0',
|
||||
boxShadow: 'var(--shadow-sm)',
|
||||
}}
|
||||
styles={{ body: { padding: '20px 24px' } }}
|
||||
>
|
||||
{/* 通道状态与软熔断横幅 */}
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
padding: '14px 18px',
|
||||
borderRadius: 8,
|
||||
marginBottom: 20,
|
||||
background: autoDelivery ? '#f0fdf4' : '#fef2f2',
|
||||
border: autoDelivery ? '1px solid #bbf7d0' : '1px solid #fecaca',
|
||||
transition: 'all 0.3s ease',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
||||
<div
|
||||
style={{
|
||||
width: 38,
|
||||
height: 38,
|
||||
borderRadius: 8,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
fontSize: 18,
|
||||
background: autoDelivery ? '#dcfce7' : '#fee2e2',
|
||||
color: autoDelivery ? '#16a34a' : '#dc2626',
|
||||
}}
|
||||
>
|
||||
{autoDelivery ? <SafetyCertificateOutlined /> : <ControlOutlined />}
|
||||
</div>
|
||||
<div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<strong style={{ fontSize: 14, color: autoDelivery ? '#166534' : '#991b1b' }}>
|
||||
{autoDelivery
|
||||
? '自动发货通道正常运转 (Active)'
|
||||
: '自动发货已全局软熔断 (Kill Switch Engaged)'}
|
||||
</strong>
|
||||
<Tag color={autoDelivery ? 'success' : 'error'} style={{ borderRadius: 10 }}>
|
||||
{autoDelivery ? '反代履约中' : '已转交人工打手'}
|
||||
</Tag>
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: autoDelivery ? '#15803d' : '#b91c1c', marginTop: 2 }}>
|
||||
{autoDelivery
|
||||
? '和平精英「黑色 ROCK 长袖」与「蓝色运动服」开启 0666.pro 全自动反代发货,UID 强一致安全门禁全面守护。'
|
||||
: '两款商品已彻底切断上游 0666.pro 自动发货通道,所有新订单均保留在待发货状态,由人工接单平台处理。'}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Space size="middle">
|
||||
<Switch
|
||||
checked={autoDelivery}
|
||||
onChange={onToggleAutoDelivery}
|
||||
checkedChildren="开启"
|
||||
unCheckedChildren="熔断"
|
||||
style={{
|
||||
backgroundColor: autoDelivery ? '#16a34a' : '#dc2626',
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
size="small"
|
||||
danger={autoDelivery}
|
||||
type={autoDelivery ? 'default' : 'primary'}
|
||||
onClick={() => onToggleAutoDelivery(!autoDelivery)}
|
||||
>
|
||||
{autoDelivery ? '一键紧急熔断' : '恢复自动发货'}
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
{/* 策略表单 */}
|
||||
<Form form={form} layout="vertical" autoComplete="off">
|
||||
{/* 阻断浏览器对凭据配置项的强制账密自动填充 (Honeypot) */}
|
||||
<div style={{ position: 'absolute', top: -9999, left: -9999, width: 0, height: 0, overflow: 'hidden' }} aria-hidden="true">
|
||||
<input type="text" name="chrome_prevent_autofill_username" tabIndex={-1} autoComplete="username" />
|
||||
<input type="password" name="chrome_prevent_autofill_password" tabIndex={-1} autoComplete="current-password" />
|
||||
</div>
|
||||
|
||||
<Row gutter={24}>
|
||||
<Col xs={24} lg={12}>
|
||||
<div
|
||||
style={{
|
||||
background: '#f8fafc',
|
||||
padding: '16px 18px',
|
||||
borderRadius: 10,
|
||||
border: '1px solid #f1f5f9',
|
||||
height: '100%',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 16 }}>
|
||||
<KeyOutlined style={{ color: '#2563eb', fontSize: 16 }} />
|
||||
<strong style={{ fontSize: 14, color: '#0f172a' }}>0666.pro 采购认证凭据</strong>
|
||||
</div>
|
||||
|
||||
<Form.Item name="base_url" label="上游平台接口地址 (Base URL)" style={{ marginBottom: 14 }}>
|
||||
<Input
|
||||
placeholder="https://0666.pro"
|
||||
autoComplete="off"
|
||||
name="upstream_base_url"
|
||||
id="upstream_base_url"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="bearer_token"
|
||||
label={
|
||||
<Space>
|
||||
<span>上游商户 Bearer Token (yd_token)</span>
|
||||
<Tooltip title="0666.pro 采用无密码架构,直接从网页 localStorage 提取 64 位十六进制 Token 即可">
|
||||
<ExclamationCircleOutlined style={{ color: '#94a3b8' }} />
|
||||
</Tooltip>
|
||||
</Space>
|
||||
}
|
||||
style={{ marginBottom: 12 }}
|
||||
>
|
||||
<Input.Password
|
||||
placeholder="粘贴 64 位十六进制 Bearer Token"
|
||||
autoComplete="new-password"
|
||||
name="upstream_bearer_token"
|
||||
id="upstream_bearer_token"
|
||||
addonAfter={
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={onTestConnection}
|
||||
loading={testingConn}
|
||||
style={{ padding: '0 4px', height: 'auto' }}
|
||||
>
|
||||
测试连通性
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<div
|
||||
style={{
|
||||
background: '#eff6ff',
|
||||
border: '1px dashed #bfdbfe',
|
||||
borderRadius: 6,
|
||||
padding: '8px 12px',
|
||||
fontSize: 12,
|
||||
color: '#1e40af',
|
||||
}}
|
||||
>
|
||||
💡 <strong>极简提取指引:</strong>登录 0666.pro 网页后,按 F12 打开控制台,在 Console 执行{' '}
|
||||
<Text code copyable={{ text: "localStorage.getItem('yd_token')" }}>
|
||||
localStorage.getItem('yd_token')
|
||||
</Text>{' '}
|
||||
即可一键复制。
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} lg={12}>
|
||||
<div
|
||||
style={{
|
||||
background: '#f8fafc',
|
||||
padding: '16px 18px',
|
||||
borderRadius: 10,
|
||||
border: '1px solid #f1f5f9',
|
||||
height: '100%',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 16 }}>
|
||||
<ThunderboltOutlined style={{ color: '#7c3aed', fontSize: 16 }} />
|
||||
<strong style={{ fontSize: 14, color: '#0f172a' }}>库存风控与自动补货策略</strong>
|
||||
</div>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="token_warning_stock" label="库存告警安全水位">
|
||||
<InputNumber min={1} max={500} style={{ width: '100%' }} addonAfter="个" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="auto_purchase_enabled" label="自动补货触发开关" valuePropName="checked">
|
||||
<Switch checkedChildren="开启自动补货" unCheckedChildren="关闭" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="auto_purchase_count" label="单次自动补货数量">
|
||||
<InputNumber min={5} max={200} style={{ width: '100%' }} addonAfter="个" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="purchase_cooldown_minutes" label="补货防抖冷却时间">
|
||||
<InputNumber min={1} max={60} style={{ width: '100%' }} addonAfter="分钟" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Divider style={{ margin: '18px 0 16px 0' }} />
|
||||
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
||||
<Button
|
||||
type="primary"
|
||||
onClick={onSaveConfig}
|
||||
loading={savingConfig}
|
||||
style={{
|
||||
background: 'linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%)',
|
||||
minWidth: 130,
|
||||
}}
|
||||
>
|
||||
保存策略配置
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user