Files
xiaoxia-saas/apps/web/src/pages/templates/TemplateLibrary.tsx
T
xiaoxia 8e2c563b42
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate - Code Quality (push) Has been cancelled
CI/CD Pipeline / Validate - Type Check (mypy) (push) Has been cancelled
CI/CD Pipeline / Validate - Migration (alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
refactor(template-library): 三阶段重构 TemplateLibrary(716→107行, -85%)(#931)
2026-07-26 22:06:12 +08:00

108 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 模板库页面(升级版)— V21 设计系统
* 对接后端模板管理 API:
* - 分页查询(page/page_size/category/keyword/duration_range)
* - 模板详情(素材规则、字幕样式、BGM、比例等参数配置)
* - 复制模板 / 从模板生成
* - 卡片网格布局 + 类型筛选 + 搜索 + 收藏
*/
import React from "react"
import { useTemplateLibrary } from "./hooks/useTemplateLibrary"
import { useTemplateDetail } from "./hooks/useTemplateDetail"
import { TemplateHeader } from "./components/template-library/TemplateHeader"
import { TemplateToolbar } from "./components/template-library/TemplateToolbar"
import { TemplateGrid } from "./components/template-library/TemplateGrid"
import { TemplateDetailModal } from "./components/template-library/TemplateDetailModal"
import "./templates.css"
const TemplateLibrary: React.FC = () => {
const {
templates,
totalTemplates,
isLoading,
isError,
error,
searchText,
activeType,
durationRange,
page,
pageSize,
setPage,
toggleFavorite,
handleCopy,
handleUse,
handleCreate,
handleSearchChange,
handleCategoryChange,
handleDurationChange,
} = useTemplateLibrary()
const {
previewTemplate,
detailLoading,
handlePreview,
handleClose,
handleToggleFavorite,
handleUse: handleUseFromDetail,
handleCopy: handleCopyFromDetail,
} = useTemplateDetail({
onToggleFavorite: (id) => toggleFavorite(id),
onUse: handleUse,
onCopy: handleCopy,
})
return (
<div className="xx-templates-page">
{/* 页面头部 */}
<TemplateHeader onCreateClick={handleCreate} />
{/* 工具栏:搜索 + 类型按钮组 + 时长筛选 */}
<TemplateToolbar
searchText={searchText}
onSearchChange={handleSearchChange}
activeType={activeType}
onTypeChange={handleCategoryChange}
durationRange={durationRange}
onDurationChange={handleDurationChange}
/>
{/* 模板展示区 */}
<TemplateGrid
templates={templates}
total={totalTemplates}
page={page}
pageSize={pageSize}
isLoading={isLoading}
isError={isError}
errorMessage={error?.message}
searchText={searchText}
activeType={activeType}
durationRange={durationRange}
onPageChange={setPage}
onPreview={handlePreview}
onToggleFavorite={toggleFavorite}
onUse={handleUse}
/>
{/* 详情弹窗 */}
{previewTemplate && (
<TemplateDetailModal
template={previewTemplate}
isFavorite={previewTemplate.is_favorite ?? false}
onClose={handleClose}
onToggleFavorite={handleToggleFavorite}
onUse={handleUseFromDetail}
onCopy={handleCopyFromDetail}
/>
)}
{/* 详情加载中的提示 */}
{detailLoading && previewTemplate && (
<div className="xx-template-detail-loading">加载中...</div>
)}
</div>
)
}
export default TemplateLibrary