"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' 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') return (
图片 动画 音频 {/* 图片上传 */} 食物图片 上传食物的展示图片,支持 JPEG、PNG、GIF 格式,建议尺寸 300x300px {imageUrl ? (
食物图片预览 当前图片
) : ( { if (files.length > 0) { onImageUpload?.(files[0].url) } }} onRemove={() => onRemove?.('image')} /> )}
{/* 动画上传 */} 食物动画 上传食物的动画效果,支持 MP4、GIF、Lottie 格式,最大 50MB {animationUrl ? (
{animationUrl.endsWith('.gif') ? ( 动画预览 ) : animationUrl.match(/\.(mp4|avi|mov|wmv|flv)$/i) ? (
) : ( { if (files.length > 0) { onAnimationUpload?.(files[0].url) } }} onRemove={() => onRemove?.('animation')} /> )}
{/* 音频上传 */} 食物音效 上传食物相关的音效,支持 MP3、WAV、OGG 等格式,最大 20MB {audioUrl ? (
当前音频
) : ( { if (files.length > 0) { onAudioUpload?.(files[0].url) } }} onRemove={() => onRemove?.('audio')} /> )}
) }