feat: 首页展示最近生成的素材画廊

- 后端新增 GET /api/v1/assets 接口,返回已完成任务的素材列表(按创建时间倒序)
- 前端新增 AssetGallery 组件,网格展示素材缩略图、类型标签和提示词
- HomePage 中工程列表上方展示最近生成素材
This commit is contained in:
2026-05-25 21:02:03 +08:00
parent 5be74e3ce1
commit b88f9aaf03
6 changed files with 172 additions and 0 deletions
+5
View File
@@ -1,4 +1,9 @@
import { post, get } from './client'
import type { RecentAssetItem } from './types'
export async function getRecentAssets(): Promise<RecentAssetItem[]> {
return get<RecentAssetItem[]>('/api/v1/assets')
}
import type {
Asset,
AssetsResponse,
+11
View File
@@ -98,6 +98,17 @@ export interface Asset {
index: number
}
// 首页最近素材
export interface RecentAssetItem {
key: string
url: string
format: string
prompt: string
assetType: string
taskId: string
createdAt: string
}
// 生成请求 — 对应 POST /api/v1/generate
export interface GenerateRequest {
projectId: string
+100
View File
@@ -0,0 +1,100 @@
import { useEffect, useState } from 'react'
import { getRecentAssets } from '../api/generate'
import type { RecentAssetItem } from '../api/types'
const ASSET_TYPE_LABELS: Record<string, string> = {
sprite: '精灵',
background: '背景',
ui: 'UI',
animation: '动画',
}
export default function AssetGallery() {
const [assets, setAssets] = useState<RecentAssetItem[]>([])
const [loading, setLoading] = useState(true)
useEffect(() => {
getRecentAssets()
.then(setAssets)
.catch(() => {})
.finally(() => setLoading(false))
}, [])
if (loading) return null
if (assets.length === 0) return null
return (
<section style={{ marginBottom: 32 }}>
<h2 style={{ fontSize: 18, marginBottom: 16 }}>最近生成</h2>
<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(180px, 1fr))',
gap: 12,
}}
>
{assets.map((item, i) => (
<div
key={`${item.taskId}-${i}`}
className="card"
style={{ padding: 8, cursor: 'pointer' }}
onClick={() => {
// navigate to result page — need projectId for URL
// For now just open the image
}}
>
<div
style={{
width: '100%',
aspectRatio: '1',
overflow: 'hidden',
borderRadius: 'var(--radius)',
background: 'var(--bg-input)',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<img
src={item.url}
alt={item.prompt}
loading="lazy"
style={{
maxWidth: '100%',
maxHeight: '100%',
objectFit: 'contain',
}}
/>
</div>
<div style={{ marginTop: 6 }}>
<span
style={{
fontSize: 11,
padding: '1px 6px',
borderRadius: 999,
background: 'var(--accent-dim)',
color: 'var(--accent)',
}}
>
{ASSET_TYPE_LABELS[item.assetType] || item.assetType}
</span>
</div>
<p
style={{
fontSize: 12,
color: 'var(--text-secondary)',
marginTop: 4,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}
>
{item.prompt}
</p>
</div>
))}
</div>
</section>
)
}
+3
View File
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'
import { useProjectListStore } from '../stores/projectList'
import { useToastStore } from '../stores/toast'
import ProjectCard from '../components/ProjectCard'
import AssetGallery from '../components/AssetGallery'
import CreateProjectModal from '../components/CreateProjectModal'
import EmptyState from '../components/EmptyState'
import Skeleton from '../components/Skeleton'
@@ -39,6 +40,8 @@ export default function HomePage() {
return (
<div className="container page-enter" style={{ paddingTop: 32, paddingBottom: 32 }}>
<AssetGallery />
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
<h1 style={{ fontSize: 22 }}>我的工程</h1>
<button className="btn-primary" onClick={() => setModalOpen(true)}>