diff --git a/app/(chat)/canvas/page.tsx b/app/(chat)/canvas/page.tsx index 34c114738..ede75e562 100644 --- a/app/(chat)/canvas/page.tsx +++ b/app/(chat)/canvas/page.tsx @@ -1,289 +1,25 @@ "use client"; -import { useEffect, useState } from "react"; +import { useEffect } from "react"; import { useRouter } from "next/navigation"; -import { Plus, LayoutGrid, Trash2, Edit2, MoreVertical, Clock, Loader2 } from "lucide-react"; -import { Button } from "@/components/ui/button"; -import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, -} from "@/components/ui/dialog"; -import { Input } from "@/components/ui/input"; -import { toast } from "sonner"; -import { canvasService } from "@/services/canvas"; +import { Loader2 } from "lucide-react"; -interface CanvasProject { - id: string; - title: string; - description?: string; - thumbnail?: string; - createdAt: string; - updatedAt: string; -} - -export default function CanvasListPage() { +// 自动重定向到新画布 +export default function CanvasRedirectPage() { const router = useRouter(); - const [projects, setProjects] = useState([]); - const [isLoading, setIsLoading] = useState(true); - const [isCreating, setIsCreating] = useState(false); - const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); - const [projectToDelete, setProjectToDelete] = useState(null); - const [renameDialogOpen, setRenameDialogOpen] = useState(false); - const [projectToRename, setProjectToRename] = useState(null); - const [newTitle, setNewTitle] = useState(""); - - // 加载画布列表 - const loadProjects = async () => { - setIsLoading(true); - const result = await canvasService.getProjects(); - if (result.success && result.data) { - setProjects(result.data); - } else { - toast.error(result.error || "加载失败"); - } - setIsLoading(false); - }; useEffect(() => { - loadProjects(); - }, []); - - // 创建新画布 - const handleCreateProject = async () => { - setIsCreating(true); - const result = await canvasService.createProject({ - title: "未命名画布", - }); - - if (result.success && result.data) { - toast.success("创建成功"); - router.push(`/canvas/${result.data.id}`); - } else { - toast.error(result.error || "创建失败"); - setIsCreating(false); - } - }; - - // 删除画布 - const handleDeleteProject = async () => { - if (!projectToDelete) return; - - const result = await canvasService.deleteProject(projectToDelete.id); - if (result.success) { - toast.success("删除成功"); - setProjects(projects.filter(p => p.id !== projectToDelete.id)); - } else { - toast.error(result.error || "删除失败"); - } - setDeleteDialogOpen(false); - setProjectToDelete(null); - }; - - // 重命名画布 - const handleRenameProject = async () => { - if (!projectToRename || !newTitle.trim()) return; - - const result = await canvasService.updateProject(projectToRename.id, { - title: newTitle.trim(), - }); - - if (result.success) { - toast.success("重命名成功"); - setProjects(projects.map(p => - p.id === projectToRename.id ? { ...p, title: newTitle.trim() } : p - )); - } else { - toast.error(result.error || "重命名失败"); - } - setRenameDialogOpen(false); - setProjectToRename(null); - setNewTitle(""); - }; - - // 格式化时间 - const formatDate = (dateString: string) => { - const date = new Date(dateString); - return date.toLocaleDateString("zh-CN", { - year: "numeric", - month: "short", - day: "numeric", - hour: "2-digit", - minute: "2-digit", - }); - }; + // 生成新的画布 ID 并跳转 + const newId = crypto.randomUUID(); + router.replace(`/canvas/${newId}`); + }, [router]); return ( -
- {/* 页面标题 */} -
-
- -

无限画布

-
- +
+
+ + 正在创建新画布...
- - {/* 画布列表 */} -
- {isLoading ? ( -
- -
- ) : projects.length === 0 ? ( -
- -

还没有画布

-

- 创建一个新画布,开始你的创作之旅 -

- -
- ) : ( -
- {projects.map((project) => ( - router.push(`/canvas/${project.id}`)} - > - -
- - {project.title} - - - e.stopPropagation()}> - - - - { - e.stopPropagation(); - setProjectToRename(project); - setNewTitle(project.title); - setRenameDialogOpen(true); - }} - > - - 重命名 - - { - e.stopPropagation(); - setProjectToDelete(project); - setDeleteDialogOpen(true); - }} - > - - 删除 - - - -
-
- -
- {project.thumbnail ? ( - {project.title} - ) : ( - - )} -
-
- -
- - {formatDate(project.updatedAt)} -
-
-
- ))} -
- )} -
- - {/* 删除确认对话框 */} - - - - 确认删除 - - 确定要删除画布 "{projectToDelete?.title}" 吗?此操作无法撤销。 - - - - - - - - - - {/* 重命名对话框 */} - - - - 重命名画布 - - setNewTitle(e.target.value)} - placeholder="输入新名称" - onKeyDown={(e) => { - if (e.key === "Enter") { - handleRenameProject(); - } - }} - /> - - - - - -
); } diff --git a/components/top-navbar.tsx b/components/top-navbar.tsx index 4ad46dc7d..9f5c9f09b 100644 --- a/components/top-navbar.tsx +++ b/components/top-navbar.tsx @@ -174,17 +174,13 @@ export function TopNavbar({ )} {/* AI智能精选 */} - + AI精选 + {/* 精选榜单 */} @@ -255,33 +251,27 @@ export function TopNavbar({ {/* 无限画布 */} - + 无限画布 + {/* 我的图册 */} - + 我的图册 + {/* 分隔线 (如果有链接或图册按钮,且是管理员) */} {isAdmin && ( @@ -290,16 +280,13 @@ export function TopNavbar({ {/* 系统设置(仅管理员可见)*/} {isAdmin && ( - + )}