/** * 柜子详情页 * - 显示柜子基本信息(ID、状态) * - 按仓控板分组展示 6 个通道的状态卡片 */ import { useEffect, useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { Card, Tag, Typography, Spin, Grid, Button, Descriptions, Message, Modal, } from '@arco-design/web-react'; import { IconLeft, IconDesktop } from '@arco-design/web-react/icon'; import { cabinetApi, type CabinetDetail } from '@/api/devices'; const Row = Grid.Row; const Col = Grid.Col; /** 状态映射 */ const STATUS_MAP: Record = { 0: { label: '空闲', color: 'green' }, 1: { label: '充电中', color: 'blue' }, 2: { label: '故障', color: 'red' }, 3: { label: '禁用', color: 'orange' }, }; /** 柜子状态映射 */ const CABINET_STATUS_MAP: Record = { 0: { label: '离线', color: 'gray' }, 1: { label: '在线', color: 'green' }, 2: { label: '充电中', color: 'blue' }, 3: { label: '故障', color: 'red' }, }; export default function CabinetDetail() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [loading, setLoading] = useState(true); const [detail, setDetail] = useState(null); const [powLoading, setPowLoading] = useState(false); useEffect(() => { if (!id) return; setLoading(true); cabinetApi .getDetail(Number(id)) .then((res) => setDetail(res.data)) .catch(() => { // 如果详情接口不可用,显示提示 }) .finally(() => setLoading(false)); }, [id]); /** 接触器合闸 */ const handlePowOn = () => { if (!id) return; Modal.confirm({ title: '确认操作', content: '确定要合闸恢复380V供电吗?', onOk: async () => { setPowLoading(true); try { await cabinetApi.powOn(Number(id)); Message.success('合闸指令已发送'); // 刷新详情 const res = await cabinetApi.getDetail(Number(id)); setDetail(res.data); } catch { Message.error('操作失败'); } finally { setPowLoading(false); } }, }); }; /** 接触器分闸 */ const handlePowOff = () => { if (!id) return; Modal.confirm({ title: '确认操作', content: '确定要分闸切断380V供电吗?', onOk: async () => { setPowLoading(true); try { await cabinetApi.powOff(Number(id)); Message.success('分闸指令已发送'); // 刷新详情 const res = await cabinetApi.getDetail(Number(id)); setDetail(res.data); } catch { Message.error('操作失败'); } finally { setPowLoading(false); } }, }); }; if (loading) { return (
); } if (!detail) { return ( 柜子不存在或加载失败 ); } const cabStatus = CABINET_STATUS_MAP[detail.status] || { label: '未知', color: 'gray' }; return (
{/* 顶部导航 */}
柜子 {detail.abstract_id} {cabStatus.label}
{/* 柜子信息 */}
{/* 仓控板列表 */} {detail.cabin_boards.map((board) => ( {board.compartments.map((comp) => { const st = STATUS_MAP[comp.status] || { label: '未知', color: 'gray' }; return (
通道 {comp.channel_id}
{st.label}
电压: 0.0V
电流: 0.0A
功率: 0W
); })}
))}
); }