Add factory dashboard mock screen
This commit is contained in:
1 parent
d7bfde754b
commit
1331d10e31
21 files changed
+2044
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { FlipNumber, WaterLevel } from '@dev-screen-starter/visual-kit'
|
||||
import { getDeviceStatus } from '../domain/deviceStatus'
|
||||
import type { CncDevice, 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 cncDevices = devices.filter((device): device is CncDevice => device.type === 'cnc' && device.online)
|
||||
const cncTotal = cncDevices
|
||||
.reduce((sum, device) => sum + Number(device.machineData?.currentProduceCount || 0), 0)
|
||||
const todayProduce = cncDevices
|
||||
.reduce((sum, device) => sum + Number(device.weeklyStats?.produce?.[todayIdx] || 0), 0)
|
||||
|
||||
return (
|
||||
<div className="status-summary">
|
||||
<div className="panel-title">设备总览</div>
|
||||
|
||||
<div className="status-count-grid">
|
||||
<StatusCount label="运行中" value={counts.running} tone="running" />
|
||||
<StatusCount label="待机" value={counts.idle} tone="idle" />
|
||||
<StatusCount label="报警" value={counts.alarm} tone="alarm" />
|
||||
<StatusCount label="离线" value={counts.offline} tone="offline" />
|
||||
</div>
|
||||
|
||||
<div className="water-pair">
|
||||
<WaterLevel label="设备可用率" value={availability} tone="green" />
|
||||
<WaterLevel label="运行率" value={running} tone="blue" />
|
||||
</div>
|
||||
|
||||
<div className="summary-total">
|
||||
<FlipNumber label="CNC 总产量" value={cncTotal.toLocaleString()} tone="blue" size="sm" />
|
||||
<div className="today-produce">今日产量 <strong>{todayProduce.toLocaleString()}</strong> 件</div>
|
||||
</div>
|
||||
|
||||
<div className="panel-title compact">近7日产能趋势</div>
|
||||
<div className="mini-bars">
|
||||
{weeklyProduce.map((value, index) => (
|
||||
<div className="mini-bar" key={`${weeklyLabels[index]}-${index}`}>
|
||||
<span>{value > 1000 ? `${Math.round(value / 100) / 10}k` : value}</span>
|
||||
<div>
|
||||
<i className={index === todayIdx ? 'today' : ''} style={{ height: `${Math.max(8, (value / maxProduce) * 90)}%` }} />
|
||||
</div>
|
||||
<small>{weeklyLabels[index]}</small>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function StatusCount({ label, value, tone }: { label: string; value: number; tone: string }) {
|
||||
return (
|
||||
<div className={`status-count ${tone}`}>
|
||||
<strong>{value}</strong>
|
||||
<span>{label}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user