import { Template } from "interface/template"; import { Container, Heading, Text, Box, Flex, Table, Button, TextField, DropdownMenu, ScrollArea, Dialog, DataList, } from "@radix-ui/themes"; import { PlusIcon, MagnifyingGlassIcon, FileIcon, TrashIcon, DownloadIcon, DotsHorizontalIcon, FileTextIcon, ImageIcon, VideoIcon, } from "@radix-ui/react-icons"; import { useState } from "react"; import type { Resource } from "interface/fields"; // 模拟文件数据 const mockFiles: Resource[] = [ { id: 1, authorId: "1", name: "前端开发规范.pdf", sizeBytes: 1024 * 1024 * 2, // 2MB storagePath: "/files/frontend-guide.pdf", fileType: "application/pdf", category: "documents", description: "前端开发规范文档", createdAt: new Date("2024-03-15"), }, { id: 2, authorId: "1", name: "项目架构图.png", sizeBytes: 1024 * 512, // 512KB storagePath: "/files/architecture.png", fileType: "image/png", category: "images", description: "项目整体架构示意图", createdAt: new Date("2024-03-14"), }, { id: 3, authorId: "1", name: "API文档.md", sizeBytes: 1024 * 256, // 256KB storagePath: "/files/api-doc.md", fileType: "text/markdown", category: "documents", description: "API接口文档", createdAt: new Date("2024-03-13"), }, ]; export default new Template({}, ({ http, args }) => { const [searchTerm, setSearchTerm] = useState(""); const [selectedType, setSelectedType] = useState("all"); const [isUploadDialogOpen, setIsUploadDialogOpen] = useState(false); // 格式化文件大小 const formatFileSize = (bytes: number) => { if (bytes === 0) return "0 Bytes"; const k = 1024; const sizes = ["Bytes", "KB", "MB", "GB"]; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i]; }; // 获取文件图标 const getFileIcon = (fileType: string) => { if (fileType.startsWith("image/")) return ; if (fileType.startsWith("video/")) return ; if (fileType.startsWith("text/")) return ; return ; }; return ( {/* 页面标题和操作栏 */} 文件管理 共 {mockFiles.length} 个文件 {/* 搜索和筛选栏 */} ) => setSearchTerm(e.target.value) } > setSelectedType("all")}> 全部 setSelectedType("documents")}> 文档 setSelectedType("images")}> 图片 setSelectedType("others")}> 其他 {/* 文件列表 */} {/* 桌面端表格视图 */}
文件名 大小 类型 上传时间 操作 {mockFiles.map((file) => ( {getFileIcon(file.fileType)} {file.name} {formatFileSize(file.sizeBytes)} {file.fileType.split("/")[1].toUpperCase()} {file.createdAt.toLocaleDateString()} ))}
{/* 移动端列表视图 */}
{mockFiles.map((file) => ( 文件名 {getFileIcon(file.fileType)} {file.name} 大小 {formatFileSize(file.sizeBytes)} 类型 {file.fileType.split("/")[1].toUpperCase()} 上传时间 {file.createdAt.toLocaleDateString()} 操作 ))}
{/* 上传对话框 */} 上传文件 选择要上传的文件 { // 处理文件上传 console.log(e.target.files); }} />
); });