Files
bj_power/bj_power_dashboard/src/pages/ProductionBoard.tsx
T

145 lines
5.9 KiB
TypeScript

import { useEffect, useMemo, useState } from 'react';
import type { EChartsOption } from 'echarts';
import type { DashboardData, ProductionProgress } from '../types';
import { EChart } from '../components/EChart';
import { dash0 } from './WarehouseBoard';
const C = {
cyan: '#22d3ee',
green: '#34d399',
text: '#e2e8f0',
sub: '#94a3b8',
dim: '#64748b',
};
/** 轮播间隔(毫秒):多订单时逐单展示 */
const ROTATE_MS = 10000;
/** 单张订单卡(左块):合同/工期/完成度 */
function OrderCard({ order }: { order: ProductionProgress }) {
return (
<div style={{ flex: '1 1 46%', minWidth: 0, display: 'flex', flexDirection: 'column', gap: 'clamp(4px, 0.7vh, 9px)' }}>
<div style={{ fontSize: 'clamp(15px, 1.25vw, 48px)', fontWeight: 600, color: '#eaf6ff', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{order.contractNo || order.orderNo || '暂无在产订单'}
</div>
<div style={{ fontSize: 'clamp(11px, 0.85vw, 33px)', color: C.sub, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{order.productName || '—'}
</div>
<div style={{ display: 'flex', gap: 'clamp(10px, 1vw, 44px)', fontSize: 'clamp(10px, 0.8vw, 31px)', color: C.sub, flexWrap: 'nowrap' }}>
<span style={{ whiteSpace: 'nowrap' }}>
交期 <span style={{ color: C.text }}>{order.planEnd || '—'}</span>
</span>
<span style={{ whiteSpace: 'nowrap', color: order.remainDays >= 0 ? C.green : '#fbbf24' }}>
剩余 {order.planEnd ? Math.max(order.remainDays, 0) : '—'} 天
</span>
</div>
<div style={{ marginTop: 'auto' }}>
<div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 8 }}>
<span style={{ fontSize: 'clamp(10px, 0.8vw, 31px)', color: C.sub }}>完成进度</span>
<span style={{ fontVariantNumeric: 'tabular-nums' }}>
<span style={{ fontSize: 'clamp(17px, 1.5vw, 62px)', fontWeight: 700, color: C.cyan }}>{dash0(order.doneQty)}</span>
<span style={{ fontSize: 'clamp(10px, 0.8vw, 31px)', color: C.sub }}> / {dash0(order.totalQty)} 台</span>
</span>
</div>
<div style={{ height: 'clamp(6px, 0.9vh, 10px)', background: '#16233a', borderRadius: 6, overflow: 'hidden', marginTop: 6 }}>
<div
style={{
width: `${Math.max(0, Math.min(100, order.progress))}%`,
height: '100%',
background: 'linear-gradient(90deg, #0ea5e9, #22d3ee)',
transition: 'width 0.6s ease',
}}
/>
</div>
<div style={{ fontSize: 'clamp(10px, 0.78vw, 29px)', color: C.dim, marginTop: 4, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
工序 {dash0(order.processDone)}/{dash0(order.processTotal)}
{order.currentProcess ? ` · 当前 ${order.currentProcess}` : ''}
</div>
</div>
</div>
);
}
/** 底部左块 · 当前订单(多订单自动轮播)+ 近 7 日产量趋势 */
export function ProductionBoard({ data }: { data: DashboardData }) {
const { trends } = data;
// 多订单轮播:progressList 优先(后端下发,进行中排前),未升级时退回单条 progress
const orders = useMemo<ProductionProgress[]>(() => {
const list = (data.progressList || []).filter((o) => o && (o.orderNo || o.contractNo));
if (list.length > 0) return list;
return data.progress ? [data.progress] : [];
}, [data.progressList, data.progress]);
const [idx, setIdx] = useState(0);
useEffect(() => {
setIdx(0);
}, [orders.length]);
useEffect(() => {
if (orders.length <= 1) return;
const t = setInterval(() => setIdx((i) => (i + 1) % orders.length), ROTATE_MS);
return () => clearInterval(t);
}, [orders.length]);
const current = orders[Math.min(idx, orders.length - 1)];
const trendOption: EChartsOption = {
grid: { left: 8, right: 12, top: 14, bottom: 4, containLabel: true },
tooltip: { trigger: 'axis' },
xAxis: {
type: 'category',
data: trends.production.map((t) => t.time),
axisTick: { show: false },
axisLine: { lineStyle: { color: 'rgba(56,189,248,0.25)' } },
axisLabel: { color: '#8fa3bf', fontSize: 11 },
},
yAxis: {
type: 'value',
splitLine: { lineStyle: { color: 'rgba(56,189,248,0.1)' } },
axisLabel: { color: '#8fa3bf', fontSize: 11 },
},
series: [
{
name: '日产量',
type: 'line',
smooth: true,
symbol: 'circle',
symbolSize: 6,
data: trends.production.map((t) => t.output),
itemStyle: { color: C.cyan },
lineStyle: { width: 2.5 },
areaStyle: { color: 'rgba(34,211,238,0.18)' },
},
],
};
return (
<div className="panel">
<div className="panel-head">
当前订单
<span className="note">合同 · 工期 · 完成度</span>
{orders.length > 1 && (
<span style={{ marginLeft: 'auto', fontSize: 'clamp(9px, 0.7vw, 26px)', color: C.dim }}>
{idx + 1}/{orders.length}
</span>
)}
</div>
<div className="panel-body" style={{ flexDirection: 'row', gap: 'clamp(8px, 0.9vw, 40px)' }}>
{/* 左:订单信息(多订单轮播,无鼠标大屏 10s 自动切换) */}
{current && <OrderCard key={current.orderNo} order={current} />}
{/* 右:近 7 日产量趋势(height:100% 跟随容器) */}
<div style={{ flex: '1 1 54%', minWidth: 0, display: 'flex', flexDirection: 'column' }}>
<div style={{ fontSize: 'clamp(10px, 0.8vw, 31px)', color: C.sub, flexShrink: 0, marginBottom: 2 }}>近 7 日产量</div>
<div style={{ flex: 1, minHeight: 0, position: 'relative' }}>
<EChart option={trendOption} height="100%" />
</div>
</div>
</div>
</div>
);
}