根据订单编号获取航线文件

修改订单状态逻辑,实现超时逻辑根据drone_flight状态更新任务状态,当主动点击已到达则直接修改订单状态
This commit is contained in:
2025-04-10 09:36:33 +08:00
parent c727fc0c1f
commit 178ed9fc02
6 changed files with 252 additions and 112 deletions
@@ -5,28 +5,61 @@ import {
ProFormText,
ProFormTextArea,
} from '@ant-design/pro-components';
import React from 'react';
import React, { useEffect } from 'react';
interface UpdateFormProps {
onSubmit: (values: DEVICE.Device) => Promise<boolean>;
onVisibleChange: (visible: boolean) => void;
updateModalVisible: boolean;
values?: DEVICE.Device;
waylineOptions: any[];
tourismOptions: any[];
}
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const { onSubmit, onVisibleChange, updateModalVisible, values } = props;
const {
onSubmit,
onVisibleChange,
updateModalVisible,
values,
waylineOptions,
tourismOptions,
} = props;
useEffect(() => {
console.log('当前航线选项:', waylineOptions);
console.log('当前表单值:', values);
}, [waylineOptions, values]);
return (
<ModalForm
title="修改设备信息"
title="修改设备"
width="800px"
visible={updateModalVisible}
onVisibleChange={onVisibleChange}
initialValues={{
...values,
waylineId: values?.waylineId?.toString(), // 确保 waylineId 是字符串
}}
onFinish={onSubmit}
initialValues={values}
modalProps={{
destroyOnClose: true,
forceRender: true,
}}
>
<ProForm.Group>
<ProFormSelect
name="waylineId"
label="航线"
options={waylineOptions}
rules={[{ required: true, message: '请选择航线' }]}
fieldProps={{
showSearch: true,
loading: !waylineOptions?.length,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
}}
/>
<ProFormText
disabled
width="md"
@@ -4,6 +4,7 @@ import {
deleteDevice,
updateDeviceBoundStatus,
} from '@/services/device/api';
import { request } from 'umi';
import { PlusOutlined, ExportOutlined, ImportOutlined, DownloadOutlined } from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import {
@@ -18,9 +19,10 @@ import {
} from '@ant-design/pro-components';
import { Button, message, Popconfirm, Typography, Space, Switch, Upload } from 'antd';
import type { RcFile } from 'antd/lib/upload';
import React, { useRef, useState } from 'react';
import React, { useRef, useState, useCallback, useEffect } from 'react';
import moment from 'moment';
import UpdateForm from './components/UpdateForm';
import { getToken } from '@/utils/authority';
const { Link } = Typography;
@@ -44,9 +46,11 @@ const COMPATIBLE_STATUS = {
const TableList: React.FC = () => {
const [searchParams, setSearchParams] = useState<Record<string, string | number>>({});
const actionRef = useRef<ActionType>();
const [createModalVisible, setCreateModalVisible] = useState<boolean>(false);
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<DEVICE.Device>();
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState<ORDERS.Qrcode>();
const [waylineOptions, setWaylineOptions] = useState<any[]>([]);
const [tourismOptions, setTourismOptions] = useState<any[]>([]);
// 统一的API请求处理函数
const handleRequest = async (
@@ -83,40 +87,104 @@ const TableList: React.FC = () => {
}
};
// 处理导出
const handleExport = async () => {
const hide = message.loading('正在导出...');
try {
const response = await fetch('/api-device/device/export', {
method: 'POST',
});
if (response.ok) {
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `设备信息_${moment().format('YYYY-MM-DD')}.xlsx`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
message.success('导出成功');
} else {
throw new Error('导出失败');
}
} catch (error) {
message.error('导出失败');
} finally {
hide();
}
// 获取认证token
const getAuthHeader = () => {
// 从sessionStorage中获取token
const token = sessionStorage.getItem('access_token') || localStorage.getItem('access_token');
return token ? `Bearer ${token}` : '';
};
// 下载模板
// 打印token信息用于调试
console.log('当前token:', {
sessionToken: sessionStorage.getItem('access_token'),
localToken: localStorage.getItem('access_token'),
authHeader: getAuthHeader()
});
// 修改导出处理函数
const handleExport = () => {
// 创建一个隐藏的表单
const form = document.createElement('form');
form.method = 'POST';
form.action = '/api-device/device/export';
form.style.display = 'none';
// 添加token到请求头
const token = sessionStorage.getItem('access_token');
if (token) {
const tokenInput = document.createElement('input');
tokenInput.type = 'hidden';
tokenInput.name = '_token'; // 添加一个隐藏字段携带token
tokenInput.value = token;
form.appendChild(tokenInput);
}
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
};
// 修改模板下载函数
const handleDownloadTemplate = () => {
// 直接通过链接下载模板
window.location.href = '/api-device/device/template';
};
const columns: ProColumns<DEVICE.Device>[] = [
// 重写获取航线数据的函数
const loadWaylineOptions = async () => {
try {
const result = await wayline({
current: 1,
pageSize: 999 // 获取更多数据
});
if (result?.data) {
const options = result.data.map((item: any) => ({
label: item.name || item.waylineId,
value: item.waylineId
}));
setWaylineOptions(options);
console.log('加载的航线选项:', options);
}
} catch (error) {
console.error('加载航线失败:', error);
message.error('获取航线列表失败');
}
};
// 组件挂载时加载数据
useEffect(() => {
loadWaylineOptions();
}, []);
// 添加操作处理函数
const handleTableAction = async (
action: 'add' | 'edit' | 'delete',
record?: ORDERS.Qrcode,
values?: any
) => {
try {
if (action === 'add') {
await addDevice(values);
message.success('添加成功');
} else if (action === 'edit') {
await updateDevice({ ...values, id: record?.id });
message.success('修改成功');
} else if (action === 'delete') {
await deleteDevice({ id: record?.id });
message.success('删除成功');
}
actionRef.current?.reload();
return true;
} catch (error) {
console.error('操作失败:', error);
message.error('操作失败');
return false;
}
};
// 修改列定义,确保操作列正确显示
const columns: ProColumns<ORDERS.Qrcode>[] = [
{
dataIndex: 'index',
valueType: 'indexBorder',
@@ -184,34 +252,29 @@ const TableList: React.FC = () => {
},
{
title: '操作',
key: 'action',
render: (_, record) => (
<Space>
<Link
onClick={() => {
setCurrentRow(record);
setUpdateModalVisible(true);
}}
>
修改
</Link>
<Popconfirm
title={`确认删除设备[${record.deviceSn}]?`}
onConfirm={async () => {
const success = await handleRequest(
() => deleteDevice(record.deviceSn),
'正在删除',
'删除成功'
);
if (success && actionRef.current) {
actionRef.current.reload();
}
}}
>
<Link>删除</Link>
</Popconfirm>
</Space>
),
dataIndex: 'option',
valueType: 'option',
render: (_, record) => [
<a
key="edit"
onClick={() => {
setCurrentRow(record);
handleUpdateModalVisible(true);
// 立即加载航线数据
loadWaylineOptions();
}}
>
修改
</a>,
<a
key="delete"
onClick={() => {
handleTableAction('delete', record);
}}
>
删除
</a>,
],
},
];
@@ -265,6 +328,21 @@ const TableList: React.FC = () => {
label="设备描述"
placeholder="请输入设备描述"
/>
<ProFormSelect
width="md"
name="waylineId"
label="航线"
placeholder="请选择航线"
options={waylineOptions}
rules={[{ required: true, message: '请选择航线' }]}
fieldProps={{
loading: !waylineOptions.length,
showSearch: true,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
notFoundContent: waylineOptions.length === 0 ? '暂无数据' : undefined,
}}
/>
</ProForm.Group>
);
@@ -287,7 +365,7 @@ const TableList: React.FC = () => {
/>
<ProFormText name="searchValue" />
</QueryFilter>
<ProTable<DEVICE.Device>
<ProTable<ORDERS.Qrcode>
rowKey="deviceSn"
headerTitle="设备管理"
actionRef={actionRef}
@@ -326,7 +404,6 @@ const TableList: React.FC = () => {
if (info.file.status === 'done') {
if (info.file.response.resp_code === 0) {
message.success('导入成功');
// 刷新表格数据
actionRef.current?.reload();
} else {
message.error(info.file.response.resp_msg || '导入失败');
@@ -343,50 +420,73 @@ const TableList: React.FC = () => {
<Button
type="primary"
key="add"
onClick={() => setCreateModalVisible(true)}
onClick={() => {
handleModalVisible(true);
// 打开新增modal时加载航线数据
loadWaylineOptions();
}}
>
<PlusOutlined /> 新增
</Button>,
]}
/>
<ModalForm
title="新增设备"
width="800px"
visible={createModalVisible}
onVisibleChange={setCreateModalVisible}
onFinish={async (values) => {
const success = await handleRequest(
() => saveOrUpdateDevice(values as DEVICE.Device),
'正在添加',
'添加成功',
);
if (success) {
setCreateModalVisible(false);
actionRef.current?.reload();
}
return success;
}}
>
{renderModalContent()}
</ModalForm>
<UpdateForm
onSubmit={async (values) => {
const success = await handleRequest(
() => saveOrUpdateDevice({ ...currentRow, ...values }),
'正在更新',
'更新成功',
);
if (success) {
setUpdateModalVisible(false);
setCurrentRow(undefined);
actionRef.current?.reload();
}
return success;
}}
onVisibleChange={setUpdateModalVisible}
updateModalVisible={updateModalVisible}
values={currentRow}
/>
{updateModalVisible && (
<UpdateForm
onSubmit={async (values) => {
const success = await handleTableAction('edit', currentRow, values);
if (success) {
handleUpdateModalVisible(false);
setCurrentRow(undefined);
}
}}
onVisibleChange={(visible) => {
if (!visible) {
handleUpdateModalVisible(false);
setCurrentRow(undefined);
}
}}
updateModalVisible={updateModalVisible}
values={currentRow}
waylineOptions={waylineOptions}
tourismOptions={tourismOptions}
/>
)}
{createModalVisible && (
<ModalForm
title="新增二维码"
visible={createModalVisible}
onVisibleChange={(visible) => {
if (visible) {
loadWaylineOptions();
}
handleModalVisible(visible);
}}
modalProps={{ destroyOnClose: true }}
onFinish={async (values) => {
const success = await handleTableAction('add', undefined, values);
if (success) {
handleModalVisible(false);
}
}}
>
<ProForm.Group>
<ProFormSelect
width="md"
name="waylineId"
label="航线"
placeholder="请选择航线"
options={waylineOptions}
rules={[{ required: true, message: '请选择航线' }]}
fieldProps={{
showSearch: true,
filterOption: (input, option) =>
(option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
}}
/>
{renderModalContent()}
</ProForm.Group>
</ModalForm>
)}
</PageContainer>
);
};