From a1def790202a57ac674ad5906d41bd545ed9adfc Mon Sep 17 00:00:00 2001 From: hobby Date: Fri, 21 Feb 2025 07:56:49 +0800 Subject: [PATCH] fix chat ui --- src/components/ChatUI.tsx | 2 +- src/components/SharePoster.tsx | 46 ++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/components/ChatUI.tsx b/src/components/ChatUI.tsx index a062638..e5e88c8 100644 --- a/src/components/ChatUI.tsx +++ b/src/components/ChatUI.tsx @@ -448,7 +448,7 @@ const ChatUI = () => { {/* Main Chat Area */}
- +
{messages.map((message) => (
((resolve) => { + canvas.toBlob((blob) => { + resolve(blob!); + }, 'image/png', 1.0); + }); + + // 检查是否为移动设备 + if (/Android|iPhone|iPad|iPod/i.test(navigator.userAgent) && navigator.share) { + // 使用系统分享 + await navigator.share({ + files: [new File([blob], 'chat-history.png', { type: 'image/png' })], + title: '聊天记录', + }); + } else { + // PC端使用传统下载方式 + const pngUrl = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = pngUrl; + a.download = 'chat-history.png'; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(pngUrl); + } } catch (error) { console.error('转换图片失败:', error); toast.error('保存图片失败,请重试'); @@ -154,15 +168,15 @@ export function SharePoster({ isOpen, onClose, chatAreaRef }: SharePosterProps) onClose(); } }}> - + {/* 图片容器 */} -
+
{posterImage && (