import { FlipNumber, WaterLevel } from '@dev-screen-starter/visual-kit' import { getDeviceStatus } from '../domain/deviceStatus' import type { FactoryDevice } from '../domain/deviceTypes' type StatusSummaryProps = { devices: FactoryDevice[] weeklyLabels: string[] weeklyProduce: number[] todayIdx: number } export function StatusSummary({ devices, weeklyLabels, weeklyProduce, todayIdx }: StatusSummaryProps) { const counts = devices.reduce( (result, device) => { const status = getDeviceStatus(device) if (status.key === 'running' || status.key === 'normal') result.running += 1 else if (status.key === 'alarm') result.alarm += 1 else if (status.key === 'offline') result.offline += 1 else result.idle += 1 return result }, { running: 0, idle: 0, alarm: 0, offline: 0 } ) const availability = devices.length ? Math.round(((devices.length - counts.offline) / devices.length) * 100) : 0 const running = devices.length ? Math.round((counts.running / devices.length) * 100) : 0 const maxProduce = Math.max(...weeklyProduce, 1) const productionDevices = devices.filter((device) => (device.type === 'cnc' || device.type === 'laser') && device.online) const cncTotal = productionDevices.reduce((sum, device) => { if (device.type === 'cnc') return sum + Number(device.machineData?.currentProduceCount || 0) if (device.type === 'laser') return sum + Number(device.machineData?.pierceCount || 0) return sum }, 0) const todayProduce = productionDevices .reduce((sum, device) => { if (device.type === 'cnc') return sum + Number(device.machineData?.todayProduce ?? device.weeklyStats?.produce?.[todayIdx] ?? 0) return sum + Number(device.weeklyStats?.produce?.[todayIdx] ?? 0) }, 0) return (
设备总览
今日产量 {todayProduce.toLocaleString()} 件
近7日产能趋势
{weeklyProduce.map((value, index) => (
{value > 1000 ? `${Math.round(value / 100) / 10}k` : value}
{weeklyLabels[index]}
))}
) } function StatusCount({ label, value, tone }: { label: string; value: number; tone: string }) { return (
{value} {label}
) }