import { useEffect, useState, useMemo } from 'react' import { getRecentAssets } from '../api/generate' import type { RecentAssetItem } from '../api/types' const ASSET_TYPE_LABELS: Record = { sprite: '精灵', background: '背景', ui: 'UI', animation: '动画', } const CATEGORIES = [ { key: 'all', label: '全部' }, { key: 'spritesheet', label: '精灵表' }, { key: 'frame', label: '帧' }, { key: 'tileset', label: '场景瓦片' }, { key: 'background', label: '背景' }, { key: 'ui', label: 'UI' }, ] function matchCategory(item: RecentAssetItem, cat: string): boolean { switch (cat) { case 'all': return true case 'spritesheet': return item.metaType === 'spritesheet' case 'frame': return item.metaType === 'frame' || item.metaType === 'preview' || item.format === 'gif' case 'tileset': return item.assetType === 'sprite' && item.metaType === 'spritesheet' case 'background': return item.assetType === 'background' case 'ui': return item.assetType === 'ui' default: return true } } export default function AssetGallery() { const [assets, setAssets] = useState([]) const [loading, setLoading] = useState(true) const [activeCat, setActiveCat] = useState('all') useEffect(() => { getRecentAssets() .then(setAssets) .catch(() => {}) .finally(() => setLoading(false)) }, []) const filtered = useMemo( () => assets.filter(item => matchCategory(item, activeCat)), [assets, activeCat] ) if (loading) return null if (assets.length === 0) return null return (

最近生成

{/* 分类标签 */}
{CATEGORIES.map(cat => ( ))}
{/* 素材网格 */} {filtered.length === 0 ? (

暂无此类素材

) : (
{filtered.map((item, i) => (
{item.prompt}
{ASSET_TYPE_LABELS[item.assetType] || item.assetType}

{item.prompt}

))}
)}
) }