feat: 航线管理页面优化

This commit is contained in:
2025-11-04 11:53:35 +08:00
parent e106e09fa5
commit e23eecdbfd
21 changed files with 515 additions and 1070 deletions
@@ -2,6 +2,7 @@
import { ModalForm, ProForm, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { Button, Upload, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
import { deviceApi } from '@/services/device';
export type WaylineFormValues = {
id?: number;
@@ -33,21 +34,57 @@ async function uploadWaylineFile(file: File) {
const WaylineForm: React.FC<WaylineFormProps> = ({ title, visible, onVisibleChange, onFinish, initialValues, workspaceOptions }) => {
const formRef = useRef<any>();
const [fileInfo, setFileInfo] = useState<{ id: string; url: string } | undefined>();
const [loading, setLoading] = useState(false);
/**
* 当编辑页面打开时,如果有waylineId,调用接口获取完整信息
*/
useEffect(() => {
if (initialValues) {
if (visible && initialValues?.waylineId) {
setLoading(true);
deviceApi
.getWaylineInfoByWaylineId(initialValues.waylineId)
.then((data) => {
if (data) {
formRef.current?.setFieldsValue({
id: data.id,
name: data.name,
waylineId: data.waylineId,
workspaceId: data.workspaceId,
sign: data.sign,
});
// 如果有fileUrl,设置文件信息
if (data.fileUrl) {
setFileInfo({
id: data.waylineId || data.id?.toString() || '',
url: data.fileUrl,
});
}
}
})
.catch((err) => {
console.error('获取航线信息失败:', err);
message.error('获取航线信息失败');
})
.finally(() => setLoading(false));
} else if (visible && initialValues) {
// 新增时直接回显
formRef.current?.setFieldsValue(initialValues);
}
}, [initialValues]);
}, [visible, initialValues?.waylineId]);
return (
<ModalForm<WaylineFormValues>
title={title}
visible={visible}
formRef={formRef}
loading={loading}
onVisibleChange={(v) => {
onVisibleChange?.(v);
if (!v) setFileInfo(undefined);
if (!v) {
setFileInfo(undefined);
setLoading(false);
}
}}
onFinish={async (values) => {
if (!values.waylineId && !fileInfo) {
@@ -2,7 +2,8 @@ import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import type { ActionType } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import type { ProColumns } from '@ant-design/pro-components';
import { Space } from 'antd';
import { Space, message } from 'antd';
import { DownloadOutlined } from '@ant-design/icons';
import { deviceApi } from '@/services/device';
import { downloadByUrl } from '@/utils/download';
@@ -21,27 +22,64 @@ const WaylineTable = forwardRef<WaylineTableRef, WaylineTableProps>(({ params, o
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
/**
* 处理航线文件下载
* 先通过waylineId获取航线信息(包含fileUrl),再使用fileUrl下载
*/
const handleDownload = async (record: any) => {
try {
if (!record.waylineId) {
message.error('航线ID缺失');
return;
}
const hide = message.loading('获取航线信息中...');
try {
// 通过waylineId获取航线完整信息,包括fileUrl
const waylineInfo = await deviceApi.getWaylineInfoByWaylineId(record.waylineId);
hide();
if (!waylineInfo) {
message.error('无法获取航线信息');
return;
}
const fileUrl = waylineInfo.fileUrl;
if (!fileUrl) {
message.error('航线文件URL不存在');
return;
}
// 使用fileUrl直接下载
const fileName = record.name || `wayline_${record.waylineId}`;
downloadByUrl(fileUrl, fileName);
message.success('开始下载航线文件');
} catch (error) {
hide();
console.error('获取航线信息失败:', error);
message.error('获取航线信息失败');
}
} catch (error) {
message.error('下载失败');
console.error('下载航线文件错误:', error);
}
};
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '航线名称', dataIndex: 'name' },
{ title: '航线ID', dataIndex: 'waylineId' },
{ title: '空间ID', dataIndex: 'workspaceId' },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '航线文件', dataIndex: 'fileUrl', search: false,
render: (_, record) => record.fileUrl ? (
<a
href={record.fileUrl}
onClick={(e) => { e.preventDefault(); downloadByUrl(record.fileUrl, record.name || 'wayline.kmz'); }}
>下载文件</a>
) : '-'
},
{ title: '文件签名', dataIndex: 'sign', ellipsis: true, copyable: true },
{
title: '操作', key: 'action', valueType: 'option',
render: (_, record) => (
<Space>
<a onClick={() => onEdit?.(record)}>编辑</a>
<a onClick={() => handleDownload(record)} title="下载航线文件">
<DownloadOutlined /> 下载
</a>
<a style={{ color: '#1677ff' }} onClick={() => onDelete?.(record)}>删除</a>
</Space>
)
@@ -62,3 +100,4 @@ const WaylineTable = forwardRef<WaylineTableRef, WaylineTableProps>(({ params, o
});
export default WaylineTable;
@@ -62,8 +62,15 @@ const WaylinePage: React.FC = () => {
return (
<PageContainer header={{ title: '航线管理' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} onFinish={async (values) => setQuery(values)}>
<ProFormText name="name" label="名称" placeholder="请输入关键字" />
<SearchBarPlus
defaultCollapsed
split span={6}
hideReset
showTenant={false}
onTenantChanged={() => tableRef.current?.reload()}
onFinish={async (values) => setQuery(values)}>
<ProFormText name="name" label="航线名称" />
<ProFormText name="waylineId" label="航线code" />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />