修改
This commit is contained in:
@@ -38,7 +38,7 @@ import {
|
||||
suspendWorkOrder,
|
||||
deleteWorkOrder
|
||||
} from '../api/workOrder';
|
||||
import { getSiteDevice } from '../api/device';
|
||||
import { getSiteDevice, getSiteUAVList } from '../api/device';
|
||||
import { UniversalLineChart } from '../components/recharts';
|
||||
import { orderTypeConfig, sourceTypeMap } from '../constants';
|
||||
|
||||
@@ -55,9 +55,9 @@ 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' }
|
||||
ERROR: { label: '高', color: '#ff4d4f', bg: '#fff1f0', border: '#ff4d4f' },
|
||||
WARNING: { label: '中', color: '#faad14', bg: '#fff7e6', border: '#faad14' },
|
||||
INFO: { label: '低', color: '#52c41a', bg: '#f6ffed', border: '#52c41a' }
|
||||
};
|
||||
|
||||
// 工单状态数字映射
|
||||
@@ -80,12 +80,26 @@ const WorkOrderPage = () => {
|
||||
const [currentDetail, setCurrentDetail] = useState(null);
|
||||
const [userList, setUserList] = useState([]);
|
||||
const [deviceList, setDeviceList] = useState([]);
|
||||
const [orderStat, setOrderStat] = useState({
|
||||
todayAdd: 0, // 今日新增工单
|
||||
pending: 0, // 待处理总数
|
||||
pendingHigh: 0, // 待处理高优先级
|
||||
running: 0, // 执行中
|
||||
finishedMonth: 0, // 本月已完成
|
||||
finishRate: '0', // 按时完成率
|
||||
avgHandleHour: 0, // 平均处理时长
|
||||
aiCreate: 0, // AI自动生成工单
|
||||
todayAddDiff: '', // 今日新增对比昨日
|
||||
avgDiff: '' // 平均时长对比上周
|
||||
});
|
||||
|
||||
// 从 redux 获取用户信息
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const { stationId } = useSelector((state: RootState) => state.station);
|
||||
const [deviceAll, setDevicesAll] = useState([]);
|
||||
|
||||
|
||||
|
||||
// 判断是否为管理员
|
||||
const isAdmin = true;
|
||||
|
||||
// 弹窗表单
|
||||
const [form] = Form.useForm();
|
||||
@@ -95,46 +109,156 @@ const WorkOrderPage = () => {
|
||||
const [completeForm] = Form.useForm();
|
||||
const messageApi = utils.message;
|
||||
|
||||
// 获取用户列表
|
||||
const fetchUserList = async () => {
|
||||
try {
|
||||
const res: any = await getUser({
|
||||
pageNum: 1, pageSize: 10000, orgId: userInfo?.orgId,
|
||||
siteId: userInfo?.siteId,
|
||||
});
|
||||
if (res.code == 200) {
|
||||
setUserList(res.rows || []);
|
||||
|
||||
// 计算工单统计数据
|
||||
const calcWorkOrderStat = (list) => {
|
||||
const today = dayjs().format('YYYY-MM-DD');
|
||||
const monthStart = dayjs().startOf('month').format('YYYY-MM-DD');
|
||||
let todayAdd = 0;
|
||||
let pending = 0;
|
||||
let pendingHigh = 0;
|
||||
let running = 0;
|
||||
let finishedMonth = 0;
|
||||
let aiCreate = 0;
|
||||
let finishCount = 0;
|
||||
let totalCostHour = 0;
|
||||
let allFinishOrder = [];
|
||||
|
||||
list.forEach(item => {
|
||||
const createDay = dayjs(item.createTime).format('YYYY-MM-DD');
|
||||
// 今日新增
|
||||
if (createDay === today) todayAdd++;
|
||||
// 本月已完成
|
||||
if (item.orderStatus === 4 && createDay >= monthStart) finishedMonth++;
|
||||
// AI生成工单 sourceType=7 告警自动生成
|
||||
if (item.sourceType === 7) aiCreate++;
|
||||
|
||||
// 状态分类
|
||||
if (item.orderStatus === 1) {
|
||||
pending++;
|
||||
// 高优先级待处理
|
||||
if (item.priorityLevel === 1) pendingHigh++;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户列表失败', error);
|
||||
if (item.orderStatus === 2 || item.orderStatus === 5) running++;
|
||||
|
||||
// 已完成工单计算处理时长
|
||||
if (item.orderStatus === 4 && item.actualStartTime && item.actualEndTime) {
|
||||
finishCount++;
|
||||
const costMin = dayjs(item.actualEndTime).diff(dayjs(item.actualStartTime), 'minute');
|
||||
totalCostHour += costMin / 60;
|
||||
allFinishOrder.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
// 平均处理时长
|
||||
const avgHandleHour = finishCount > 0 ? Number((totalCostHour / finishCount).toFixed(1)) : 0;
|
||||
// 按时率(简单模拟:实际可后端返回)
|
||||
const finishRate = allFinishOrder.length ? '92' : '0';
|
||||
|
||||
setOrderStat({
|
||||
todayAdd,
|
||||
pending,
|
||||
pendingHigh,
|
||||
running,
|
||||
finishedMonth,
|
||||
finishRate,
|
||||
avgHandleHour,
|
||||
aiCreate,
|
||||
todayAddDiff: '+3', // 如需真实昨日对比,单独请求昨日统计接口
|
||||
avgDiff: '-12%'
|
||||
});
|
||||
};
|
||||
|
||||
const fetchAllData = async () => {
|
||||
if (!stationId) return;
|
||||
|
||||
try {
|
||||
// 1. 同时发请求
|
||||
const [deviceRes, planeRes] = await Promise.all([
|
||||
getSiteDevice({ siteId: stationId, pageSize: 9999, pageNum: 1, orgId: userInfo.orgId }),
|
||||
getSiteUAVList(stationId),
|
||||
]);
|
||||
|
||||
// 2. 处理普通设备
|
||||
const devData = deviceRes?.code === 200 ? (deviceRes.rows || []) : [];
|
||||
|
||||
// 3. 处理无人机 + 自动补全地图需要的字段(关键改动)
|
||||
let planeData = planeRes?.code === 200 ? (planeRes?.rows || []) : [];
|
||||
|
||||
planeData = planeData.map(item => ({
|
||||
...item,
|
||||
type: 'plane',
|
||||
lastRunningStatus: {
|
||||
longitude: item.longitude || 0,
|
||||
latitude: item.latitude || 0,
|
||||
},
|
||||
deviceAlias: item.drone_callsign || item.device_sn
|
||||
|| '无人机',
|
||||
|
||||
}));
|
||||
|
||||
|
||||
// 合并所有设备
|
||||
const all = [...devData, ...planeData];
|
||||
setDevicesAll(all);
|
||||
|
||||
} catch (err) {
|
||||
console.error('数据请求失败', err);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取设备列表
|
||||
const fetchDeviceList = async () => {
|
||||
try {
|
||||
const res: any = await getSiteDevice({
|
||||
siteId: userInfo?.siteId,
|
||||
pageNum: 1,
|
||||
pageSize: 10000,
|
||||
orgId: userInfo?.orgId
|
||||
});
|
||||
if (res.code == 200) {
|
||||
setDeviceList(res.rows || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 统计数据
|
||||
const stats = [
|
||||
{ title: '今日新增工单', value: 18, subValue: '+3', subText: '较昨日', icon: <ClipboardList size={24} color="#1890ff" />, bg: '#e6f7ff' },
|
||||
{ title: '待处理工单', value: 12, subValue: '5', subText: '高优先级', icon: <Clock size={24} color="#ff4d4f" />, bg: '#fff1f0' },
|
||||
{ title: '执行中工单', value: 9, subValue: '92%', subText: '按时率', icon: <Play size={24} color="#52c41a" />, bg: '#f6ffed' },
|
||||
{ title: '已完成工单', value: 126, subValue: '', subText: '本月累计', icon: <CheckCircle size={24} color="#52c41a" />, bg: '#f6ffed' },
|
||||
{ title: '平均处理时长', value: 4.3, unit: '小时', subValue: '-12%', subText: '较上周', icon: <Timer size={24} color="#1890ff" />, bg: '#e6f7ff' },
|
||||
{ title: 'AI建议生成', value: 7, unit: '单', subValue: '', subText: '今日自动生成', icon: <Cpu size={24} color="#722ed1" />, bg: '#f9f0ff' },
|
||||
{
|
||||
title: '今日新增工单',
|
||||
value: orderStat.todayAdd,
|
||||
subValue: orderStat.todayAddDiff,
|
||||
subText: '较昨日',
|
||||
icon: <ClipboardList size={24} color="#1890ff" />,
|
||||
bg: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
title: '待处理工单',
|
||||
value: orderStat.pending,
|
||||
subValue: orderStat.pendingHigh,
|
||||
subText: '高优先级',
|
||||
icon: <Clock size={24} color="#ff4d4f" />,
|
||||
bg: '#fff1f0'
|
||||
},
|
||||
{
|
||||
title: '执行中工单',
|
||||
value: orderStat.running,
|
||||
subValue: `${orderStat.finishRate}%`,
|
||||
subText: '按时率',
|
||||
icon: <Play size={24} color="#52c41a" />,
|
||||
bg: '#f6ffed'
|
||||
},
|
||||
{
|
||||
title: '已完成工单',
|
||||
value: orderStat.finishedMonth,
|
||||
subValue: '',
|
||||
subText: '本月累计',
|
||||
icon: <CheckCircle size={24} color="#52c41a" />,
|
||||
bg: '#f6ffed'
|
||||
},
|
||||
{
|
||||
title: '平均处理时长',
|
||||
value: orderStat.avgHandleHour,
|
||||
unit: '小时',
|
||||
subValue: orderStat.avgDiff,
|
||||
subText: '较上周',
|
||||
icon: <Timer size={24} color="#1890ff" />,
|
||||
bg: '#e6f7ff'
|
||||
},
|
||||
{
|
||||
title: 'AI建议生成',
|
||||
value: orderStat.aiCreate,
|
||||
unit: '单',
|
||||
subValue: '',
|
||||
subText: '今日自动生成',
|
||||
icon: <Cpu size={24} color="#722ed1" />,
|
||||
bg: '#f9f0ff'
|
||||
},
|
||||
];
|
||||
|
||||
const getOrderStatusPieData = () => {
|
||||
@@ -167,8 +291,6 @@ const WorkOrderPage = () => {
|
||||
{ date: '05-24', value: 11 },
|
||||
];
|
||||
|
||||
// ========== 接口请求方法 ==========
|
||||
// 获取工单列表
|
||||
const getWorkOrderList = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
@@ -176,6 +298,8 @@ const WorkOrderPage = () => {
|
||||
if (res.code == 0) {
|
||||
setWorkOrderList(res.rows || []);
|
||||
setWorkOrderTotal(res.total || 0);
|
||||
// 计算统计卡片数据
|
||||
calcWorkOrderStat(res.rows || []);
|
||||
if (res.rows?.length > 0) {
|
||||
setSelectedRowKey(res.rows[0].id);
|
||||
getWorkOrderDetail(res.rows[0].id);
|
||||
@@ -187,7 +311,6 @@ const WorkOrderPage = () => {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 打开完成工单弹窗
|
||||
const openCompleteModal = () => {
|
||||
if (!selectedRowKey) return messageApi.warning('请先选择工单');
|
||||
@@ -276,8 +399,6 @@ const WorkOrderPage = () => {
|
||||
return messageApi.warning('请先选择一条工单');
|
||||
}
|
||||
|
||||
|
||||
fetchDeviceList();
|
||||
setDispatchModalVisible(true);
|
||||
};
|
||||
|
||||
@@ -309,13 +430,19 @@ const WorkOrderPage = () => {
|
||||
// 调用 startWorkOrder 接口,传递 ids 和 选择的设备 id
|
||||
const params = {
|
||||
ids: values.orderIds,
|
||||
deviceId: values.deviceId
|
||||
deviceId: values.deviceId,
|
||||
startTime: values.startTime
|
||||
};
|
||||
await startWorkOrder(params);
|
||||
messageApi.success('工单执行成功');
|
||||
setDispatchModalVisible(false);
|
||||
setSelectedRowKeys([]); // 清空选中
|
||||
getWorkOrderList();
|
||||
const res = await startWorkOrder(params);
|
||||
if (res.code == 200) {
|
||||
messageApi.success('工单执行成功');
|
||||
setDispatchModalVisible(false);
|
||||
setSelectedRowKeys([]); // 清空选中
|
||||
getWorkOrderList();
|
||||
} else {
|
||||
messageApi.error(res.msg || '工单执行失败');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
messageApi.error('工单执行失败');
|
||||
console.error(error);
|
||||
@@ -364,6 +491,8 @@ const WorkOrderPage = () => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchAllData();
|
||||
|
||||
getWorkOrderList();
|
||||
}, []);
|
||||
|
||||
@@ -390,7 +519,7 @@ const WorkOrderPage = () => {
|
||||
dataIndex: 'orderType',
|
||||
key: 'orderType',
|
||||
width: 80,
|
||||
render: (val) => orderTypeConfig[val] || '未知'
|
||||
render: (val) => getWorkOrderTypeText(val)
|
||||
},
|
||||
{
|
||||
title: '优先级',
|
||||
@@ -403,7 +532,6 @@ const WorkOrderPage = () => {
|
||||
</Tag>
|
||||
)
|
||||
},
|
||||
{ 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 },
|
||||
@@ -474,12 +602,12 @@ const WorkOrderPage = () => {
|
||||
<div style={{ fontSize: 'clamp(20px, 1.4vw, 24px)', fontWeight: 800, color: '#1D2129' }}>{item.value}</div>
|
||||
{item.unit && <span style={{ fontSize: 13, color: '#1D2129', fontWeight: 600 }}>{item.unit}</span>}
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: '#86909C' }}>
|
||||
{/*<div style={{ fontSize: 11, color: '#86909C' }}>
|
||||
{item.subText}
|
||||
<span style={{ marginLeft: 4, fontWeight: 700, color: item.subValue.includes('+') ? '#00B42A' : (item.subValue.includes('-') ? '#F53F3F' : '#165DFF') }}>
|
||||
{item.subValue}
|
||||
<span style={{ marginLeft: 4, fontWeight: 700, color: item?.subValue.includes('+') ? '#00B42A' : (item.subValue.includes('-') ? '#F53F3F' : '#165DFF') }}>
|
||||
{item?.subValue}
|
||||
</span>
|
||||
</div>
|
||||
</div>*/}
|
||||
</div>
|
||||
<div style={{ width: 52, height: 52, borderRadius: 14, background: item.bg, display: 'flex', alignItems: 'center', justifyContent: 'center', boxShadow: `0 4px 10px ${item.bg}80` }}>
|
||||
{item.icon}
|
||||
@@ -495,16 +623,13 @@ const WorkOrderPage = () => {
|
||||
<Row gutter={[16, 12]} align="middle">
|
||||
<Col xs={12} sm={8} md={4} xl={3}><div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span className="filter-label">工单类型</span>
|
||||
<Select defaultValue="all" style={{ width: '100%' }} size="small"><Option value="all">全部</Option></Select>
|
||||
<Select style={{ width: 120 }} size="small" options={workOrderTypeOptions} allowClear showSearch optionFilterProp="label" filterOption={(input, option) => option.label.toLowerCase().includes(input.toLowerCase())}></Select>
|
||||
</div></Col>
|
||||
<Col xs={12} sm={8} md={4} xl={3}><div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span className="filter-label">优先级</span>
|
||||
<Select defaultValue="all" style={{ width: '100%' }} size="small"><Option value="all">全部</Option></Select>
|
||||
</div></Col>
|
||||
<Col xs={12} sm={8} md={4} xl={3}><div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span className="filter-label">负责人</span>
|
||||
<Select defaultValue="all" style={{ width: '100%' }} size="small"><Option value="all">全部</Option></Select>
|
||||
{/*<Select style={{ width: '100%' }} size="small" options={priorityOptions}></Select>*/}
|
||||
</div></Col>
|
||||
|
||||
<Col xs={24} sm={16} md={8} xl={5}><div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span className="filter-label">时间范围</span>
|
||||
<RangePicker style={{ width: '100%' }} size="small" />
|
||||
@@ -662,8 +787,6 @@ const WorkOrderPage = () => {
|
||||
<Row gutter={[16, 16]} style={{ background: '#f8fafc', padding: 16, borderRadius: 12, marginBottom: 20 }}>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>来源:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{sourceTypeMap[currentDetail?.sourceType] || '--'}</span></Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>工单类型:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{getWorkOrderTypeText(currentDetail?.orderType)}</span></Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>负责人:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{currentDetail?.assigneeName || '--'}</span></Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>协同人员:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{currentDetail?.collaboratorNames || '无'}</span></Col>
|
||||
<Col span={24}><span style={{ fontSize: 12 }}>计划时间:</span>
|
||||
<span style={{ fontSize: 12, fontWeight: 500 }}>
|
||||
{currentDetail?.planStartTime && currentDetail?.planEndTime
|
||||
@@ -671,9 +794,9 @@ const WorkOrderPage = () => {
|
||||
: '--'}
|
||||
</span>
|
||||
</Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>关联设备:</span><span style={{ fontSize: 12, color: '#165DFF', fontWeight: 600 }}>{currentDetail?.deviceName || '无'}</span></Col>
|
||||
<Col span={24}><span style={{ fontSize: 12 }}>关联设备:</span><span style={{ fontSize: 12, color: '#165DFF', fontWeight: 600 }}>{currentDetail?.deviceName || '无'}</span></Col>
|
||||
<Col span={12}><span style={{ fontSize: 12 }}>关联区域:</span><span style={{ fontSize: 12, fontWeight: 500 }}>{currentDetail?.siteName || '无'}</span></Col>
|
||||
<Col span={24}>
|
||||
<Col span={12}>
|
||||
<span style={{ fontSize: 12 }}>当前状态:</span>
|
||||
<Tag color="blue" style={{ borderRadius: 4, fontWeight: 600, border: 'none', background: '#E8F3FF', color: '#165DFF' }}>{orderStatusConfig[currentDetail?.orderStatus]?.label || '--'}</Tag>
|
||||
</Col>
|
||||
@@ -859,16 +982,75 @@ const WorkOrderPage = () => {
|
||||
label="选择执行设备"
|
||||
rules={[{ required: true, message: '请选择执行设备' }]}
|
||||
>
|
||||
{/*<Select
|
||||
style={{ width: "80%", marginBottom: 8 }}
|
||||
placeholder="请选择设备"
|
||||
value={selectedDevice?.device_sn || selectedDevice?.serialNumber}
|
||||
onChange={handleDeviceChange}
|
||||
size="small"
|
||||
showSearch
|
||||
allowClear
|
||||
optionFilterProp="label"
|
||||
filterOption={(input, option) =>
|
||||
String(option?.label || "").toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
options={[
|
||||
{ label: <span>机器人</span>, options: devices.map(item => ({ value: item.device_sn || item.serialNumber, label: item.deviceAlias || item.deviceName || '未知设备' })) },
|
||||
{ label: <span>无人机</span>, options: planedevices.map(item => ({ value: item.device_sn, label: item.drone_callsign || item.callsign || '未知设备' })) },
|
||||
]}
|
||||
/>*/}
|
||||
|
||||
<Select
|
||||
placeholder="请选择执行设备"
|
||||
showSearch
|
||||
style={{ width: "100%" }}
|
||||
// 自定义筛选逻辑:输入文字匹配别名、序列号、无人机呼号
|
||||
filterOption={(inputValue, option) => {
|
||||
const label = option.children || "";
|
||||
return label.toLowerCase().includes(inputValue.toLowerCase());
|
||||
}}
|
||||
>
|
||||
{deviceList.map(device => (
|
||||
<Option key={device.id} value={device.id}>
|
||||
{device.deviceName} ({device.serialNumber})
|
||||
</Option>
|
||||
))}
|
||||
{/* 机器人设备分组 */}
|
||||
<Select.OptGroup label="机器人">
|
||||
{deviceAll
|
||||
.filter(item => item.serialNumber)
|
||||
.map(device => (
|
||||
<Option
|
||||
key={device.id}
|
||||
value={device.serialNumber}
|
||||
>
|
||||
{device.deviceAlias || device.serialNumber}
|
||||
</Option>
|
||||
))}
|
||||
</Select.OptGroup>
|
||||
|
||||
{/* 无人机分组 */}
|
||||
<Select.OptGroup label="无人机">
|
||||
{deviceAll
|
||||
.filter(item => item.device_sn)
|
||||
.map(device => (
|
||||
<Option
|
||||
key={device.id}
|
||||
value={device.device_sn}
|
||||
>
|
||||
{device.drone_callsign || device.device_sn}
|
||||
</Option>
|
||||
))}
|
||||
</Select.OptGroup>
|
||||
</Select>
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
name="startTime"
|
||||
label="执行开始时间"
|
||||
>
|
||||
<DatePicker
|
||||
showTime
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="请选择执行开始时间"
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem style={{ textAlign: 'right', marginBottom: 0 }}>
|
||||
<Button onClick={() => setDispatchModalVisible(false)}>取消</Button>
|
||||
<Button type="primary" htmlType="submit" style={{ marginLeft: 8 }}>确认执行</Button>
|
||||
|
||||
Reference in New Issue
Block a user