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 (
{order.contractNo || order.orderNo || '暂无在产订单'}
{order.productName || '—'}
交期 {order.planEnd || '—'} = 0 ? C.green : '#fbbf24' }}> 剩余 {order.planEnd ? Math.max(order.remainDays, 0) : '—'} 天
完成进度 {dash0(order.doneQty)} / {dash0(order.totalQty)} 台
工序 {dash0(order.processDone)}/{dash0(order.processTotal)} {order.currentProcess ? ` · 当前 ${order.currentProcess}` : ''}
); } /** 底部左块 · 当前订单(多订单自动轮播)+ 近 7 日产量趋势 */ export function ProductionBoard({ data }: { data: DashboardData }) { const { trends } = data; // 多订单轮播:progressList 优先(后端下发,进行中排前),未升级时退回单条 progress const orders = useMemo(() => { 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 (
当前订单 合同 · 工期 · 完成度 {orders.length > 1 && ( {idx + 1}/{orders.length} )}
{/* 左:订单信息(多订单轮播,无鼠标大屏 10s 自动切换) */} {current && } {/* 右:近 7 日产量趋势(height:100% 跟随容器) */}
近 7 日产量
); }