// src/pages/gallery\components\GridView.tsx import { ImageItem } from '@/pages/gallery/typings'; import { DeleteOutlined, DownloadOutlined, EyeOutlined, MoreOutlined, LoadingOutlined } from '@ant-design/icons'; import { Button, Checkbox, Dropdown, Menu, Spin } from 'antd'; import React, { FC, useCallback, useState, useEffect } from 'react'; import useAuthImageUrls from '@/components/Hooks/useAuthImageUrls'; import { fetchImage } from '@/services/file/api'; import '../index.css'; import { getAuthization } from '@/utils/userUtils'; interface GridViewProps { imageList: ImageItem[]; viewMode: 'small' | 'large' | 'list' | 'table'; batchMode: boolean; selectedRowKeys: string[]; onPreview: (index: number) => void; onSelect: (instanceId: string, checked: boolean) => void; onDownload: (instanceId: string, imageName: string) => void; onDelete: (instanceId: string, imageName: string) => void; loadingMore?: boolean; onScroll: (e: React.UIEvent) => void; } const GridView: FC = ({ imageList, viewMode, batchMode, selectedRowKeys, onPreview, onSelect, onDownload, onDelete, loadingMore, onScroll, }) => { const getImageSize = useCallback(() => { switch (viewMode) { case 'small': return { width: 150, height: 150 }; case 'large': return { width: 300, height: 300 }; default: return { width: 150, height: 150 }; } }, [viewMode]); const imageSize = getImageSize(); const getImageMenu = useCallback( (item: ImageItem) => ( } onClick={() => { const index = imageList.findIndex((img) => img.instanceId === item.instanceId); onPreview(index); }} > 预览 } onClick={() => onDownload(item.instanceId, item.imageName)} > 下载 } danger onClick={() => onDelete(item.instanceId, item.imageName)} > 删除 ), [imageList, onPreview, onDownload, onDelete], ); // 根据视图模式确定图像 URL const getImageUrl = (instanceId: string, isHighRes?: boolean) => { // 小图模式使用低分辨率图像,除非明确要求高清 if (viewMode === 'small' && !isHighRes) { return `/file/image-low-res/${instanceId}?Authorization=${getAuthization()}`; } // 其他模式使用原图 return `/file/image/${instanceId}?Authorization=${getAuthization()}`; }; return (
{imageList.map((item: ImageItem, index: number) => (
{batchMode && ( onSelect(item.instanceId, e.target.checked)} /> )}
!batchMode && onPreview(index)} />
{item.imageName}
))} {loadingMore && (
)}
); }; export default GridView;