From 864368edfdbb0d84965d491f3f0e3035d3f6d3ab Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Fri, 15 May 2026 15:56:00 +0800 Subject: [PATCH] xxx --- src/api/workOrder.ts | 2 +- src/constants.ts | 41 ++-- src/pages/WorkOrder.tsx | 491 +++++++++++++--------------------------- 3 files changed, 169 insertions(+), 365 deletions(-) diff --git a/src/api/workOrder.ts b/src/api/workOrder.ts index bf32ed5..ef5f147 100644 --- a/src/api/workOrder.ts +++ b/src/api/workOrder.ts @@ -77,6 +77,6 @@ export function suspendWorkOrder(id) { export function deleteWorkOrder(ids) { return request({ url: `/iot/ioTworkOrder/${ids}`, - method: 'post', + method: 'delete', }); } diff --git a/src/constants.ts b/src/constants.ts index 12cecd6..c085089 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,27 +1,18 @@ -import { Device, Alert, VideoRecord, User } from './types'; -export const DEVICES: Device[] = [ - { id: 'R001', name: '巡检机器人 A1', type: '巡检型', status: 'online', battery: 85, cpu: 12, temp: 32.08, lastUpdate: '2024-03-20 10:00:00' }, - { id: 'R002', name: '安防辅助 B2', type: '安防型', status: 'alert', battery: 45, cpu: 45, temp: 42.5, lastUpdate: '2024-03-20 09:55:00' }, - { id: 'R003', name: '清洁终端 C1', type: '清洁型', status: 'offline', battery: 0, cpu: 0, temp: 20.0, lastUpdate: '2024-03-19 18:00:00' }, - { id: 'R004', name: '运输搬运 D5', type: '运输型', status: 'online', battery: 92, cpu: 8, temp: 28.5, lastUpdate: '2024-03-20 10:05:00' }, -]; +export const orderTypeConfig = { + 1: '巡检', + 2: '检修', + 3: '清洗', + 4: '维修', + 5: '运维' +}; -export const ALERTS: Alert[] = [ - { id: 'A001', deviceId: 'R002', deviceName: '安防辅助 B2', type: 'critical', message: '芯片温度过高', time: '2024-03-20 10:02:15', handled: false }, - { id: 'A002', deviceId: 'R001', deviceName: '巡检机器人 A1', type: 'warning', message: '电池电量低于20%', time: '2024-03-20 09:30:00', handled: true }, - { id: 'A003', deviceId: 'R004', deviceName: '运输搬运 D5', type: 'info', message: '任务顺利完成', time: '2024-03-20 08:00:00', handled: true }, -]; - -export const VIDEOS: VideoRecord[] = [ - { id: 'V001', deviceId: 'R001', deviceName: '巡检机器人 A1', startTime: '2024-03-20 08:00', endTime: '2024-03-20 09:00', size: '450MB', url: '#' }, - { id: 'V002', deviceId: 'R001', deviceName: '巡检机器人 A1', startTime: '2024-03-20 09:00', endTime: '2024-03-20 10:00', size: '520MB', url: '#' }, - { id: 'V003', deviceId: 'R002', deviceName: '安防辅助 B2', startTime: '2024-03-20 07:30', endTime: '2024-03-20 08:30', size: '380MB', url: '#' }, -]; - -export const MANAGED_USERS: User[] = [ - { id: 'user-1', name: 'James Wilson', role: 'admin', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=James' }, - { id: 'user-2', name: 'Sarah Chen', role: 'operator', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=Sarah' }, - { id: 'user-3', name: 'Mike Ross', role: 'viewer', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=Mike' }, - { id: 'user-4', name: 'Anna Lee', role: 'operator', avatar: 'https://api.dicebear.com/7.x/avataaars/svg?seed=Anna' }, -]; +export const sourceTypeMap = { + 1: 'AI', + 2: '无人机', + 3: '清洗', + 4: '视频', + 5: '装备', + 6: '人工', + 7: '告警' +}; diff --git a/src/pages/WorkOrder.tsx b/src/pages/WorkOrder.tsx index afc15b4..460c2f2 100644 --- a/src/pages/WorkOrder.tsx +++ b/src/pages/WorkOrder.tsx @@ -1,7 +1,7 @@ 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 + Statistic, Modal, message, Empty, Drawer, Descriptions, Timeline, Divider, Form, Tabs, Progress, Badge, DatePicker, Pagination, Popconfirm } from 'antd'; import { CheckOutlined, ClockCircleOutlined, ControlOutlined, @@ -28,9 +28,18 @@ import { History, ExternalLink } from 'lucide-react'; -// 导入工单接口 -import { getWorkOrderApi, getWorkOrderDetailApi, updateWorkOrder, dispatchWorkOrder, completeWorkOrder } from '../api/workOrder'; + +import { + getWorkOrderApi, + getWorkOrderDetailApi, + updateWorkOrder, + dispatchWorkOrder, + completeWorkOrder, + suspendWorkOrder, + deleteWorkOrder +} from '../api/workOrder'; import { UniversalLineChart } from '../components/recharts'; +import { orderTypeConfig, sourceTypeMap } from '../constants'; const { Option } = Select; const { Search } = Input; @@ -54,14 +63,7 @@ const orderStatusConfig = { 5: { label: '处理中', textColor: '#722ed1' } }; -// 工单类型映射 -const orderTypeConfig = { - 1: '巡检', - 2: '检修', - 3: '清洗', - 4: '维修', - 5: '运维' -}; + const WorkOrderPage = () => { const [activeTab, setActiveTab] = useState('1'); @@ -80,8 +82,7 @@ const WorkOrderPage = () => { const [completeForm] = Form.useForm(); // 完成工单表单 const [messageApi, contextHolder] = message.useMessage(); - - // 统计数据(保留原模拟不变) + // 统计数据 const stats = [ { title: '今日新增工单', value: 18, subValue: '+3', subText: '较昨日', icon: , bg: '#e6f7ff' }, { title: '待处理工单', value: 12, subValue: '5', subText: '高优先级', icon: , bg: '#fff1f0' }, @@ -91,7 +92,7 @@ const WorkOrderPage = () => { { title: 'AI建议生成', value: 7, unit: '单', subValue: '', subText: '今日自动生成', icon: , bg: '#f9f0ff' }, ]; - // 图表模拟数据保留不变 + // 图表模拟数据 const pieData = [ { type: '待处理', value: 12 }, { type: '执行中', value: 9 }, @@ -145,17 +146,14 @@ const WorkOrderPage = () => { // 提交完成工单 const submitComplete = async (values) => { try { - // 构造后端需要的参数(只需要传 id + 处理信息) const params = { id: values.id, handleResult: values.handleResult, handleRemark: values.handleRemark, }; - await completeWorkOrder(params); messageApi.success('工单已完成'); setCompleteModalVisible(false); - // 刷新列表 + 详情 getWorkOrderList(); getWorkOrderDetail(selectedRowKey); } catch (err) { @@ -196,12 +194,11 @@ const WorkOrderPage = () => { setEditModalVisible(true); }; - // 打开派发工单弹窗 // 打开派发工单弹窗 const openDispatchModal = () => { if (!selectedRowKey) return messageApi.warning('请先选择一条工单'); form.setFieldsValue({ - orderId: selectedRowKey, // 自动回填工单ID + orderId: selectedRowKey, assigneeName: currentDetail?.assigneeName || '', planStartTime: currentDetail?.planStartTime ? dayjs(currentDetail.planStartTime) : null, planEndTime: currentDetail?.planEndTime ? dayjs(currentDetail.planEndTime) : null, @@ -211,19 +208,17 @@ const WorkOrderPage = () => { }; // 提交修改工单 - // 提交修改工单(完整匹配后端参数) const submitEdit = async (values) => { try { - // 拼接你给的所有工单参数(1:1 匹配) const params = { - id: selectedRowKey, // 主键ID - orderNo: currentDetail?.orderNo, // 工单编号 - orderTitle: values.orderTitle, // 工单标题 - sourceType: currentDetail?.sourceType, // 来源(保持不变) - orderType: values.orderType, // 类型 - priorityLevel: values.priorityLevel, // 优先级 - deviceId: currentDetail?.deviceId, // 设备ID - deviceName: currentDetail?.deviceName, // 设备名称 + id: selectedRowKey, + orderNo: currentDetail?.orderNo, + orderTitle: values.orderTitle, + sourceType: currentDetail?.sourceType, + orderType: values.orderType, + priorityLevel: values.priorityLevel, + deviceId: currentDetail?.deviceId, + deviceName: currentDetail?.deviceName, deviceType: currentDetail?.deviceType, siteId: currentDetail?.siteId, siteName: currentDetail?.siteName, @@ -240,20 +235,16 @@ const WorkOrderPage = () => { orderStatus: currentDetail?.orderStatus, alarmId: currentDetail?.alarmId, alarmNo: currentDetail?.alarmNo, - taskDescription: values.taskDescription, // 任务描述 + taskDescription: values.taskDescription, aiSuggestion: currentDetail?.aiSuggestion, requiredEquipment: currentDetail?.requiredEquipment, estimatedImpact: currentDetail?.estimatedImpact, handleResult: currentDetail?.handleResult, handleRemark: currentDetail?.handleRemark, }; - - // 调用你提供的接口 await updateWorkOrder(params); - messageApi.success('修改工单成功'); setEditModalVisible(false); - // 刷新列表和详情 getWorkOrderList(); getWorkOrderDetail(selectedRowKey); } catch (error) { @@ -262,14 +253,12 @@ const WorkOrderPage = () => { } }; - // 提交派发工单 // 提交派发工单 const submitDispatch = async (values) => { try { - // 拼接接口需要的参数(完全按你给的格式) const params = { orderId: values.orderId, - assigneeId: values.assigneeName === '王工' ? 1003 : '', // 你可以自己映射ID + assigneeId: values.assigneeId ?? '', assigneeName: values.assigneeName, collaboratorIds: '', collaboratorNames: values.collaboratorNames?.join(',') || '', @@ -277,18 +266,40 @@ const WorkOrderPage = () => { planEndTime: values.planEndTime ? values.planEndTime.format('YYYY-MM-DDTHH:mm:ss') : '', deadlineTime: values.deadlineTime ? values.deadlineTime.format('YYYY-MM-DDTHH:mm:ss') : '', }; - await dispatchWorkOrder(params); - messageApi.success('工单派发成功'); setDispatchModalVisible(false); - getWorkOrderList(); // 刷新列表 + getWorkOrderList(); } catch (error) { messageApi.error('工单派发失败'); console.error(error); } }; + // 挂起工单 + const handleSuspend = async () => { + if (!selectedRowKey) return messageApi.warning('请选择工单'); + try { + await suspendWorkOrder(selectedRowKey); + messageApi.success('工单已挂起'); + getWorkOrderList(); + } catch (e) { + messageApi.error('挂起失败'); + } + }; + + // 删除工单 + const handleDelete = async () => { + if (!selectedRowKey) return messageApi.warning('请选择工单'); + try { + await deleteWorkOrder(selectedRowKey); + messageApi.success('删除成功'); + getWorkOrderList(); + } catch (e) { + messageApi.error('删除失败'); + } + }; + useEffect(() => { getWorkOrderList(); }, []); @@ -300,11 +311,20 @@ const WorkOrderPage = () => { overflow: 'hidden' }; - // 表格列【已适配后端真实字段】 + // 表格列【已完善】 const columns = [ - { title: '工单编号', dataIndex: 'orderNo', key: 'orderNo', width: 130 }, - { title: '工单标题', dataIndex: 'orderTitle', key: 'orderTitle', width: 180, ellipsis: true }, - { title: '来源', dataIndex: 'sourceType', key: 'sourceType', width: 100 }, + { title: '工单编号', dataIndex: 'orderNo', key: 'orderNo', width: 150 }, + { title: '工单标题', dataIndex: 'orderTitle', key: 'orderTitle', width: 200, ellipsis: true }, + { + title: '来源', + dataIndex: 'sourceType', + key: 'sourceType', + width: 90, + render: (t) => { + const map = { 1: 'AI', 2: '无人机', 3: '清洗', 4: '视频', 5: '装备', 6: '人工', 7: '告警' }; + return map[t] || t; + } + }, { title: '类型', dataIndex: 'orderType', @@ -318,26 +338,20 @@ const WorkOrderPage = () => { 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: 'assigneeName', key: 'assigneeName', width: 90 }, + { title: '设备名称', dataIndex: 'deviceName', key: 'deviceName', width: 160, ellipsis: true }, + { title: '站点', dataIndex: 'siteName', key: 'siteName', width: 130 }, + { title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: 160 }, { title: '状态', dataIndex: 'orderStatus', key: 'orderStatus', - width: 90, + width: 100, render: (s) => (
@@ -348,19 +362,14 @@ const WorkOrderPage = () => { { title: '操作', key: 'action', - width: 60, + width: 180, fixed: "right", render: (_, record) => ( - + + + + + ) }, ]; @@ -368,50 +377,21 @@ const WorkOrderPage = () => { return (
{contextHolder} - + {/* 顶部标题和页签 */}
- 工单任务管理 - + 工单任务管理 +
{/* 统计卡片 */} @@ -428,20 +408,12 @@ const WorkOrderPage = () => {
{item.subText} - + {item.subValue}
-
+
{item.icon}
@@ -453,55 +425,32 @@ const WorkOrderPage = () => { {/* 筛选栏 */} - -
- 工单类型 - -
- - -
- 优先级 - -
- - -
- 负责人 - -
- - -
- 时间范围 - -
- - -
- 状态 - -
- - -
- 关键词 - } size="small" /> -
- +
+ 工单类型 + +
+
+ 优先级 + +
+
+ 负责人 + +
+
+ 时间范围 + +
+
+ 状态 + +
+
+ 关键词 + } size="small" /> +
- - - - +
@@ -509,12 +458,8 @@ const WorkOrderPage = () => { {/* 左侧:列表 + 底部图表 */} - 工单列表(共 {workOrderTotal} 条)
} - bodyStyle={{ padding: 0 }} - style={{ ...cardStyle, marginBottom: 8 }} - > + 工单列表(共 {workOrderTotal} 条)} + bodyStyle={{ padding: 0 }} style={{ ...cardStyle, marginBottom: 8 }}> { rowKey="id" className="compact-table" scroll={{ x: 'max-content' }} - rowSelection={{ - type: 'radio', - selectedRowKeys: [selectedRowKey], - onChange: handleRowSelect - }} + rowSelection={{ type: 'radio', selectedRowKeys: [selectedRowKey], onChange: handleRowSelect }} />
@@ -539,27 +480,9 @@ const WorkOrderPage = () => {
工单状态分布} style={{ ...cardStyle, height: 380 }}>
- { - const total = pieData.reduce((a, b) => a + b.value, 0); - const percent = ((item.value / total) * 100).toFixed(1); - return `${item.value} (${percent}%)`; - } - } - }} - height={260} - /> + legend={{ position: 'right', layout: 'vertical' }} height={260} />
总数
{workOrderTotal}
@@ -568,13 +491,9 @@ const WorkOrderPage = () => {
- 任务排班 / 日历视图} + 任务排班 / 日历视图} extra={} - style={{ ...cardStyle, height: 380 }} - bodyStyle={{ padding: '16px' }} - > + style={{ ...cardStyle, height: 380 }} bodyStyle={{ padding: '16px' }}>
- +
工单详情 工单编号: {currentDetail?.orderNo || '--'} @@ -625,23 +540,14 @@ const WorkOrderPage = () => {
{currentDetail?.orderTitle || '暂无标题'} {currentDetail?.priorityLevel && ( - + {priorityConfig[currentDetail.priorityLevel].label}优先级 )}
-
来源:{currentDetail?.sourceType || '--'} + 来源:{sourceTypeMap[currentDetail?.sourceType] || '--'}工单类型:{orderTypeConfig[currentDetail?.orderType] || '--'}负责人:{currentDetail?.assigneeName || '--'}协同人员:{currentDetail?.collaboratorNames || '无'} @@ -661,11 +567,9 @@ const WorkOrderPage = () => {
- {/* 连线 */}
= 3 ? '100%' : (currentDetail?.orderStatus === 2 ? '66%' : '33%'), height: '100%', background: '#00B42A' }}>
- {[ { label: '已创建', step: 1, active: currentDetail?.orderStatus >= 1 }, { label: '已派发', step: 2, active: currentDetail?.orderStatus >= 2 }, @@ -688,25 +592,19 @@ const WorkOrderPage = () => {
- - + + + >完成 - AI 建议与关联信息} - style={{ ...cardStyle, marginTop: 16 }} - bodyStyle={{ padding: '16px' }} - > + AI 建议与关联信息} + style={{ ...cardStyle, marginTop: 16 }} bodyStyle={{ padding: '16px' }}>
@@ -750,14 +648,7 @@ const WorkOrderPage = () => { showGrid={true} smooth dot - series={[ - { - key: 'value', - name: '告警数量', - color: '#165DFF', - strokeWidth: 2, - }, - ]} + series={[{ key: 'value', name: '告警数量', color: '#165DFF', strokeWidth: 2 }]} />
@@ -784,98 +675,45 @@ const WorkOrderPage = () => { - {/* 修改工单弹窗 */} {/* 修改工单弹窗 */} setEditModalVisible(false)} footer={null} width={520}>
- + - - + - - + - - + - - +
- {/* 派发工单弹窗 */} setDispatchModalVisible(false)} footer={null} width={550}>
- - - + + - - - + + + @@ -884,44 +722,19 @@ const WorkOrderPage = () => {
{/* 完成工单弹窗 */} - setCompleteModalVisible(false)} - footer={null} - width={500} - > + setCompleteModalVisible(false)} footer={null} width={500}> - - - - - - - + + + - - - - - + - +