"use client" import type React from "react" import { useState, useRef, useCallback } from "react" import { Button } from "@/app/components/ui/button" import { Card, CardContent } from "@/app/components/ui/card" import { Progress } from "@/app/components/ui/progress" import { Badge } from "@/app/components/ui/badge" import { Upload, X, File, ImageIcon, Video, FileText, Download, Eye } from "lucide-react" import { cn } from "@/app/lib/utils" export interface UploadedFile { id: string name: string size: number type: string url?: string progress?: number status: "uploading" | "success" | "error" error?: string } export interface FileUploaderProps { /** 允许的文件类型 */ accept?: string /** 是否支持多文件上传 */ multiple?: boolean /** 最大文件大小(字节) */ maxSize?: number /** 最大文件数量 */ maxFiles?: number /** 已上传的文件列表 */ files?: UploadedFile[] /** 文件变更回调 */ onFilesChange?: (files: UploadedFile[]) => void /** 文件上传处理函数 */ onUpload?: (file: File) => Promise<{ url: string; id: string }> /** 文件删除回调 */ onDelete?: (fileId: string) => void /** 是否禁用 */ disabled?: boolean /** 自定义类名 */ className?: string /** 上传区域提示文本 */ placeholder?: string /** 是否显示预览 */ showPreview?: boolean } /** * 统一的文件上传组件 * 支持拖拽上传、多文件上传、进度显示、预览等功能 */ export function FileUploader({ accept, multiple = false, maxSize = 10 * 1024 * 1024, // 10MB maxFiles = 10, files = [], onFilesChange, onUpload, onDelete, disabled = false, className, placeholder = "点击或拖拽文件到此处上传", showPreview = true, }: FileUploaderProps) { const [isDragging, setIsDragging] = useState(false) const [uploadingFiles, setUploadingFiles] = useState([]) const fileInputRef = useRef(null) // 获取文件图标 const getFileIcon = (type: string) => { if (type.startsWith("image/")) return if (type.startsWith("video/")) return