diff --git a/api/resources.ts b/api/resources.ts new file mode 100644 index 0000000..a881f9c --- /dev/null +++ b/api/resources.ts @@ -0,0 +1,23 @@ +import { post } from './request'; +import { ApiResponse } from './common'; + +// 资源列表请求参数 +export interface ResourcesListRequest { + published: number; +} + +// 资源项数据结构 +export interface Resource { + id: number; + title: string; + creator_name: string; + media_type: number; + url: string; + script_id: number; + created_at: string; +} + +// 获取资源列表 +export const getResourcesList = async (data: ResourcesListRequest): Promise> => { + return post>('/api/resources/resources/list', data); +}; \ No newline at end of file diff --git a/components/pages/home-page2.tsx b/components/pages/home-page2.tsx index 941cd33..ec14bad 100644 --- a/components/pages/home-page2.tsx +++ b/components/pages/home-page2.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useRef } from "react"; +import { useState, useRef, useEffect } from "react"; import { Plus, Table, AlignHorizontalSpaceAround, Loader2 } from "lucide-react"; import "./style/home-page2.css"; import { useRouter } from "next/navigation"; @@ -16,16 +16,48 @@ import { ModeEnum, ResolutionEnum } from '@/api/enums'; +import { + getResourcesList, + Resource +} from '@/api/resources'; export function HomePage2() { const router = useRouter(); const [activeTool, setActiveTool] = useState("stretch"); const [isCreating, setIsCreating] = useState(false); const [createdProjectId, setCreatedProjectId] = useState(null); + const [resources, setResources] = useState([]); + const [isLoadingResources, setIsLoadingResources] = useState(false); const containerRef = useRef(null); - // 视频数据 - const videos: Array<{id: string; url: string; title: string}> = []; + // 将资源数据转换为视频格式 + const videos = resources.map(resource => ({ + id: resource.id.toString(), + url: resource.url, + title: resource.title + })); + + // 获取资源列表 + const fetchResources = async () => { + try { + setIsLoadingResources(true); + const response = await getResourcesList({ published: 1 }); + if (response.code === 0 && response.successful) { + setResources(response.data); + } else { + console.error('获取资源列表失败:', response.message); + } + } catch (error) { + console.error('获取资源列表出错:', error); + } finally { + setIsLoadingResources(false); + } + }; + + // 组件挂载时获取资源 + useEffect(() => { + fetchResources(); + }, []); // 处理编辑视频 const handleEdit = (id: string) => { diff --git a/next.config.js b/next.config.js index 18ae2c3..d1f43bc 100644 --- a/next.config.js +++ b/next.config.js @@ -10,6 +10,10 @@ const nextConfig = { source: '/api/proxy/:path*', destination: 'https://77.smartvideo.py.qikongjian.com/:path*', }, + { + source: '/api/resources/:path*', + destination: 'https://movieflow.api.huiying.video/:path*', + }, ]; }, };