((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();
}
}}>
-
+
{/* 图片容器 */}
-