feat[后台管理]:图片的预览和下载功能
This commit is contained in:
@@ -61,6 +61,10 @@
|
||||
{
|
||||
path: '/orders/tourism.html',
|
||||
component: './orders/Tourism',
|
||||
},
|
||||
{
|
||||
path: '/orders/qrcode.html',
|
||||
component: './orders/Qrcode',
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm } from 'antd';
|
||||
import { Typography, message, Popconfirm, Tag } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
@@ -30,6 +30,20 @@ const { Link } = Typography;
|
||||
// }
|
||||
// };
|
||||
|
||||
// 状态颜色映射
|
||||
const statusColorMap = {
|
||||
0: { color: 'yellow', text: '待处理' },
|
||||
1: { color: 'orange', text: '待处理' },
|
||||
3: { color: 'green', text: '已完成' },
|
||||
2: { color: 'red', text: '已取消' },
|
||||
};
|
||||
|
||||
// 渲染状态标签
|
||||
const renderStatus = (status: {} | null | undefined) => {
|
||||
const statusInfo = statusColorMap[status] || { color: 'gray', text: '未知状态' };
|
||||
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
|
||||
};
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
@@ -49,6 +63,7 @@ const TableList: React.FC = () => {
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'orderStatus',
|
||||
render: (status) => renderStatus(status),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, message, Popconfirm } from 'antd';
|
||||
import { Typography, message, Popconfirm, Image } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
@@ -30,6 +30,8 @@ const handleDelete = async (deletefile: ORDERS.OrderFile) => {
|
||||
}
|
||||
};
|
||||
|
||||
const imagePreviewTypes = ['image/jpeg', 'image/png', 'image/gif']; // 可预览的图片类型
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
@@ -47,8 +49,27 @@ const TableList: React.FC = () => {
|
||||
dataIndex: 'fileId',
|
||||
},
|
||||
{
|
||||
title: '文件路径',
|
||||
dataIndex: 'filePath',
|
||||
title: '文件',
|
||||
dataIndex: 'zipViewUrl',
|
||||
render: (zipViewUrl, entity) => (
|
||||
<>
|
||||
{imagePreviewTypes.includes(entity.fileType) ? (
|
||||
<Image src={zipViewUrl} width={100} />
|
||||
) : (
|
||||
<Link href={entity.viewUrl} target="_blank" rel="noopener noreferrer">
|
||||
下载文件
|
||||
</Link>
|
||||
)}
|
||||
<Link
|
||||
href={entity.viewUrl} // 假设 originalUrl 是原图的 URL
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
style={{ marginLeft: '8px', color: 'blue' }} // 添加样式以区分
|
||||
>
|
||||
预览原图
|
||||
</Link>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '文件类型',
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
@import (reference) '~antd/es/style/themes/index';
|
||||
@@ -0,0 +1,121 @@
|
||||
import { qrcode } from '@/services/orders/api';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import {
|
||||
PageContainer,
|
||||
ProFormText,
|
||||
ProTable,
|
||||
QueryFilter,
|
||||
} from '@ant-design/pro-components';
|
||||
import { Typography, Popconfirm } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
// const handleDelete = async (deletefile: FILES.File) => {
|
||||
// const hide = message.loading('正在删除');
|
||||
// try {
|
||||
// const result = await deleteFile(deletefile.id);
|
||||
// hide();
|
||||
// if (result.resp_code === 0) {
|
||||
// message.success('删除File成功');
|
||||
// return true;
|
||||
// } else {
|
||||
// message.error(result.resp_msg);
|
||||
// return false;
|
||||
// }
|
||||
// } catch (error) {
|
||||
// hide();
|
||||
// message.error('删除File失败');
|
||||
// return false;
|
||||
// }
|
||||
// };
|
||||
|
||||
const TableList: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [params, setParams] = useState<Record<string, string | number>>({ });
|
||||
const columns: ProColumns<ORDERS.Qrcode>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
},
|
||||
{
|
||||
title: 'ID',
|
||||
dataIndex: 'id',
|
||||
},
|
||||
{
|
||||
title: 'CodeID',
|
||||
dataIndex: 'codeId',
|
||||
},
|
||||
{
|
||||
title: '景区ID',
|
||||
dataIndex: 'tourismId',
|
||||
},
|
||||
{
|
||||
title: '文件路径',
|
||||
dataIndex: 'path',
|
||||
},
|
||||
{
|
||||
title: '文件ID',
|
||||
dataIndex: 'fileId',
|
||||
},
|
||||
{
|
||||
title: '设备SN',
|
||||
dataIndex: 'deviceSn',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (_, entity) => <Popconfirm
|
||||
title={`确认删除文件[${entity.id}]?`}
|
||||
onConfirm={async () => {
|
||||
// const success = await handleDelete(entity);
|
||||
// if (success) {
|
||||
// if (actionRef.current) {
|
||||
// actionRef.current.reload();
|
||||
// }
|
||||
// }
|
||||
}}
|
||||
>
|
||||
<Link>删除</Link>
|
||||
</Popconfirm>,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer header={{ subTitle: '管理任务' }}>
|
||||
<QueryFilter
|
||||
defaultCollapsed
|
||||
split
|
||||
span={6}
|
||||
className="query-filter"
|
||||
onFinish={async (values) => setParams(values)}
|
||||
>
|
||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
||||
</QueryFilter>
|
||||
<ProTable<ORDERS.Qrcode>
|
||||
rowKey="id"
|
||||
headerTitle="二维码列表"
|
||||
request={qrcode}
|
||||
actionRef={actionRef}
|
||||
columns={columns}
|
||||
search={false}
|
||||
params={params}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TableList;
|
||||
@@ -51,4 +51,13 @@ export async function deleteTourism(id: number) {
|
||||
method: 'DELETE',
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function qrcode(params?: { [key: string]: string | number }) {
|
||||
const { current, pageSize, ...rest } = params ?? {};
|
||||
const result = await request<SYSTEM.Page<ORDERS.Qrcode>>('/api-order/qrcode', {
|
||||
method: 'GET',
|
||||
params: { page: current, limit: pageSize, ...rest },
|
||||
});
|
||||
return { data: result.data, total: result.count };
|
||||
}
|
||||
@@ -17,6 +17,8 @@ declare namespace ORDERS {
|
||||
userId: string;
|
||||
fileId: string;
|
||||
filePath: string;
|
||||
viewUrl: string;
|
||||
zipViewUrl: string;
|
||||
orderNo: string;
|
||||
fileType: string;
|
||||
createTime?: string;
|
||||
@@ -36,4 +38,18 @@ declare namespace ORDERS {
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
type Qrcode = {
|
||||
id: number;
|
||||
codeId: string;
|
||||
tourismId: string;
|
||||
path: string;
|
||||
fileId: string;
|
||||
deviceSn: string;
|
||||
createTime?: string;
|
||||
status: number;
|
||||
tenantId?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user