"use client" import React, { useState } from 'react' import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs' import { FileUpload } from '@/components/ui/file-upload' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Image, Play, Music, Trash2 } from 'lucide-react' import { Button } from '@/components/ui/button' import type { UploadResponse } from '@/lib/api/upload' interface FoodMediaUploadProps { /** 当前图片URL */ imageUrl?: string /** 当前动画URL */ animationUrl?: string /** 当前音频URL */ audioUrl?: string /** 图片上传成功回调 */ onImageUpload?: (url: string) => void /** 动画上传成功回调 */ onAnimationUpload?: (url: string) => void /** 音频上传成功回调 */ onAudioUpload?: (url: string) => void /** 文件移除回调 */ onRemove?: (type: 'image' | 'animation' | 'audio') => void /** 是否禁用 */ disabled?: boolean } export function FoodMediaUpload({ imageUrl, animationUrl, audioUrl, onImageUpload, onAnimationUpload, onAudioUpload, onRemove, disabled = false, }: FoodMediaUploadProps) { const [activeTab, setActiveTab] = useState('image') // 准备默认文件列表 const getDefaultFiles = (url?: string, type: string = 'image'): UploadResponse[] => { if (!url) return [] return [{ url, filename: `当前${type === 'image' ? '图片' : type === 'animation' ? '动画' : '音频'}`, size: 0, mimeType: type === 'image' ? 'image/jpeg' : type === 'animation' ? 'video/mp4' : 'audio/mp3' }] } return (
图片 动画 音频 {/* 图片上传 */} 食物图片 上传食物的展示图片,支持 JPEG、PNG、GIF 格式,建议尺寸 300x300px { if (files.length > 0) { onImageUpload?.(files[0].url) } }} onRemove={() => onRemove?.('image')} /> {imageUrl && (
食物图片预览 当前图片
)}
{/* 动画上传 */} 食物动画 上传食物的动画效果,支持 MP4、GIF、Lottie 格式,最大 50MB { if (files.length > 0) { onAnimationUpload?.(files[0].url) } }} onRemove={() => onRemove?.('animation')} /> {animationUrl && (
{animationUrl.endsWith('.gif') ? ( 动画预览 ) : animationUrl.match(/\.(mp4|avi|mov|wmv|flv)$/i) ? (
)}
{/* 音频上传 */} 食物音效 上传食物相关的音效,支持 MP3、WAV、OGG 等格式,最大 20MB { if (files.length > 0) { onAudioUpload?.(files[0].url) } }} onRemove={() => onRemove?.('audio')} /> {audioUrl && (
当前音频
)}
) }