From 83473b457fe00d96b4fecd3debc3a366431b5fd8 Mon Sep 17 00:00:00 2001 From: 15945162479 <15945162479@qq.com> Date: Sat, 13 Dec 2025 14:46:09 +0800 Subject: [PATCH] Add File --- .../components/TransparentMediaOverlay.tsx | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/elderly/components/TransparentMediaOverlay.tsx diff --git a/src/elderly/components/TransparentMediaOverlay.tsx b/src/elderly/components/TransparentMediaOverlay.tsx new file mode 100644 index 0000000..b3b2be5 --- /dev/null +++ b/src/elderly/components/TransparentMediaOverlay.tsx @@ -0,0 +1,112 @@ +import React, { useEffect, useState } from 'react'; +import { X } from 'lucide-react'; + +interface TransparentMediaOverlayProps { + mediaFilename: string; + mediaType: 'photo' | 'video'; + avatarText?: string; + duration?: number; // 展示时长(秒) + onClose: () => void; +} + +/** + * 透明窗口媒体展示组件 + * 在数字人主页中部弹出,展示媒体文件 + */ +export const TransparentMediaOverlay: React.FC = ({ + mediaFilename, + mediaType, + avatarText, + duration = 30, // 默认30秒 + onClose, +}) => { + const [autoCloseTimer, setAutoCloseTimer] = useState(duration); + const [isClosing, setIsClosing] = useState(false); + + // 构建媒体文件URL + const mediaUrl = `http://localhost:8000/uploads/${mediaFilename}`; + + // 处理关闭(带淡出动画) + const handleClose = () => { + setIsClosing(true); + setTimeout(() => { + onClose(); + }, 300); // 等待淡出动画完成 + }; + + // 自动关闭倒计时 + useEffect(() => { + const interval = setInterval(() => { + setAutoCloseTimer((prev) => { + if (prev <= 1) { + clearInterval(interval); + handleClose(); + return 0; + } + return prev - 1; + }); + }, 1000); + + return () => clearInterval(interval); + }, []); + + return ( +
+ {/* 媒体内容容器 - 下调10% */} +
+ {/* 媒体内容 - 尽量大 */} +
+ {mediaType === 'photo' ? ( + 展示的照片 { + console.error('图片加载失败:', mediaUrl); + (e.target as HTMLImageElement).src = '/placeholder-photo.jpg'; + }} + /> + ) : ( +
+
+
+ ); +};