feat: 航线管理页面优化
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user