import React, { useState, useEffect } from 'react'; import { Layout, Card, Row, Col, Button, Table, Tag, Select, Input, Typography, Space, Statistic, Modal, message, Empty, Drawer, Descriptions, Timeline, Divider, Form, Tabs, Progress, Badge, DatePicker, Pagination } from 'antd'; import { CheckOutlined, ClockCircleOutlined, ControlOutlined, BarChartOutlined, RiseOutlined, ArrowUpOutlined, SearchOutlined, PlusOutlined, EditOutlined, DeleteOutlined, EyeOutlined, CommentOutlined, PauseOutlined, FormOutlined, ReloadOutlined, FilterOutlined, MoreOutlined, CheckCircleFilled, PlayCircleFilled, InfoCircleFilled, RobotOutlined, ThunderboltOutlined, AlertOutlined } from '@ant-design/icons'; import { Pie, Line } from '@ant-design/charts'; import { ClipboardList, Clock, Play, CheckCircle, Timer, Cpu, Calendar as CalendarIcon, ChevronRight, History, ExternalLink } from 'lucide-react'; // 导入工单接口 import { getWorkOrderApi, getWorkOrderDetailApi, updateWorkOrder, dispatchWorkOrder } from '../api/workOrder'; const { Option } = Select; const { Search } = Input; const { Text, Title } = Typography; const { RangePicker } = DatePicker; const FormItem = Form.Item; // 优先级数字映射 1高 2中 3低 const priorityConfig = { 1: { label: '高', color: '#ff4d4f', bg: '#fff1f0', border: '#ff4d4f' }, 2: { label: '中', color: '#faad14', bg: '#fff7e6', border: '#faad14' }, 3: { label: '低', color: '#52c41a', bg: '#f6ffed', border: '#52c41a' } }; // 工单状态数字映射 const orderStatusConfig = { 1: { label: '待处理', textColor: '#1890ff' }, 2: { label: '执行中', textColor: '#1890ff' }, 3: { label: '挂起', textColor: '#faad14' }, 4: { label: '已完成', textColor: '#52c41a' }, 5: { label: '处理中', textColor: '#722ed1' } }; // 工单类型映射 const orderTypeConfig = { 1: '巡检', 2: '检修', 3: '清洗', 4: '维修', 5: '运维' }; const WorkOrderPage = () => { const [activeTab, setActiveTab] = useState('1'); const [selectedRowKey, setSelectedRowKey] = useState(''); // 接口相关状态 const [loading, setLoading] = useState(false); const [workOrderList, setWorkOrderList] = useState([]); const [workOrderTotal, setWorkOrderTotal] = useState(0); const [currentDetail, setCurrentDetail] = useState(null); // 弹窗表单 const [form] = Form.useForm(); const [editModalVisible, setEditModalVisible] = useState(false); const [dispatchModalVisible, setDispatchModalVisible] = useState(false); // 统计数据(保留原模拟不变) const stats = [ { title: '今日新增工单', value: 18, subValue: '+3', subText: '较昨日', icon: , bg: '#e6f7ff' }, { title: '待处理工单', value: 12, subValue: '5', subText: '高优先级', icon: , bg: '#fff1f0' }, { title: '执行中工单', value: 9, subValue: '92%', subText: '按时率', icon: , bg: '#f6ffed' }, { title: '已完成工单', value: 126, subValue: '', subText: '本月累计', icon: , bg: '#f6ffed' }, { title: '平均处理时长', value: 4.3, unit: '小时', subValue: '-12%', subText: '较上周', icon: , bg: '#e6f7ff' }, { title: 'AI建议生成', value: 7, unit: '单', subValue: '', subText: '今日自动生成', icon: , bg: '#f9f0ff' }, ]; // 表格列【已适配后端真实字段】 const columns = [ { title: '工单编号', dataIndex: 'orderNo', key: 'orderNo', width: 130 }, { title: '工单标题', dataIndex: 'orderTitle', key: 'orderTitle', width: 180, ellipsis: true }, { title: '类型', dataIndex: 'orderType', key: 'orderType', width: 80, render: (val) => orderTypeConfig[val] || '未知' }, { title: '优先级', dataIndex: 'priorityLevel', key: 'priorityLevel', width: 80, render: (p) => ( {priorityConfig[p]?.label} ) }, { title: '负责人', dataIndex: 'assigneeName', key: 'assigneeName', width: 80 }, { title: '截止时间', dataIndex: 'deadlineTime', key: 'deadlineTime', width: 150 }, { title: '状态', dataIndex: 'orderStatus', key: 'orderStatus', width: 90, render: (s) => ( {orderStatusConfig[s]?.label} ) }, { title: '操作', key: 'action', width: 60, fixed: "right", render: () => }, ]; // 图表模拟数据保留不变 const pieData = [ { type: '待处理', value: 12 }, { type: '执行中', value: 9 }, { type: '已完成', value: 126 }, { type: '已挂起', value: 4 }, ]; const alarmTrendData = [ { date: '05-18', value: 5 }, { date: '05-19', value: 10 }, { date: '05-20', value: 7 }, { date: '05-21', value: 12 }, { date: '05-22', value: 8 }, { date: '05-23', value: 15 }, { date: '05-24', value: 11 }, ]; // ========== 接口请求方法 ========== // 获取工单列表 const getWorkOrderList = async () => { setLoading(true); try { const res = await getWorkOrderApi(); if (res.code == 0) { setWorkOrderList(res.rows || []); setWorkOrderTotal(res.total || 0); if (res.rows && res.rows.length > 0) { setSelectedRowKey(res.rows[0].id); getWorkOrderDetail(res.rows[0].id); } } } catch (error) { message.error('获取工单列表失败'); } finally { setLoading(false); } }; // 获取工单详情 const getWorkOrderDetail = async (id) => { try { const res = await getWorkOrderDetailApi(id); if (res.code === 0) { setCurrentDetail(res.data); } } catch (error) { message.error('获取工单详情失败'); } }; // 选中表格行 const handleRowSelect = (keys) => { if (keys.length > 0) { setSelectedRowKey(keys[0]); getWorkOrderDetail(keys[0]); } }; // 打开修改工单弹窗 const openEditModal = () => { if (!selectedRowKey) return message.warning('请先选择一条工单'); form.setFieldsValue({ title: currentDetail?.orderTitle, content: currentDetail?.taskDescription, priority: currentDetail?.priorityLevel, type: currentDetail?.orderType, remark: currentDetail?.remark }); setEditModalVisible(true); }; // 打开派发工单弹窗 const openDispatchModal = () => { if (!selectedRowKey) return message.warning('请先选择一条工单'); form.setFieldsValue({ title: currentDetail?.orderTitle, content: currentDetail?.taskDescription, priority: currentDetail?.priorityLevel, type: currentDetail?.orderType, remark: currentDetail?.remark }); setDispatchModalVisible(true); }; // 提交修改工单 const submitEdit = async (values) => { try { // 适配后端传参:id、title、content、priority、type、remark await updateWorkOrder({ id: selectedRowKey, orderTitle: values.title, taskDescription: values.content, priorityLevel: values.priority, orderType: values.type, remark: values.remark }); message.success('修改工单成功'); setEditModalVisible(false); getWorkOrderList(); } catch (error) { message.error('修改工单失败'); } }; // 提交派发工单 const submitDispatch = async (values) => { try { await dispatchWorkOrder({ id: selectedRowKey, orderTitle: values.title, taskDescription: values.content, priorityLevel: values.priority, orderType: values.type, remark: values.remark }); message.success('派发工单成功'); setDispatchModalVisible(false); getWorkOrderList(); } catch (error) { message.error('派发工单失败'); } }; useEffect(() => { getWorkOrderList(); }, []); return (
{/* 顶部标题和页签 */}
工单任务
{/* 统计卡片 */} {/* 统一风格统计卡片 —— 宽高一致 + 自动换行 + 最小宽度168px */} {stats.map((item, index) => (
{/* 左侧文字 */}
{item.title}
{item.value} {item.unit && {item.unit}}
{item.subText} {item.subValue}
{/* 右侧图标 */}
{item.icon}
))}
{/* 筛选栏 */}
工单类型
优先级
负责人
时间范围
状态
关键词 } />
{/* 左侧:列表 + 底部图表 */} 工单列表(共 {workOrderTotal} 条)
} bodyStyle={{ padding: 0 }} style={{ borderRadius: 8, marginBottom: 16 }} >
{ const total = pieData.reduce((a, b) => a + b.value, 0); const percent = ((item.value / total) * 100).toFixed(2); return `${item.value} (${percent}%)`; } } }} height={240} />
总数
{workOrderTotal}
更多 } style={{ borderRadius: 8, height: 360 }} >
{['08:00', '10:00', '12:00', '14:00', '16:00', '18:00'].map(t => (
{t}
))}
{['李工', '王工', '赵工', '陈工'].map((name, idx) => (
{name}
{idx === 0 &&
INV-05 告警排查
08:30 - 12:00
} {idx === 1 &&
B-12 热斑复检
13:30 - 15:00
} {idx === 1 &&
无人机巡检
16:00-18:00
} {idx === 2 &&
组件清洗 C-05
09:00 - 12:00
} {idx === 2 &&
清洗效果复检
15:00 - 17:00
} {idx === 3 &&
周界摄像头修复
10:00 - 12:30
} {idx === 3 &&
设备巡检
15:30 - 17:30
}
))}
{/* 右侧:详情 + AI + 告警 */}
工单详情 工单编号: {currentDetail?.orderNo || '--'}
{currentDetail?.orderTitle || '暂无标题'} {currentDetail?.priorityLevel && ( {priorityConfig[currentDetail.priorityLevel].label}优先级 )}
来源:{currentDetail?.sourceType || '--'}工单类型:{orderTypeConfig[currentDetail?.orderType] || '--'}负责人:{currentDetail?.assigneeName || '--'}协同人员:{currentDetail?.collaboratorNames || '无'}计划时间:{currentDetail?.planStartTime ? `${currentDetail.planStartTime} ~ ${currentDetail.planEndTime}` : '--'}关联设备:{currentDetail?.deviceName || '无'}关联电站:{currentDetail?.siteName || '无'}当前状态:{orderStatusConfig[currentDetail?.orderStatus]?.label || '--'}任务描述:{currentDetail?.taskDescription || '暂无描述'}
已创建
已派发
3
执行中
4
已完成
AI 建议与关联信息} style={{ borderRadius: 8, marginBottom: 16 }} bodyStyle={{ padding: '12px' }} >
建议携带
{currentDetail?.requiredEquipment || '无'}
AI建议方案
{currentDetail?.aiSuggestion || '无'}
预计发电影响
{currentDetail?.estimatedImpact ?? 0}%
查看全部 } style={{ borderRadius: 8 }}>
INV-05 逆变器告警 05-24 10:24
B-12 区块热斑告警 05-24 09:56
B-12 组件温度异常 05-24 09:32
{/* 修改工单弹窗 */} setEditModalVisible(false)} footer={null} width={520}>
{/* 派发工单弹窗 */} setDispatchModalVisible(false)} footer={null} width={520}>
); }; export default WorkOrderPage;