From 1331d10e31b6153d5b741f888e5691c742d14a0a Mon Sep 17 00:00:00 2001 From: zhougf Date: Sun, 31 May 2026 02:20:12 +0800 Subject: [PATCH] Add factory dashboard mock screen --- apps/factory-dashboard/.env.example | 3 + apps/factory-dashboard/index.html | 12 + apps/factory-dashboard/package.json | 28 + apps/factory-dashboard/src/ProjectScreen.tsx | 5 + .../src/components/AlarmPanel.tsx | 23 + .../src/components/CncCard.tsx | 42 + .../src/components/DeviceListPanel.tsx | 74 ++ .../src/components/FocusDevicePanel.tsx | 161 +++ .../src/components/HeaderBar.tsx | 32 + .../src/components/LaserCard.tsx | 58 + .../src/components/PowerCard.tsx | 31 + .../src/components/StatusSummary.tsx | 77 ++ .../src/domain/deviceStatus.ts | 96 ++ .../src/domain/deviceTypes.ts | 120 ++ apps/factory-dashboard/src/main.tsx | 6 + .../src/mock/factoryDevices.ts | 146 +++ .../src/pages/DashboardPage.tsx | 65 ++ .../src/styles/factory-dashboard.css | 1039 +++++++++++++++++ .../factory-dashboard/src/utils/weekLabels.ts | 12 + apps/factory-dashboard/tsconfig.json | 8 + apps/factory-dashboard/vite.config.ts | 6 + 21 files changed, 2044 insertions(+) create mode 100644 apps/factory-dashboard/.env.example create mode 100644 apps/factory-dashboard/index.html create mode 100644 apps/factory-dashboard/package.json create mode 100644 apps/factory-dashboard/src/ProjectScreen.tsx create mode 100644 apps/factory-dashboard/src/components/AlarmPanel.tsx create mode 100644 apps/factory-dashboard/src/components/CncCard.tsx create mode 100644 apps/factory-dashboard/src/components/DeviceListPanel.tsx create mode 100644 apps/factory-dashboard/src/components/FocusDevicePanel.tsx create mode 100644 apps/factory-dashboard/src/components/HeaderBar.tsx create mode 100644 apps/factory-dashboard/src/components/LaserCard.tsx create mode 100644 apps/factory-dashboard/src/components/PowerCard.tsx create mode 100644 apps/factory-dashboard/src/components/StatusSummary.tsx create mode 100644 apps/factory-dashboard/src/domain/deviceStatus.ts create mode 100644 apps/factory-dashboard/src/domain/deviceTypes.ts create mode 100644 apps/factory-dashboard/src/main.tsx create mode 100644 apps/factory-dashboard/src/mock/factoryDevices.ts create mode 100644 apps/factory-dashboard/src/pages/DashboardPage.tsx create mode 100644 apps/factory-dashboard/src/styles/factory-dashboard.css create mode 100644 apps/factory-dashboard/src/utils/weekLabels.ts create mode 100644 apps/factory-dashboard/tsconfig.json create mode 100644 apps/factory-dashboard/vite.config.ts diff --git a/apps/factory-dashboard/.env.example b/apps/factory-dashboard/.env.example new file mode 100644 index 0000000..1df144a --- /dev/null +++ b/apps/factory-dashboard/.env.example @@ -0,0 +1,3 @@ +VITE_API_BASE_URL=http://localhost:3000 +VITE_WS_URL=ws://localhost:3000/ws/screen +VITE_ENABLE_STAGE_DEBUG=true diff --git a/apps/factory-dashboard/index.html b/apps/factory-dashboard/index.html new file mode 100644 index 0000000..a25ba1c --- /dev/null +++ b/apps/factory-dashboard/index.html @@ -0,0 +1,12 @@ + + + + + + 工厂设备智能监控平台 + + +
+ + + diff --git a/apps/factory-dashboard/package.json b/apps/factory-dashboard/package.json new file mode 100644 index 0000000..56a2466 --- /dev/null +++ b/apps/factory-dashboard/package.json @@ -0,0 +1,28 @@ +{ + "name": "@dev-screen-starter/factory-dashboard", + "version": "0.1.0", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --host 0.0.0.0", + "build": "tsc --noEmit && vite build", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@dev-screen-starter/charts": "workspace:*", + "@dev-screen-starter/data": "workspace:*", + "@dev-screen-starter/debug": "workspace:*", + "@dev-screen-starter/screen-core": "workspace:*", + "@dev-screen-starter/visual-kit": "workspace:*", + "@vitejs/plugin-react": "^5.0.4", + "echarts": "^6.0.0", + "react": "^19.1.1", + "react-dom": "^19.1.1", + "vite": "^7.1.7" + }, + "devDependencies": { + "@types/react": "^19.1.16", + "@types/react-dom": "^19.1.9", + "typescript": "^5.9.2" + } +} diff --git a/apps/factory-dashboard/src/ProjectScreen.tsx b/apps/factory-dashboard/src/ProjectScreen.tsx new file mode 100644 index 0000000..2ba45bd --- /dev/null +++ b/apps/factory-dashboard/src/ProjectScreen.tsx @@ -0,0 +1,5 @@ +import { DashboardPage } from './pages/DashboardPage' + +export function ProjectScreen() { + return +} diff --git a/apps/factory-dashboard/src/components/AlarmPanel.tsx b/apps/factory-dashboard/src/components/AlarmPanel.tsx new file mode 100644 index 0000000..fc5b798 --- /dev/null +++ b/apps/factory-dashboard/src/components/AlarmPanel.tsx @@ -0,0 +1,23 @@ +import { MarqueeList } from '@dev-screen-starter/visual-kit' +import type { AlarmRow } from '../domain/deviceTypes' + +export function AlarmPanel({ alarms }: { alarms: AlarmRow[] }) { + return ( +
+
报警信息
+ {alarms.length ? {alarms.length} 条报警 :
全部设备运行正常
} + {alarms.length ? ( + ( +
+ {alarm.time} + {alarm.device} + {alarm.message} +
+ )} + /> + ) : null} +
+ ) +} diff --git a/apps/factory-dashboard/src/components/CncCard.tsx b/apps/factory-dashboard/src/components/CncCard.tsx new file mode 100644 index 0000000..39cc070 --- /dev/null +++ b/apps/factory-dashboard/src/components/CncCard.tsx @@ -0,0 +1,42 @@ +import { formatFanucTimeShort, getCncWorkModeText, getDeviceStatus, STATUS_COLORS } from '../domain/deviceStatus' +import type { CncDevice } from '../domain/deviceTypes' + +export function CncCard({ device, onOpen }: { device: CncDevice; onOpen?: () => void }) { + const status = getDeviceStatus(device) + const machineData = device.machineData + const todayProduce = Number(device.weeklyStats?.produce?.[6] || 0) + + return ( + + ) +} diff --git a/apps/factory-dashboard/src/components/DeviceListPanel.tsx b/apps/factory-dashboard/src/components/DeviceListPanel.tsx new file mode 100644 index 0000000..4e6a566 --- /dev/null +++ b/apps/factory-dashboard/src/components/DeviceListPanel.tsx @@ -0,0 +1,74 @@ +import { useMemo, useState } from 'react' +import { getDeviceStatus, STATUS_COLORS } from '../domain/deviceStatus' +import type { DeviceStatusKey, FactoryDevice } from '../domain/deviceTypes' + +type DeviceListPanelProps = { + devices: FactoryDevice[] + selectedId: string + onSelect: (deviceId: string) => void +} + +type StatusFilter = 'all' | Extract + +export function DeviceListPanel({ devices, selectedId, onSelect }: DeviceListPanelProps) { + const [keyword, setKeyword] = useState('') + const [statusFilter, setStatusFilter] = useState('all') + + const filtered = useMemo(() => { + const normalized = keyword.trim().toLowerCase() + + return devices.filter((device) => { + const status = getDeviceStatus(device) + const matchKeyword = !normalized || `${device.name} ${device.id}`.toLowerCase().includes(normalized) + const matchStatus = statusFilter === 'all' || status.key === statusFilter + return matchKeyword && matchStatus + }) + }, [devices, keyword, statusFilter]) + + return ( +
+
设备选择
+ + setKeyword(event.target.value)} + placeholder="搜索设备编号" + value={keyword} + /> + +
+ setStatusFilter('all')} /> + setStatusFilter('running')} /> + setStatusFilter('alarm')} /> + setStatusFilter('offline')} /> +
+ +
+ {filtered.map((device) => { + const status = getDeviceStatus(device) + + return ( + + ) + })} +
+
+ ) +} + +function FilterButton({ active, label, onClick }: { active: boolean; label: string; onClick: () => void }) { + return ( + + ) +} diff --git a/apps/factory-dashboard/src/components/FocusDevicePanel.tsx b/apps/factory-dashboard/src/components/FocusDevicePanel.tsx new file mode 100644 index 0000000..b444a73 --- /dev/null +++ b/apps/factory-dashboard/src/components/FocusDevicePanel.tsx @@ -0,0 +1,161 @@ +import { ChartPanel, createDualAxisOption, createLineOption } from '@dev-screen-starter/charts' +import { FlipNumber, TrendBadge, WaterLevel } from '@dev-screen-starter/visual-kit' +import { formatFanucTimeShort, getDeviceStatus, getLaserSysStateText, STATUS_COLORS } from '../domain/deviceStatus' +import type { FactoryDevice } from '../domain/deviceTypes' +import { getLast7DaysChartInfo } from '../utils/weekLabels' + +export function FocusDevicePanel({ device }: { device: FactoryDevice }) { + const status = getDeviceStatus(device) + + return ( +
+
+
+ 焦点设备 + {device.name} +
+
+ + {status.label} +
+
+ +
+ + +
+
+ ) +} + +function FocusRealtime({ device }: { device: FactoryDevice }) { + if (device.type === 'laser') { + const nc = device.machineData?.CutSystemState?.NcState + const ds = device.machineData?.CutSystemState?.DeviceState + const progress = nc?.CutPercent ?? 0 + + return ( +
+
+ 0 ? 'green' : 'blue'} /> +
+ 当前图纸 + {nc?.TaskName ?? '无当前图纸'} + {getLaserSysStateText(nc?.SysState)} +
+
+
+ + + + +
+
+ ) + } + + if (device.type === 'cnc') { + const md = device.machineData + + return ( +
+
+ +
+ 当前程序 + {md?.programCurrent?.name ?? '无程序'} + 运行 {formatFanucTimeShort(md?.runtime)} +
+
+
+ + + + +
+
+ ) + } + + const phases = [ + { label: 'A相电流', value: device.machineData?.slave1?.current1 ?? '--' }, + { label: 'B相电流', value: device.machineData?.slave1?.current2 ?? '--' }, + { label: 'C相电流', value: device.machineData?.slave1?.current3 ?? '--' } + ] + + return ( +
+
+ +
+ 实时三相电流 + {device.name} + {device.machineData?.timestamp ?? '等待数据'} +
+
+
+ {phases.map((phase) => ( + 16} /> + ))} +
+
+ ) +} + +function FocusTrend({ device }: { device: FactoryDevice }) { + const labels = device.weeklyStats?.dates ?? getLast7DaysChartInfo().labels + const title = device.type === 'power' ? '最近7天电流趋势' : '最近7天产量与运行趋势' + const option = device.type === 'power' + ? createLineOption({ + categories: labels, + values: device.powerHistory ?? [], + name: '视在功率', + color: '#d8a13e' + }) + : createDualAxisOption({ + categories: labels, + leftName: device.type === 'laser' ? '穿孔' : '产量', + rightName: '运行时长', + bar: { + name: device.type === 'laser' ? '穿孔' : '产量', + values: device.weeklyStats?.produce ?? [], + color: '#63a4ff' + }, + line: { + name: device.type === 'laser' ? '激光时长' : '运行时长', + values: device.weeklyStats?.cuttime ?? [], + color: '#d8a13e' + } + }) + + return ( +
+ } + /> +
+ ) +} + +function FocusMetric({ label, value, unit, warn = false }: { label: string; value: string; unit?: string; warn?: boolean }) { + return ( +
+ {label} + {value}{unit ? {unit} : null} +
+ ) +} + +function estimatePower(device: Extract) { + const currents = [ + device.machineData?.slave1?.current1, + device.machineData?.slave1?.current2, + device.machineData?.slave1?.current3 + ].map((value) => Number.parseFloat(String(value ?? '').replace(/A$/i, ''))) + + if (!currents.every(Number.isFinite)) return 0 + const avg = currents.reduce((sum, value) => sum + value, 0) / currents.length + return (Math.sqrt(3) * 380 * avg) / 1000 +} diff --git a/apps/factory-dashboard/src/components/HeaderBar.tsx b/apps/factory-dashboard/src/components/HeaderBar.tsx new file mode 100644 index 0000000..6b58eeb --- /dev/null +++ b/apps/factory-dashboard/src/components/HeaderBar.tsx @@ -0,0 +1,32 @@ +import { useEffect, useState } from 'react' + +function readClock() { + const now = new Date() + return { + date: now.toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', weekday: 'short' }), + time: now.toLocaleTimeString('zh-CN', { hour12: false }) + } +} + +export function HeaderBar() { + const [clock, setClock] = useState(readClock) + + useEffect(() => { + const timer = window.setInterval(() => setClock(readClock()), 1000) + return () => window.clearInterval(timer) + }, []) + + return ( +
+
+
+ {clock.date} + {clock.time} +
+
+ 工厂设备智能监控平台 +
+
设备实时状态 · React starter edition
+
+ ) +} diff --git a/apps/factory-dashboard/src/components/LaserCard.tsx b/apps/factory-dashboard/src/components/LaserCard.tsx new file mode 100644 index 0000000..c2af55e --- /dev/null +++ b/apps/factory-dashboard/src/components/LaserCard.tsx @@ -0,0 +1,58 @@ +import { getDeviceStatus, STATUS_COLORS } from '../domain/deviceStatus' +import type { LaserDevice } from '../domain/deviceTypes' + +export function LaserCard({ device, onOpen }: { device: LaserDevice; onOpen?: () => void }) { + const status = getDeviceStatus(device) + const nc = device.machineData?.CutSystemState?.NcState + + return ( + + ) +} + +function Stat({ label, value, unit }: { label: string; value: string; unit?: string }) { + return ( +
+ {label} + {value}{unit ? {unit} : null} +
+ ) +} + +function Progress({ value }: { value: number }) { + return ( +
+ + {value.toFixed(1)}% +
+ ) +} + +function StatusBadge({ color, label, status }: { color: string; label: string; status: string }) { + return ( + + + {label} + + ) +} diff --git a/apps/factory-dashboard/src/components/PowerCard.tsx b/apps/factory-dashboard/src/components/PowerCard.tsx new file mode 100644 index 0000000..2e72820 --- /dev/null +++ b/apps/factory-dashboard/src/components/PowerCard.tsx @@ -0,0 +1,31 @@ +import { getDeviceStatus, STATUS_COLORS } from '../domain/deviceStatus' +import type { PowerDevice } from '../domain/deviceTypes' + +export function PowerCard({ device, onOpen }: { device: PowerDevice; onOpen?: () => void }) { + const status = getDeviceStatus(device) + const phases = [ + { label: 'A相', value: device.machineData?.slave1?.current1 ?? '--' }, + { label: 'B相', value: device.machineData?.slave1?.current2 ?? '--' }, + { label: 'C相', value: device.machineData?.slave1?.current3 ?? '--' } + ] + + return ( + + ) +} diff --git a/apps/factory-dashboard/src/components/StatusSummary.tsx b/apps/factory-dashboard/src/components/StatusSummary.tsx new file mode 100644 index 0000000..e7f2320 --- /dev/null +++ b/apps/factory-dashboard/src/components/StatusSummary.tsx @@ -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 ( +
+
设备总览
+ +
+ + + + +
+ +
+ + +
+ +
+ +
今日产量 {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} +
+ ) +} diff --git a/apps/factory-dashboard/src/domain/deviceStatus.ts b/apps/factory-dashboard/src/domain/deviceStatus.ts new file mode 100644 index 0000000..e9b9979 --- /dev/null +++ b/apps/factory-dashboard/src/domain/deviceStatus.ts @@ -0,0 +1,96 @@ +import type { CncMachineData, DeviceStatus, FactoryDevice, LaserMachineData, PowerMachineData } from './deviceTypes' + +const CNC_WORK_MODES: Record = { + '0': 'MDI', + '1': 'AUTO', + '2': 'ERR', + '3': 'EDIT', + '4': 'HANDLE', + '5': 'JOG', + '6': 'T-JOG', + '7': 'T-HNDL', + '8': 'INC', + '9': 'REF', + '10': 'REMOTE' +} + +const LASER_SYS_STATES: Record = { + 0: '待机', + 1: '模拟', + 2: '点动', + 3: '回零', + 7: '走边框', + 8: '加工状态', + 9: '暂停', + 13: '定位', + 21: '单点寻边', + 22: '绝对寻边' +} + +export const STATUS_COLORS: Record = { + running: '#56d08a', + idle: '#d8a13e', + alarm: '#ec646c', + offline: '#66788e', + normal: '#56d08a' +} + +export function getCncWorkModeText(mode?: string | number) { + return CNC_WORK_MODES[String(mode ?? '')] || `MODE ${mode ?? '-'}` +} + +export function getLaserSysStateText(state?: string | number) { + const n = Number(state) + if (Number.isFinite(n) && LASER_SYS_STATES[n]) { + return LASER_SYS_STATES[n] + } + return `状态 ${state ?? '-'}` +} + +export function getCncStatus(machineData?: CncMachineData | null): DeviceStatus { + const statusInfo = machineData?.statusInfo + if (!statusInfo) return { key: 'offline', label: '离线' } + if ((machineData?.alarmStatus ?? 0) > 0 || (statusInfo.Alarm ?? 0) > 0 || (statusInfo.Emergency ?? 0) > 0) { + return { key: 'alarm', label: '报警' } + } + if (statusInfo.RunStatus === '3' && statusInfo.Motion === 1) return { key: 'running', label: '运行中' } + if (statusInfo.RunStatus === '2' || statusInfo.MSTB === 1) return { key: 'running', label: '运行中' } + return { key: 'idle', label: '待机' } +} + +export function getLaserStatus(machineData?: LaserMachineData | null): DeviceStatus { + const nc = machineData?.CutSystemState?.NcState + if (!nc) return { key: 'offline', label: '离线' } + const sys = Number(nc.SysState) + if (sys === 8) return { key: 'running', label: getLaserSysStateText(nc.SysState) } + return { key: 'idle', label: getLaserSysStateText(nc.SysState) } +} + +export function getPowerStatus(machineData?: PowerMachineData | null): DeviceStatus { + if (!machineData) return { key: 'offline', label: '离线' } + const values = [machineData.slave1?.current1, machineData.slave1?.current2, machineData.slave1?.current3] + if (values.some((value) => value === 'invalid')) return { key: 'alarm', label: '异常' } + return { key: 'normal', label: '正常' } +} + +export function getDeviceStatus(device: FactoryDevice): DeviceStatus { + if (!device.online) return { key: 'offline', label: '离线' } + if (device.type === 'cnc') return getCncStatus(device.machineData) + if (device.type === 'laser') return getLaserStatus(device.machineData) + return getPowerStatus(device.machineData) +} + +export function parseFanucTime(time?: string) { + if (!time) return { hours: 0, minutes: 0, seconds: 0, totalMinutes: 0 } + const match = time.match(/(\d+)\s*H\s*(\d+)\s*M\s*(\d+)\s*S/) + if (!match) return { hours: 0, minutes: 0, seconds: 0, totalMinutes: 0 } + const hours = Number(match[1]) + const minutes = Number(match[2]) + const seconds = Number(match[3]) + return { hours, minutes, seconds, totalMinutes: hours * 60 + minutes } +} + +export function formatFanucTimeShort(time?: string) { + const parsed = parseFanucTime(time) + return `${parsed.hours}H ${parsed.minutes}M` +} diff --git a/apps/factory-dashboard/src/domain/deviceTypes.ts b/apps/factory-dashboard/src/domain/deviceTypes.ts new file mode 100644 index 0000000..844bab7 --- /dev/null +++ b/apps/factory-dashboard/src/domain/deviceTypes.ts @@ -0,0 +1,120 @@ +export type DeviceType = 'laser' | 'cnc' | 'power' +export type DeviceStatusKey = 'running' | 'idle' | 'alarm' | 'offline' | 'normal' + +export type WeeklyStats = { + dates: string[] + produce: number[] + cuttime?: number[] +} + +export type DeviceStatus = { + key: DeviceStatusKey + label: string +} + +export type BaseFactoryDevice = { + id: string + name: string + type: DeviceType + online: boolean + offlineReason?: string + weeklyStats?: WeeklyStats | null +} + +export type LaserMachineData = { + startRate?: string + cutRate?: string + pierceCount?: number + cutLength?: number + moveLength?: number + workTime?: number + laserTime?: number + timestamp?: string + CutSystemState?: { + NcState?: { + SysState?: number + AlarmCount?: number + AlarmMsg?: string + TaskName?: string + CutPercent?: number + LaserPower?: number + WorkSpeed?: number + FeedRate?: number + } + DeviceState?: { + GasPressure?: number + GasType?: string | number + IsLaserOn?: boolean + IsGasOn?: boolean + } + } +} + +export type CncMachineData = { + alarm?: string[] + alarmStatus?: number + boottime?: string + runtime?: string + cuttime?: string + cycletime?: string + currentProduceCount?: number + programCurrent?: { + name?: string + number?: number + } + setFeedRate?: number + setSpindleSpeed?: number + spindleSpeedAndFeedRate?: { + speed?: number + feedRate?: number + } + statusInfo?: { + Alarm?: number + Emergency?: number + Motion?: number + MSTB?: number + RunStatus?: string + WorkMode?: string + } + sysInfo?: { + axes?: number + cncType?: string + mtType?: string + } + timestamp?: string +} + +export type PowerMachineData = { + timestamp?: string + slave1?: { + current1?: string + current2?: string + current3?: string + } +} + +export type LaserDevice = BaseFactoryDevice & { + type: 'laser' + appName?: string + ip?: string + machineData: LaserMachineData | null +} + +export type CncDevice = BaseFactoryDevice & { + type: 'cnc' + machineData: CncMachineData | null +} + +export type PowerDevice = BaseFactoryDevice & { + type: 'power' + machineData: PowerMachineData | null + powerHistory?: number[] +} + +export type FactoryDevice = LaserDevice | CncDevice | PowerDevice + +export type AlarmRow = { + time: string + device: string + message: string +} diff --git a/apps/factory-dashboard/src/main.tsx b/apps/factory-dashboard/src/main.tsx new file mode 100644 index 0000000..641bf03 --- /dev/null +++ b/apps/factory-dashboard/src/main.tsx @@ -0,0 +1,6 @@ +import { createRoot } from 'react-dom/client' +import { ProjectScreen } from './ProjectScreen' +import '@dev-screen-starter/visual-kit/styles.css' +import './styles/factory-dashboard.css' + +createRoot(document.getElementById('root')!).render() diff --git a/apps/factory-dashboard/src/mock/factoryDevices.ts b/apps/factory-dashboard/src/mock/factoryDevices.ts new file mode 100644 index 0000000..8f6e295 --- /dev/null +++ b/apps/factory-dashboard/src/mock/factoryDevices.ts @@ -0,0 +1,146 @@ +import type { AlarmRow, FactoryDevice } from '../domain/deviceTypes' +import { getLast7DaysChartInfo } from '../utils/weekLabels' + +const { labels } = getLast7DaysChartInfo() + +export const factoryDevices: FactoryDevice[] = [ + { + id: 'laser:192.168.1.101:HypCut', + name: '激光 #1', + type: 'laser', + online: true, + appName: 'HypCut', + ip: '192.168.1.101', + machineData: { + startRate: '83.4%', + cutRate: '42.1%', + pierceCount: 3728, + cutLength: 537221.81, + moveLength: 7271764.2, + timestamp: '2026-04-06 22:15:00', + CutSystemState: { + NcState: { + SysState: 8, + AlarmCount: 0, + AlarmMsg: '', + TaskName: '20180814001.lxds', + CutPercent: 62.5, + LaserPower: 3000, + WorkSpeed: 500, + FeedRate: 100 + }, + DeviceState: { + GasPressure: 4.5, + GasType: 'Oxygen', + IsLaserOn: true, + IsGasOn: true + } + } + }, + weeklyStats: { + dates: labels, + produce: [3500, 3600, 3728, 3800, 3650, 3890, 4020], + cuttime: [0.4, 0.45, 0.48, 0.5, 0.47, 0.55, 0.58] + } + }, + { + id: 'laser:192.168.1.102:TubePro', + name: '激光 #2', + type: 'laser', + online: true, + appName: 'TubePro', + ip: '192.168.1.102', + machineData: { + startRate: '76.2%', + cutRate: '35.8%', + pierceCount: 4120, + cutLength: 680000.2, + timestamp: '2026-04-06 22:15:00', + CutSystemState: { + NcState: { + SysState: 0, + AlarmCount: 1, + AlarmMsg: '气压不足', + TaskName: '20201010002.lxds', + CutPercent: 0, + LaserPower: 2000 + }, + DeviceState: { + GasPressure: 0.8, + GasType: 'Nitrogen', + IsLaserOn: false, + IsGasOn: false + } + } + }, + weeklyStats: { + dates: labels, + produce: [4100, 4200, 4000, 4300, 4150, 4220, 4380], + cuttime: [0.55, 0.6, 0.5, 0.65, 0.52, 0.58, 0.62] + } + }, + ...Array.from({ length: 13 }, (_, index) => { + const id = index + 1 + const running = [0, 4, 7].includes(index) + const offline = [8, 10].includes(index) + return { + id: `B-${String(id).padStart(3, '0')}`, + name: `CNC-${String(id).padStart(3, '0')}`, + type: 'cnc' as const, + online: !offline, + offlineReason: offline ? '等待 MQTT 首条数据' : undefined, + machineData: offline + ? null + : { + alarm: index === 5 ? ['主轴冷却液不足'] : [], + alarmStatus: index === 5 ? 1 : 0, + boottime: `${5400 + index * 320} H 40 M 0 S`, + runtime: `${320 + index * 18} H 13 M 25 S`, + cuttime: `${2029 + index * 96} H 22 M 15 S`, + cycletime: `0 H ${String(12 + index).padStart(2, '0')} M 30 S`, + currentProduceCount: 400 + index * 870, + programCurrent: { name: `O${2168 + index}`, number: 2168 + index }, + setFeedRate: 100, + setSpindleSpeed: 100, + spindleSpeedAndFeedRate: { feedRate: running ? 500 : 0, speed: running ? 1200 : 0 }, + statusInfo: { + Alarm: index === 5 ? 1 : 0, + Emergency: 0, + Motion: running ? 1 : 0, + MSTB: running ? 1 : 0, + RunStatus: running ? '3' : '0', + WorkMode: running ? '1' : '5' + }, + sysInfo: { axes: index > 7 ? 4 : 3, cncType: index > 3 ? 'Series 0i-MF' : 'Series 0i-MD', mtType: 'Machining center' }, + timestamp: '2026-04-06 22:15:00' + }, + weeklyStats: { + dates: labels, + produce: [80 + index * 8, 92 + index * 9, 76 + index * 10, 110 + index * 7, 128 + index * 8, 118 + index * 9, 136 + index * 10], + cuttime: [7, 7.5, 8, 7.8, 8, 8.4, 8.9] + } + } + }), + { + id: 'C-001', + name: '配电柜 #1', + type: 'power', + online: true, + machineData: { timestamp: '2026-04-06 22:15:00', slave1: { current1: '12.4A', current2: '13.1A', current3: '12.8A' } }, + powerHistory: [8.2, 8.5, 8.4, 8.9, 9.2, 9.1, 8.8] + }, + { + id: 'C-002', + name: '配电柜 #2', + type: 'power', + online: true, + machineData: { timestamp: '2026-04-06 22:15:00', slave1: { current1: '16.8A', current2: '15.4A', current3: '16.1A' } }, + powerHistory: [10.2, 10.5, 10.9, 11.4, 11.8, 11.6, 11.2] + } +] + +export const factoryAlarms: AlarmRow[] = [ + { time: '18:20', device: '激光 #2', message: '气压不足' }, + { time: '18:12', device: 'CNC-006', message: '主轴冷却液不足' }, + { time: '17:48', device: '配电柜 #2', message: 'B 相电流偏高' } +] diff --git a/apps/factory-dashboard/src/pages/DashboardPage.tsx b/apps/factory-dashboard/src/pages/DashboardPage.tsx new file mode 100644 index 0000000..a38635e --- /dev/null +++ b/apps/factory-dashboard/src/pages/DashboardPage.tsx @@ -0,0 +1,65 @@ +import { ScreenStage, type ScaleMode } from '@dev-screen-starter/screen-core' +import { useMemo, useState } from 'react' +import { AlarmPanel } from '../components/AlarmPanel' +import { DeviceListPanel } from '../components/DeviceListPanel' +import { FocusDevicePanel } from '../components/FocusDevicePanel' +import { HeaderBar } from '../components/HeaderBar' +import { StatusSummary } from '../components/StatusSummary' +import { factoryAlarms, factoryDevices } from '../mock/factoryDevices' +import { getLast7DaysChartInfo } from '../utils/weekLabels' + +const scaleModes: ScaleMode[] = ['fit', 'fill', 'stretch', 'none'] + +function readScaleMode(): ScaleMode { + if (typeof window === 'undefined') { + return 'fit' + } + + const value = new URLSearchParams(window.location.search).get('scaleMode') + return scaleModes.includes(value as ScaleMode) ? (value as ScaleMode) : 'fit' +} + +export function DashboardPage() { + const scaleMode = readScaleMode() + const defaultFocus = factoryDevices.find((device) => device.online && device.type === 'cnc') ?? factoryDevices[0] + const [selectedDeviceId, setSelectedDeviceId] = useState(defaultFocus.id) + const selectedDevice = useMemo( + () => factoryDevices.find((device) => device.id === selectedDeviceId) ?? defaultFocus, + [defaultFocus, selectedDeviceId] + ) + const { labels, todayIdx } = getLast7DaysChartInfo() + const weeklyProduce = labels.map((_, index) => + factoryDevices.reduce((sum, device) => sum + Number(device.weeklyStats?.produce?.[index] || 0), 0) + ) + + return ( + +
+ + +
+ + +
+ +
+ + +
+ + +
+
+ ) +} diff --git a/apps/factory-dashboard/src/styles/factory-dashboard.css b/apps/factory-dashboard/src/styles/factory-dashboard.css new file mode 100644 index 0000000..7cddd9e --- /dev/null +++ b/apps/factory-dashboard/src/styles/factory-dashboard.css @@ -0,0 +1,1039 @@ +* { + box-sizing: border-box; +} + +body { + margin: 0; + background: #020c20; + color: #d0e8ff; + font-family: + "Noto Sans SC", "PingFang SC", "Microsoft YaHei", Inter, ui-sans-serif, system-ui, sans-serif; +} + +button { + font: inherit; +} + +.screen-viewport { + background: #020c20; + height: 100vh; + overflow: hidden; + position: relative; + width: 100vw; +} + +.screen-stage { + left: 50%; + overflow: hidden; + position: absolute; + top: 50%; + transform-origin: center center; +} + +.factory-dashboard { + background: + linear-gradient(180deg, rgb(4 11 28 / 96%), rgb(2 12 32 / 98%)), + radial-gradient(circle at 50% 0, rgb(4 185 255 / 18%), transparent 34%); + display: flex; + flex-direction: column; + height: 1080px; + overflow: hidden; + width: 1920px; +} + +.factory-header { + align-items: center; + background: linear-gradient(180deg, #040b1c, #0d1b3e); + border-bottom: 2px solid rgb(4 185 255 / 26%); + display: flex; + height: 70px; + justify-content: center; + position: relative; +} + +.header-line { + background: linear-gradient(90deg, transparent, rgb(4 185 255 / 80%), transparent); + bottom: -2px; + height: 1px; + left: 360px; + position: absolute; + right: 360px; +} + +.header-time { + left: 330px; + position: absolute; + top: 12px; +} + +.header-time span { + color: #8eb8d8; + display: block; + font-size: 13px; +} + +.header-time strong { + color: #04b9ff; + display: block; + font-size: 22px; + letter-spacing: 3px; +} + +.header-title span { + color: #f0f7ff; + font-size: 30px; + font-weight: 800; + letter-spacing: 6px; + text-shadow: 0 0 20px rgb(4 185 255 / 65%); +} + +.header-sub { + color: #5a7a9a; + font-size: 12px; + position: absolute; + right: 330px; + top: 28px; +} + +.factory-main { + display: flex; + flex: 1; + gap: 12px; + min-height: 0; + padding: 10px 14px; +} + +.side-panel { + background: rgb(4 20 55 / 56%); + border: 1px solid rgb(4 185 255 / 16%); + border-radius: 8px; + height: 100%; + min-height: 0; + padding: 12px; +} + +.left-panel { + flex: 0 0 330px; +} + +.right-panel { + display: flex; + flex: 0 0 360px; + flex-direction: column; + gap: 10px; +} + +.center-panel { + display: flex; + flex: 1; + flex-direction: column; + min-height: 0; +} + +.screen-panel { + background: rgb(8 22 36 / 86%); + border: 1px solid rgb(88 130 171 / 36%); + border-radius: 8px; + display: flex; + flex-direction: column; + padding: 16px; +} + +.screen-panel header { + align-items: center; + color: #d7e6f7; + display: flex; + font-size: 16px; + font-weight: 800; + justify-content: space-between; + margin-bottom: 10px; +} + +.screen-panel-body { + flex: 1; + min-height: 0; +} + +.chart-host { + height: 100%; + width: 100%; +} + +.chart-panel-body { + position: relative; +} + +.chart-panel-extra { + color: #88a1bd; + font-size: 12px; + font-weight: 400; +} + +.chart-panel-state { + align-items: center; + color: #88a1bd; + display: flex; + height: 100%; + justify-content: center; +} + +.chart-panel-state.is-error { + color: #ff9fa7; +} + +.device-section { + flex: 0 0 auto; +} + +.device-section.grow { + display: flex; + flex: 1; + flex-direction: column; + min-height: 0; +} + +.device-section header { + align-items: center; + display: flex; + gap: 8px; + justify-content: center; + margin-bottom: 6px; +} + +.device-section header i { + background: linear-gradient(90deg, transparent, rgb(4 185 255 / 80%)); + display: block; + height: 1px; + width: 80px; +} + +.device-section header i:last-child { + transform: scaleX(-1); +} + +.device-section header span { + color: #8eb8d8; + font-size: 13px; + font-weight: 800; + letter-spacing: 3px; + white-space: nowrap; +} + +.device-section.red header i { + background: linear-gradient(90deg, transparent, rgb(236 100 108 / 90%)); +} + +.device-section.amber header i { + background: linear-gradient(90deg, transparent, rgb(216 161 62 / 90%)); +} + +.laser-grid { + display: grid; + gap: 10px; + grid-template-columns: repeat(2, minmax(0, 1fr)); +} + +.cnc-grid { + display: grid; + flex: 1; + gap: 8px; + grid-template-columns: repeat(4, minmax(0, 1fr)); + grid-template-rows: repeat(3, minmax(0, 1fr)); + min-height: 0; +} + +.power-grid { + display: grid; + gap: 10px; + grid-template-columns: repeat(2, minmax(0, 1fr)); +} + +.panel-title { + color: #04b9ff; + font-size: 14px; + font-weight: 800; + letter-spacing: 2px; + margin-bottom: 8px; + text-shadow: 0 0 8px rgb(4 185 255 / 28%); +} + +.panel-title.compact { + margin-top: 12px; +} + +.status-summary, +.alarm-panel { + display: flex; + flex-direction: column; + min-height: 0; +} + +.right-panel .status-summary { + flex: 0 0 445px; +} + +.right-panel .alarm-panel { + flex: 1; +} + +.device-list-panel { + display: flex; + flex-direction: column; + height: 100%; + min-height: 0; +} + +.device-search { + background: rgb(6 18 42 / 90%); + border: 1px solid rgb(4 185 255 / 22%); + border-radius: 6px; + color: #d0e8ff; + font-size: 13px; + height: 36px; + outline: none; + padding: 0 12px; +} + +.device-search::placeholder { + color: #5a7a9a; +} + +.status-filter { + display: grid; + gap: 6px; + grid-template-columns: repeat(4, 1fr); + margin: 10px 0; +} + +.status-filter button { + background: rgb(4 185 255 / 8%); + border: 1px solid rgb(4 185 255 / 18%); + border-radius: 6px; + color: #8eb8d8; + cursor: pointer; + font-size: 12px; + height: 30px; +} + +.status-filter button.active { + background: rgb(4 185 255 / 18%); + border-color: rgb(4 185 255 / 48%); + color: #f0f7ff; +} + +.device-list { + display: flex; + flex: 1; + flex-direction: column; + gap: 6px; + min-height: 0; + overflow: auto; + padding-right: 4px; +} + +.device-list-item { + align-items: center; + background: rgb(6 18 42 / 78%); + border: 1px solid rgb(88 130 171 / 20%); + border-radius: 6px; + color: #d0e8ff; + cursor: pointer; + display: grid; + gap: 8px; + grid-template-columns: 10px 1fr 54px; + min-height: 42px; + padding: 0 10px; + text-align: left; +} + +.device-list-item.selected { + background: rgb(4 185 255 / 14%); + border-color: rgb(4 185 255 / 58%); + box-shadow: inset 0 0 16px rgb(4 185 255 / 8%); +} + +.device-list-item strong { + color: #f0f7ff; + font-size: 14px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.device-list-item small { + color: #8eb8d8; + font-size: 12px; + text-align: right; +} + +.list-status-dot { + border-radius: 50%; + height: 8px; + width: 8px; +} + +.status-count-grid { + display: grid; + gap: 5px; + grid-template-columns: 1fr 1fr; + margin-bottom: 8px; +} + +.status-count { + border: 1px solid; + border-radius: 6px; + padding: 6px 2px; + text-align: center; +} + +.status-count strong { + display: block; + font-size: 22px; + line-height: 1; +} + +.status-count span { + color: #5a7a9a; + display: block; + font-size: 10px; + margin-top: 3px; +} + +.status-count.running { + background: rgb(86 208 138 / 7%); + border-color: rgb(86 208 138 / 25%); +} + +.status-count.running strong { + color: #56d08a; +} + +.status-count.idle { + background: rgb(216 161 62 / 7%); + border-color: rgb(216 161 62 / 25%); +} + +.status-count.idle strong { + color: #d8a13e; +} + +.status-count.alarm { + background: rgb(236 100 108 / 8%); + border-color: rgb(236 100 108 / 28%); +} + +.status-count.alarm strong { + color: #ec646c; +} + +.status-count.offline { + background: rgb(100 120 142 / 8%); + border-color: rgb(100 120 142 / 25%); +} + +.status-count.offline strong { + color: #66788e; +} + +.water-pair { + display: flex; + gap: 8px; + margin-bottom: 8px; +} + +.water-pair .vk-water-level { + flex: 1; + gap: 6px; + padding: 6px; +} + +.water-pair .vk-water-level-tank { + height: 60px; + width: 60px; +} + +.summary-total { + background: rgb(4 185 255 / 5%); + border: 1px solid rgb(4 185 255 / 15%); + border-radius: 6px; + margin-bottom: 4px; + padding: 6px 8px; +} + +.summary-total .vk-flip-number { + background: transparent; + border: 0; + padding: 0; +} + +.today-produce { + color: #7ea3c0; + font-size: 11px; + margin-top: 4px; + text-align: center; +} + +.today-produce strong { + color: #56d08a; +} + +.mini-bars { + align-items: flex-end; + display: flex; + flex: 1; + gap: 3px; + min-height: 72px; +} + +.mini-bar { + align-items: center; + display: flex; + flex: 1; + flex-direction: column; + height: 100%; +} + +.mini-bar span, +.mini-bar small { + color: #5a7a9a; + font-size: 8px; +} + +.mini-bar div { + align-items: flex-end; + background: rgb(4 185 255 / 5%); + border-radius: 2px 2px 0 0; + display: flex; + flex: 1; + width: 100%; +} + +.mini-bar i { + background: linear-gradient(180deg, rgb(4 185 255 / 70%), rgb(26 90 154 / 90%)); + border-radius: 2px 2px 0 0; + display: block; + width: 100%; +} + +.mini-bar i.today { + background: linear-gradient(180deg, #56d08a, #04b9ff); +} + +.device-card { + background: linear-gradient(135deg, #0d1b35, #050f24); + border: 1px solid #1e3a6a; + border-radius: 10px; + color: inherit; + cursor: pointer; + display: flex; + flex-direction: column; + gap: 8px; + height: 100%; + min-height: 0; + padding: 12px 14px; + text-align: left; + transition: border-color 0.2s, box-shadow 0.2s; +} + +.device-card:hover { + border-color: #04b9ff; + box-shadow: 0 0 14px rgb(4 185 255 / 16%); +} + +.device-card.status-running, +.device-card.status-normal { + border-color: rgb(86 208 138 / 45%); +} + +.device-card.status-alarm { + border-color: rgb(236 100 108 / 70%); +} + +.device-card.status-offline { + border-color: #333; + opacity: 0.62; +} + +.focus-panel { + background: + linear-gradient(180deg, rgb(8 22 36 / 88%), rgb(4 16 38 / 92%)), + radial-gradient(circle at 50% 8%, rgb(4 185 255 / 16%), transparent 36%); + border: 1px solid rgb(88 130 171 / 34%); + border-radius: 8px; + display: flex; + flex: 1; + flex-direction: column; + min-height: 0; + padding: 16px; +} + +.focus-panel.status-running, +.focus-panel.status-normal { + border-color: rgb(86 208 138 / 42%); +} + +.focus-panel.status-alarm { + border-color: rgb(236 100 108 / 55%); +} + +.focus-header { + align-items: center; + border-bottom: 1px solid rgb(88 130 171 / 18%); + display: flex; + justify-content: space-between; + margin-bottom: 14px; + padding-bottom: 12px; +} + +.focus-header span { + color: #8eb8d8; + display: block; + font-size: 14px; + margin-bottom: 8px; +} + +.focus-header strong { + color: #f0f7ff; + display: block; + font-size: 36px; + letter-spacing: 1px; + line-height: 1; +} + +.focus-state { + align-items: center; + border: 1px solid; + border-radius: 999px; + display: flex; + font-size: 16px; + font-weight: 800; + gap: 10px; + min-width: 130px; + padding: 8px 16px; +} + +.focus-state i { + border-radius: 50%; + height: 12px; + width: 12px; +} + +.focus-main { + display: grid; + flex: 1; + gap: 14px; + grid-template-rows: minmax(0, 320px) minmax(0, 1fr); + min-height: 0; +} + +.focus-realtime { + display: grid; + gap: 14px; + grid-template-columns: 430px 1fr; + min-height: 0; +} + +.focus-hero { + background: rgb(4 20 55 / 48%); + border: 1px solid rgb(4 185 255 / 15%); + border-radius: 8px; + display: grid; + gap: 12px; + grid-template-columns: 190px 1fr; + min-height: 0; + padding: 14px; +} + +.focus-hero .vk-water-level, +.focus-hero .vk-flip-number { + background: transparent; + border: 0; + padding: 0; +} + +.focus-hero .vk-water-level { + flex-direction: column; +} + +.focus-hero .vk-water-level-tank { + height: 112px; + width: 112px; +} + +.focus-task { + display: flex; + flex-direction: column; + justify-content: center; + min-width: 0; +} + +.focus-task span { + color: #8eb8d8; + font-size: 14px; +} + +.focus-task strong { + color: #f0f7ff; + font-size: 26px; + margin: 10px 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.focus-task small { + color: #04b9ff; + font-size: 16px; + font-weight: 800; +} + +.focus-metric-grid { + display: grid; + gap: 10px; + grid-template-columns: repeat(2, minmax(0, 1fr)); +} + +.focus-metric { + background: rgb(6 18 42 / 72%); + border: 1px solid rgb(88 130 171 / 24%); + border-radius: 8px; + display: flex; + flex-direction: column; + justify-content: center; + min-width: 0; + padding: 12px 16px; +} + +.focus-metric.warn { + border-color: rgb(236 100 108 / 54%); +} + +.focus-metric span { + color: #8eb8d8; + font-size: 14px; + margin-bottom: 10px; +} + +.focus-metric strong { + color: #f0f7ff; + font-size: 28px; + line-height: 1; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.focus-metric.warn strong { + color: #ff9fa7; +} + +.focus-metric small { + color: #8eb8d8; + font-size: 16px; + margin-left: 6px; +} + +.focus-trend { + min-height: 0; +} + +.focus-trend .screen-panel { + height: 100%; +} + +.device-card-head { + align-items: flex-start; + border-bottom: 1px solid rgb(4 185 255 / 14%); + display: flex; + gap: 10px; + justify-content: space-between; + padding-bottom: 5px; +} + +.device-card-head strong { + color: #f0f7ff; + display: block; + font-size: 16px; + font-weight: 800; +} + +.device-card-head span { + color: #5a7a9a; + font-size: 10px; +} + +.device-status { + align-items: center; + display: inline-flex; + flex: 0 0 auto; + font-size: 12px; + font-weight: 800; + gap: 5px; +} + +.status-dot { + border-radius: 50%; + display: inline-block; + height: 8px; + width: 8px; +} + +.status-dot.running, +.status-dot.normal { + background: #56d08a; + box-shadow: 0 0 8px rgb(86 208 138 / 70%); +} + +.status-dot.idle { + background: #d8a13e; +} + +.status-dot.alarm { + background: #ec646c; +} + +.status-dot.offline { + background: #66788e; +} + +.laser-card { + padding: 14px 18px; +} + +.laser-stats { + border-top: 1px dashed rgb(30 58 106 / 65%); + display: grid; + gap: 6px 10px; + grid-template-columns: repeat(4, minmax(0, 1fr)); + padding-top: 8px; +} + +.laser-stats span, +.cnc-produce span, +.cnc-line span:first-child, +.phase-grid span { + color: #5a7a9a; + font-size: 10px; +} + +.laser-stats strong { + color: #d0e8ff; + display: block; + font-size: 14px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.laser-stats small { + font-size: 10px; + margin-left: 2px; + opacity: 0.72; +} + +.device-card-foot { + display: flex; + flex-direction: column; + gap: 6px; + margin-top: auto; +} + +.device-card-foot > span { + color: #04b9ff; + font-size: 12px; + font-weight: 700; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.device-card-foot small { + color: #8eb8d8; +} + +.progress-line { + align-items: center; + display: flex; + gap: 8px; +} + +.progress-line i { + background: linear-gradient(90deg, #04b9ff, #56d08a); + border-radius: 999px; + display: block; + height: 8px; +} + +.progress-line::before { + background: #0d2654; + border-radius: 999px; + content: ""; + flex: 1; + height: 8px; + order: -1; +} + +.progress-line span { + color: #04b9ff; + font-size: 12px; + font-weight: 800; +} + +.cnc-produce { + align-items: baseline; + display: flex; + justify-content: space-between; +} + +.cnc-produce strong { + color: #56d08a; + font-size: 20px; +} + +.cnc-produce small { + font-size: 11px; + margin-left: 3px; +} + +.cnc-line { + align-items: center; + display: flex; + justify-content: space-between; +} + +.cnc-line span:last-child { + background: rgb(4 185 255 / 12%); + border: 1px solid rgb(4 185 255 / 24%); + border-radius: 3px; + color: #04b9ff; + font-size: 11px; + font-weight: 800; + padding: 1px 8px; +} + +.cnc-line.muted span:last-child { + background: rgb(0 0 0 / 20%); + border: 0; + color: #8eb8d8; +} + +.offline-copy { + align-items: center; + color: #66788e; + display: flex; + flex: 1; + font-size: 11px; + line-height: 1.5; +} + +.phase-grid { + display: flex; + gap: 20px; +} + +.phase-grid div { + display: flex; + flex: 1; + flex-direction: column; +} + +.phase-grid strong { + color: #04b9ff; + font-family: Consolas, monospace; + font-size: 18px; +} + +.phase-grid strong.warn { + color: #ec646c; +} + +.alarm-count { + background: rgb(236 100 108 / 10%); + border: 1px solid rgb(236 100 108 / 30%); + border-radius: 4px; + color: #ec646c; + font-size: 12px; + font-weight: 800; + margin-bottom: 8px; + padding: 3px 10px; + width: fit-content; +} + +.no-alarm { + color: #56d08a; + font-size: 13px; + font-weight: 700; + padding: 12px 0; +} + +.alarm-panel .vk-marquee-list { + flex: 1; + min-height: 0; +} + +.alarm-row { + align-items: center; + display: grid; + gap: 8px; + grid-template-columns: 54px 64px 1fr; +} + +.alarm-row span { + color: #8eb8d8; +} + +.alarm-row strong { + color: #04b9ff; +} + +.alarm-row small { + color: #ffb1b1; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.factory-footer { + align-items: center; + background: rgb(2 12 32 / 92%); + border-top: 1px solid rgb(4 185 255 / 18%); + color: #7ea3c0; + display: flex; + font-size: 12px; + gap: 16px; + height: 30px; + justify-content: center; +} + +.conn-dot { + background: #56d08a; + border-radius: 50%; + display: inline-block; + height: 8px; + width: 8px; +} + +.conn-dot.pulse { + box-shadow: 0 0 10px rgb(86 208 138 / 85%); +} + +.screen-stage-debug { + background: rgb(3 8 13 / 84%); + border: 1px solid rgb(100 135 170 / 35%); + border-radius: 6px; + bottom: 18px; + color: #9fb4cc; + display: flex; + flex-wrap: wrap; + gap: 10px; + max-width: min(760px, calc(100vw - 36px)); + padding: 8px 10px; + position: absolute; + right: 18px; + z-index: 10; +} + +.screen-stage-debug span { + font-size: 12px; + white-space: nowrap; +} diff --git a/apps/factory-dashboard/src/utils/weekLabels.ts b/apps/factory-dashboard/src/utils/weekLabels.ts new file mode 100644 index 0000000..a8e3cd9 --- /dev/null +++ b/apps/factory-dashboard/src/utils/weekLabels.ts @@ -0,0 +1,12 @@ +export function getLast7DaysChartInfo() { + const today = new Date() + const labels: string[] = [] + + for (let index = 6; index >= 0; index -= 1) { + const date = new Date(today) + date.setDate(today.getDate() - index) + labels.push(`${String(date.getMonth() + 1).padStart(2, '0')}/${String(date.getDate()).padStart(2, '0')}`) + } + + return { labels, todayIdx: 6 } +} diff --git a/apps/factory-dashboard/tsconfig.json b/apps/factory-dashboard/tsconfig.json new file mode 100644 index 0000000..3bc1e46 --- /dev/null +++ b/apps/factory-dashboard/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "jsx": "react-jsx", + "types": ["vite/client"] + }, + "include": ["src", "vite.config.ts"] +} diff --git a/apps/factory-dashboard/vite.config.ts b/apps/factory-dashboard/vite.config.ts new file mode 100644 index 0000000..12f7f53 --- /dev/null +++ b/apps/factory-dashboard/vite.config.ts @@ -0,0 +1,6 @@ +import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite' + +export default defineConfig({ + plugins: [react()] +})