Files
affiliate_dash/frontend/src/pages/platformRock/RockMetricCards.tsx
T

165 lines
6.0 KiB
TypeScript

import { Col, Row, Tag } from 'antd'
import {
CheckCircleOutlined,
CloudServerOutlined,
ExclamationCircleOutlined,
FireOutlined,
ShoppingCartOutlined,
} from '@ant-design/icons'
import type { RockStats } from '../../api'
export interface RockMetricCardsProps {
stats: RockStats | null
upstreamStock: number | null
blackTokenCost: number
availableStock: number
warningStock: number
isStockLow: boolean
hasMismatch: boolean
upstreamPoints: number
maxPurchasable: number
onOpenPurchase: (count: number) => void
}
export function RockMetricCards({
stats,
upstreamStock,
blackTokenCost,
availableStock,
warningStock,
isStockLow,
hasMismatch,
upstreamPoints,
maxPurchasable,
onOpenPurchase,
}: RockMetricCardsProps) {
return (
<Row gutter={[16, 16]} style={{ marginBottom: 20 }}>
<Col flex="1 1 200px">
<div className="metric-card-box">
<div className="metric-card-header">
<span className="metric-card-title">上游可用库存 (0666.pro)</span>
<div className="metric-card-icon" style={{ background: '#e0f2fe', color: '#0284c7' }}>
<CloudServerOutlined />
</div>
</div>
<div className="metric-card-value" style={{ color: upstreamStock === null ? '#94a3b8' : '#0369a1' }}>
{upstreamStock === null ? '-' : upstreamStock}
<span style={{ fontSize: 13, fontWeight: 500, marginLeft: 4, color: '#64748b' }}>个</span>
</div>
<div className="metric-card-footer">
<span>采购单价: {blackTokenCost.toFixed(2)} 点/个</span>
{upstreamStock === null ? (
<Tag color="warning" style={{ margin: 0, borderRadius: 4 }}>
未获取
</Tag>
) : upstreamStock === 0 ? (
<Tag color="error" style={{ margin: 0, borderRadius: 4 }}>
无库存
</Tag>
) : (
<Tag color="processing" style={{ margin: 0, borderRadius: 4 }}>
实时
</Tag>
)}
</div>
</div>
</Col>
<Col flex="1 1 200px">
<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 flex="1 1 200px">
<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 flex="1 1 200px">
<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 flex="1 1 200px">
<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>
)
}