Files
web-Iot/src/pages/WorkOrder.tsx

513 lines
22 KiB
TypeScript
Raw Normal View History

import React, { useState } from 'react';
import {
Layout, Card, Row, Col, Button, Table, Tag, Select, Input, Typography, Space,
2026-05-11 11:59:17 +08:00
Statistic, message, Drawer, Descriptions, Timeline, Divider, Form, Modal
} from 'antd';
import {
2026-05-11 11:59:17 +08:00
PlusOutlined, SearchOutlined, EditOutlined, EyeOutlined,
ClockCircleOutlined, CheckCircleOutlined, PlayCircleOutlined,
CloseCircleOutlined, ThunderboltOutlined, SettingOutlined,
SendOutlined, PauseOutlined, ArrowRightOutlined, FileDoneOutlined,
RobotOutlined, CloudOutlined, RiseOutlined,
BranchesOutlined
} from '@ant-design/icons';
2026-05-11 11:59:17 +08:00
import { Pie, Line, Bar } from '@ant-design/charts';
import dayjs from 'dayjs';
const { Option } = Select;
const { Search } = Input;
const { Text, Title } = Typography;
2026-05-11 11:59:17 +08:00
// 模拟数据(完全匹配参考图)
const workOrderList = [
{
2026-05-11 11:59:17 +08:00
id: 'WO20250524001',
title: '逆变器 INV-05 告警排查',
source: 'AI诊断',
type: '检修',
priority: 'high',
handler: '李工',
deadline: '2025-05-24 14:30',
status: 'pending',
description: ''
},
{
id: 'WO20250524002',
title: '区块 B-12 热斑复检',
source: '无人机巡检',
type: '巡检',
2026-05-11 11:59:17 +08:00
priority: 'high',
handler: '王工',
deadline: '2025-05-24 15:00',
status: 'processing',
description: '对AI识别热斑区域进行复检与红外复核,确认是否需要更换组件。'
},
{
id: 'WO20250524003',
title: '组件清洗任务 C-05',
source: '清洗优化',
type: '清洗',
priority: 'medium',
handler: '赵工',
deadline: '2025-05-24 16:00',
status: 'dispatched',
2026-05-11 11:59:17 +08:00
description: ''
},
{
2026-05-11 11:59:17 +08:00
id: 'WO20250524004',
title: '周界摄像头 CAM-08 离线修复',
source: '视频监控',
type: '维修',
priority: 'medium',
2026-05-11 11:59:17 +08:00
handler: '陈工',
deadline: '2025-05-24 17:30',
status: 'processing',
description: ''
},
{
id: 'WO20250524005',
title: '除草机器人补给',
source: '装备控制',
type: '运维',
priority: 'low',
handler: '刘工',
deadline: '2025-05-24 18:00',
status: 'pending',
2026-05-11 11:59:17 +08:00
description: ''
},
{
2026-05-11 11:59:17 +08:00
id: 'WO20250524006',
title: '逆变器室夜间巡检',
source: '人工创建',
type: '巡检',
priority: 'medium',
handler: '张运维',
2026-05-11 11:59:17 +08:00
deadline: '2025-05-24 21:00',
status: 'completed',
description: ''
}
];
// 工单状态配置
const statusConfig = {
2026-05-11 11:59:17 +08:00
pending: { label: '待处理', color: '#1890ff', icon: <ClockCircleOutlined /> },
dispatched: { label: '已派发', color: '#52c41a', icon: <SendOutlined /> },
processing: { label: '执行中', color: '#2f54eb', icon: <PlayCircleOutlined /> },
suspended: { label: '挂起', color: '#faad14', icon: <PauseOutlined /> },
2026-05-11 11:59:17 +08:00
completed: { label: '已完成', color: '#52c41a', icon: <CheckCircleOutlined /> },
closed: { label: '已关闭', color: '#8c8c8c', icon: <CloseCircleOutlined /> }
};
// 优先级配置
const priorityConfig = {
low: { label: '低', color: '#52c41a' },
medium: { label: '中', color: '#faad14' },
high: { label: '高', color: '#ff4d4f' },
urgent: { label: '紧急', color: '#f5222d' }
};
2026-05-11 11:59:17 +08:00
// 统计卡片数据
const overviewCards = [
{ title: '今日新增工单', value: 18, suffix: '单', desc: '较昨日 +3', color: '#1890ff', icon: <FileDoneOutlined /> },
{ title: '待处理工单', value: 12, suffix: '单', desc: '高优先级 5', color: '#ff4d4f', icon: <ClockCircleOutlined /> },
{ title: '执行中工单', value: 9, suffix: '单', desc: '按时率 92%', color: '#52c41a', icon: <PlayCircleOutlined /> },
{ title: '已完成工单', value: 126, suffix: '单', desc: '本月累计', color: '#52c41a', icon: <CheckCircleOutlined /> },
{ title: '平均处理时长', value: 4.3, suffix: '小时', desc: '较上周 -12% ↓', color: '#1890ff', icon: <ClockCircleOutlined /> },
{ title: 'AI建议生成', value: 7, suffix: '单', desc: '今日自动生成', color: '#722ed1', icon: <RobotOutlined /> }
];
// 任务排班数据
const scheduleData = [
{ handler: '李工', tasks: [{ title: 'INV-05 告警排查', time: '08:30 - 12:00', type: 'alarm' }] },
{ handler: '王工', tasks: [{ title: 'B-12 热斑复检', time: '13:30 - 15:00', type: 'inspect' }] },
{ handler: '赵工', tasks: [{ title: '组件清洗 C-05', time: '09:00 - 12:00', type: 'clean' }, { title: '清洗效果复检', time: '15:00 - 17:00', type: 'clean' }] },
{ handler: '陈工', tasks: [{ title: '周界摄像头修复', time: '10:00 - 12:30', type: 'repair' }, { title: '设备巡检', time: '15:30 - 17:30', type: 'inspect' }] }
];
// 告警趋势数据
const alarmTrendData = [
{ date: '05-18', count: 5 },
{ date: '05-19', count: 10 },
{ date: '05-20', count: 5 },
{ date: '05-21', count: 5 },
{ date: '05-22', count: 12 },
{ date: '05-23', count: 10 },
{ date: '05-24', count: 12 }
];
// 告警列表数据
const alarmList = [
{ name: 'INV-05 逆变器告警', time: '05-24 10:24' },
{ name: 'B-12 区块热斑告警', time: '05-24 09:56' },
{ name: 'B-12 组件温度异常', time: '05-24 09:32' }
];
2026-05-11 11:59:17 +08:00
export default function WorkOrderPage() {
const [selectedOrder, setSelectedOrder] = useState(workOrderList[1]); // 默认选中执行中的工单
const [drawerVisible, setDrawerVisible] = useState(false);
const [editModalVisible, setEditModalVisible] = useState(false);
const [editingOrder, setEditingOrder] = useState(null);
const [editForm] = Form.useForm();
// 表格列定义
const columns = [
2026-05-11 11:59:17 +08:00
{ title: '工单编号', dataIndex: 'id', key: 'id', width: 140 },
{ title: '工单标题', dataIndex: 'title', key: 'title' },
{ title: '来源', dataIndex: 'source', key: 'source', width: 100 },
{ title: '类型', dataIndex: 'type', key: 'type', width: 80 },
{
title: '优先级',
dataIndex: 'priority',
key: 'priority',
width: 80,
render: (priority) => (
2026-05-11 11:59:17 +08:00
<Tag color={priorityConfig[priority]?.color} style={{ borderRadius: 4 }}>
{priorityConfig[priority]?.label}
</Tag>
)
},
2026-05-11 11:59:17 +08:00
{ title: '负责人', dataIndex: 'handler', key: 'handler', width: 80 },
{ title: '截止时间', dataIndex: 'deadline', key: 'deadline', width: 160 },
{
title: '状态',
dataIndex: 'status',
key: 'status',
width: 100,
render: (status) => (
2026-05-11 11:59:17 +08:00
<Tag color={statusConfig[status]?.color} style={{ borderRadius: 4 }}>
{statusConfig[status]?.label}
</Tag>
)
},
{
title: '操作',
key: 'action',
2026-05-11 11:59:17 +08:00
width: 80,
render: (_, record) => (
2026-05-11 11:59:17 +08:00
<Button type="link" size="small" onClick={() => { setSelectedOrder(record); setDrawerVisible(true); }}>
查看
</Button>
)
}
];
2026-05-11 11:59:17 +08:00
// 工单状态分布饼图数据
const pieData = [
2026-05-11 11:59:17 +08:00
{ type: '待处理', value: 12, color: '#1890ff' },
{ type: '执行中', value: 9, color: '#2f54eb' },
{ type: '已完成', value: 126, color: '#52c41a' },
{ type: '已挂起', value: 4, color: '#faad14' }
];
return (
<div style={{ padding: 20, background: '#f5f7fa', minHeight: '100vh' }}>
2026-05-11 11:59:17 +08:00
{/* 顶部统计卡片 */}
<Row gutter={16} style={{ marginBottom: 20 }}>
{overviewCards.map((card, idx) => (
<Col span={4} key={idx}>
<Card bordered={false} style={{ borderRadius: 8, height: 120 }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
<div>
<div style={{ fontSize: 14, color: '#666' }}>{card.title}</div>
<div style={{ fontSize: 28, fontWeight: 700, color: card.color, margin: '8px 0' }}>
{card.value} <span style={{ fontSize: 14, fontWeight: 400 }}>{card.suffix}</span>
</div>
<div style={{ fontSize: 12, color: '#999' }}>{card.desc}</div>
</div>
<div style={{ width: 48, height: 48, borderRadius: '50%', background: `${card.color}15`, display: 'flex', alignItems: 'center', justifyContent: 'center', color: card.color, fontSize: 20 }}>
{card.icon}
</div>
</div>
</Card>
</Col>
))}
</Row>
{/* 筛选栏 */}
<div style={{ display: 'flex', alignItems: 'center', marginBottom: 20, gap: 16, flexWrap: 'wrap' }}>
<Select placeholder="工单类型" style={{ width: 120 }} defaultValue="all">
<Option value="all">全部</Option>
<Option value="inspect">巡检</Option>
<Option value="repair">维修</Option>
<Option value="clean">清洗</Option>
</Select>
<Select placeholder="优先级" style={{ width: 120 }} defaultValue="all">
<Option value="all">全部</Option>
<Option value="high">高</Option>
<Option value="medium">中</Option>
<Option value="low">低</Option>
</Select>
<Select placeholder="负责人" style={{ width: 120 }} defaultValue="all">
<Option value="all">全部</Option>
<Option value="李工">李工</Option>
<Option value="王工">王工</Option>
<Option value="赵工">赵工</Option>
</Select>
<Space>
2026-05-11 11:59:17 +08:00
<span>时间范围</span>
<Input style={{ width: 180 }} value="2025-05-24 ~ 2025-05-24" readOnly />
</Space>
<Select placeholder="状态" style={{ width: 120 }} defaultValue="all">
<Option value="all">全部</Option>
<Option value="pending">待处理</Option>
<Option value="processing">执行中</Option>
<Option value="completed">已完成</Option>
</Select>
<Input placeholder="请输入工单编号/标题" style={{ width: 240 }} prefix={<SearchOutlined />} />
<Space>
<Button>重置</Button>
<Button type="primary">查询</Button>
</Space>
</div>
2026-05-11 11:59:17 +08:00
<Row gutter={16}>
{/* 左侧工单列表 */}
<Col span={14}>
<Card bordered={false} style={{ borderRadius: 8, marginBottom: 20 }} title="工单列表(共 147 条)">
<Table
rowKey="id"
columns={columns}
dataSource={workOrderList}
pagination={{ pageSize: 15, showSizeChanger: true, showTotal: (total) => `共 ${total} 条` }}
scroll={{ x: 'max-content' }}
rowClassName={(record) => record.id === selectedOrder?.id ? 'selected-row' : ''}
onRow={(record) => ({ onClick: () => setSelectedOrder(record) })}
/>
2026-05-11 11:59:17 +08:00
<style>{`
.selected-row { background-color: #e6f7ff !important; }
`}</style>
</Card>
2026-05-11 11:59:17 +08:00
{/* 工单状态分布 + 任务排班 */}
<Row gutter={16}>
<Col span={8}>
<Card bordered={false} style={{ borderRadius: 8 }} title="工单状态分布">
<Pie
data={pieData}
angleField="value"
colorField="type"
color={['#1890ff', '#2f54eb', '#52c41a', '#faad14']}
radius={0.8}
innerRadius={0.6}
height={180}
label={{
formatter: (datum) => `${datum.value} (${((datum.value / 147) * 100).toFixed(2)}%)`
}}
interactions={[{ type: 'pie-legend-active' }]}
/>
<div style={{ textAlign: 'center', marginTop: -120 }}>
<div style={{ fontSize: 16, fontWeight: 600 }}>总数</div>
<div style={{ fontSize: 24, fontWeight: 700 }}>147</div>
</div>
</Card>
</Col>
<Col span={16}>
<Card bordered={false} style={{ borderRadius: 8 }} title={<div style={{ display: 'flex', justifyContent: 'space-between' }}><span>任务排班 / 日历视图</span><Button type="link">更多 </Button></div>}>
<div style={{ display: 'flex', alignItems: 'center', marginBottom: 16 }}>
<Button type="text" icon={<ArrowRightOutlined style={{ transform: 'rotate(180deg)' }} />} />
<span style={{ margin: '0 16px' }}>2025-05-24 (今天)</span>
<Button type="text" icon={<ArrowRightOutlined />} />
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
{scheduleData.map((item, idx) => (
<div key={idx} style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
<div style={{ width: 60, textAlign: 'right' }}>{item.handler}</div>
<div style={{ flex: 1, display: 'flex', gap: 16, height: 40, alignItems: 'center', position: 'relative' }}>
<div style={{ position: 'absolute', left: 0, right: 0, height: 1, background: '#e8e8e8', zIndex: 0 }} />
{item.tasks.map((task, i) => (
<div key={i} style={{
background: task.type === 'alarm' ? '#e6ffed' : task.type === 'inspect' ? '#e6f7ff' : task.type === 'clean' ? '#f9f0ff' : '#fff7e6',
border: '1px solid #d9d9d9',
borderRadius: 4,
padding: '4px 8px',
fontSize: 12,
zIndex: 1
}}>
<div>{task.title}</div>
<div style={{ color: '#666' }}>{task.time}</div>
</div>
))}
</div>
</div>
))}
</div>
</Card>
</Col>
</Row>
</Col>
2026-05-11 11:59:17 +08:00
{/* 右侧工单详情面板 */}
<Col span={10}>
<Card bordered={false} style={{ borderRadius: 8, marginBottom: 16 }} title={
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<div>
<Title level={5} style={{ margin: 0 }}>{selectedOrder?.title}</Title>
<Tag color="red" size="small">高优先级</Tag>
</div>
<Text type="secondary">工单编号: {selectedOrder?.id}</Text>
</div>
}>
<Row gutter={16} style={{ marginBottom: 16 }}>
<Col span={12}><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>来源:</span><span>{selectedOrder?.source}</span></div></Col>
<Col span={12}><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>工单类型:</span><span>{selectedOrder?.type}</span></div></Col>
<Col span={12}><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>负责人:</span><span>{selectedOrder?.handler}</span></div></Col>
<Col span={12}><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>协同人员:</span><span>无人机A01 / 张运维</span></div></Col>
<Col span={12}><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>计划时间:</span><span>2025-05-24 13:30 ~ 15:00</span></div></Col>
<Col span={12}><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>关联区域:</span><span>B-12</span></div></Col>
<Col span={12}><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>关联设备:</span><span>UAV-A01</span></div></Col>
<Col span={12}><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>当前状态:</span><Tag color="blue">执行中</Tag></div></Col>
</Row>
2026-05-11 11:59:17 +08:00
<div style={{ marginBottom: 16 }}>
<div style={{ fontSize: 14, fontWeight: 500, marginBottom: 8 }}>任务描述</div>
<div style={{ fontSize: 13, color: '#666', background: '#fafafa', padding: 12, borderRadius: 4 }}>
{selectedOrder?.description}
</div>
</div>
{/* 流程步骤 */}
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24, padding: '0 20px' }}>
{['已创建', '已派发', '执行中', '已完成'].map((step, idx) => (
<div key={idx} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<div style={{
width: 24, height: 24, borderRadius: '50%', background: idx < 3 ? '#1890ff' : '#d9d9d9',
display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#fff', fontSize: 12
}}>
{idx + 1}
</div>
<div style={{ fontSize: 12, marginTop: 4 }}>{step}</div>
</div>
))}
<div style={{ position: 'absolute', width: 'calc(100% - 120px)', height: 2, background: '#e8e8e8', left: 60, top: 100, zIndex: 0 }} />
</div>
{/* 操作按钮 */}
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
<Button type="primary">派发文单</Button>
<Button>转派</Button>
<Button>挂起</Button>
<Button type="primary" style={{ background: '#52c41a', borderColor: '#52c41a' }}>完成工单</Button>
</div>
</Card>
2026-05-11 11:59:17 +08:00
{/* AI建议与关联信息 */}
<Card bordered={false} style={{ borderRadius: 8 }} title="AI建议与关联信息">
<div style={{ display: 'flex', gap: 16, marginBottom: 16 }}>
<div style={{ flex: 1, background: '#f0f5ff', padding: 12, borderRadius: 8 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
<div style={{ width: 32, height: 32, borderRadius: 4, background: '#e6f7ff', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#1890ff' }}>
<CloudOutlined />
</div>
<div style={{ fontSize: 13, fontWeight: 500 }}>建议携带红外热像设备</div>
</div>
</div>
<div style={{ flex: 1, background: '#f6ffed', padding: 12, borderRadius: 8 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
<div style={{ width: 32, height: 32, borderRadius: 4, background: '#e6ffed', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#52c41a' }}>
<BranchesOutlined />
</div>
<div style={{ fontSize: 13, fontWeight: 500 }}>优先复检组件 B-12-03 / B-12-05</div>
</div>
</div>
<div style={{ flex: 1, background: '#fff7e6', padding: 12, borderRadius: 8 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
<div style={{ width: 32, height: 32, borderRadius: 4, background: '#fff7e6', display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#fa8c16' }}>
<ThunderboltOutlined />
</div>
<div style={{ fontSize: 13, fontWeight: 500 }}>预计影响发电 2.1%</div>
</div>
</div>
</div>
2026-05-11 11:59:17 +08:00
<Row gutter={16}>
<Col span={12}>
<div style={{ fontSize: 14, fontWeight: 500, marginBottom: 8 }}>关联告警趋势(近7天)</div>
<Line
data={alarmTrendData}
xField="date"
yField="count"
color="#1890ff"
point={{ size: 4 }}
height={120}
legend={false}
smooth
/>
</Col>
<Col span={12}>
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
<span style={{ fontSize: 14, fontWeight: 500 }}>关联告警列表(近3条)</span>
<Button type="link" size="small">查看全部 </Button>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{alarmList.map((alarm, idx) => (
<div key={idx} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '4px 8px', background: '#fafafa', borderRadius: 4 }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<div style={{ width: 8, height: 8, borderRadius: '50%', background: idx === 0 ? '#ff4d4f' : idx === 1 ? '#fa8c16' : '#faad14' }} />
<span style={{ fontSize: 13 }}>{alarm.name}</span>
</div>
<span style={{ fontSize: 12, color: '#999' }}>{alarm.time}</span>
</div>
))}
</div>
</Col>
</Row>
</Card>
</Col>
</Row>
{/* 工单详情抽屉 */}
<Drawer
title="工单详情"
placement="right"
width={600}
onClose={() => setDrawerVisible(false)}
open={drawerVisible}
destroyOnClose
>
2026-05-11 11:59:17 +08:00
{selectedOrder && (
<div>
2026-05-11 11:59:17 +08:00
<Descriptions column={2} bordered size="small" title="基础信息">
<Descriptions.Item label="工单编号">{selectedOrder.id}</Descriptions.Item>
<Descriptions.Item label="状态">{statusConfig[selectedOrder.status]?.label}</Descriptions.Item>
<Descriptions.Item label="标题">{selectedOrder.title}</Descriptions.Item>
<Descriptions.Item label="优先级">
2026-05-11 11:59:17 +08:00
<Tag color={priorityConfig[selectedOrder.priority]?.color}>{priorityConfig[selectedOrder.priority]?.label}</Tag>
</Descriptions.Item>
2026-05-11 11:59:17 +08:00
<Descriptions.Item label="来源">{selectedOrder.source}</Descriptions.Item>
<Descriptions.Item label="类型">{selectedOrder.type}</Descriptions.Item>
<Descriptions.Item label="负责人">{selectedOrder.handler || '—'}</Descriptions.Item>
<Descriptions.Item label="截止时间">{selectedOrder.deadline}</Descriptions.Item>
<Descriptions.Item label="描述" span={2}>{selectedOrder.description || '—'}</Descriptions.Item>
</Descriptions>
</div>
)}
</Drawer>
2026-05-11 11:59:17 +08:00
{/* 编辑工单弹窗 */}
<Modal
title="编辑工单"
open={editModalVisible}
onCancel={() => setEditModalVisible(false)}
2026-05-11 11:59:17 +08:00
onOk={() => { editForm.validateFields().then(values => { message.success('工单保存成功'); setEditModalVisible(false); }); }}
okText="保存"
cancelText="取消"
width={600}
destroyOnClose
>
<Form form={editForm} layout="vertical" initialValues={{ priority: 'low', source: '人工创建', type: '巡检' }}>
2026-05-11 11:59:17 +08:00
<Form.Item label="标题" name="title" rules={[{ required: true, message: '请输入标题' }]}><Input /></Form.Item>
<Row gutter={16}>
2026-05-11 11:59:17 +08:00
<Col span={12}><Form.Item label="来源" name="source"><Select><Option value="人工创建">人工创建</Option><Option value="告警">告警</Option><Option value="AI诊断">AI诊断</Option></Select></Form.Item></Col>
<Col span={12}><Form.Item label="类型" name="type"><Select><Option value="巡检">巡检</Option><Option value="故障排查">故障排查</Option><Option value="维护">维护</Option><Option value="清洗">清洗</Option></Select></Form.Item></Col>
</Row>
<Row gutter={16}>
2026-05-11 11:59:17 +08:00
<Col span={12}><Form.Item label="优先级" name="priority"><Select><Option value="low">低</Option><Option value="medium">中</Option><Option value="high">高</Option></Select></Form.Item></Col>
<Col span={12}><Form.Item label="负责人" name="handler"><Input /></Form.Item></Col>
</Row>
2026-05-11 11:59:17 +08:00
<Form.Item label="描述" name="description"><Input.TextArea rows={4} /></Form.Item>
</Form>
</Modal>
</div>
);
2026-05-11 11:59:17 +08:00
}