fix chat ui
This commit is contained in:
@@ -448,7 +448,7 @@ const ChatUI = () => {
|
|||||||
|
|
||||||
{/* Main Chat Area */}
|
{/* Main Chat Area */}
|
||||||
<div className="flex-1 overflow-hidden">
|
<div className="flex-1 overflow-hidden">
|
||||||
<ScrollArea className="h-full p-4" ref={chatAreaRef}>
|
<ScrollArea className="h-full p-2" ref={chatAreaRef}>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{messages.map((message) => (
|
{messages.map((message) => (
|
||||||
<div key={message.id}
|
<div key={message.id}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function SharePoster({ isOpen, onClose, chatAreaRef }: SharePosterProps)
|
|||||||
style: {
|
style: {
|
||||||
padding: `${extraSpace}px`,
|
padding: `${extraSpace}px`,
|
||||||
margin: '0',
|
margin: '0',
|
||||||
width: '110%',
|
width: '120%',
|
||||||
height: '110%',
|
height: '110%',
|
||||||
transform: `scale(${scale})`,
|
transform: `scale(${scale})`,
|
||||||
transformOrigin: 'top left',
|
transformOrigin: 'top left',
|
||||||
@@ -111,7 +111,7 @@ export function SharePoster({ isOpen, onClose, chatAreaRef }: SharePosterProps)
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 创建高分辨率canvas
|
// 创建高分辨率canvas
|
||||||
const scale = 2; // 将分辨率提高2倍
|
const scale = 2;
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = img.width * scale;
|
canvas.width = img.width * scale;
|
||||||
canvas.height = img.height * scale;
|
canvas.height = img.height * scale;
|
||||||
@@ -121,22 +121,36 @@ export function SharePoster({ isOpen, onClose, chatAreaRef }: SharePosterProps)
|
|||||||
throw new Error('无法创建canvas上下文');
|
throw new Error('无法创建canvas上下文');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置更好的图像渲染质量
|
|
||||||
ctx.imageSmoothingEnabled = true;
|
ctx.imageSmoothingEnabled = true;
|
||||||
ctx.imageSmoothingQuality = 'high';
|
ctx.imageSmoothingQuality = 'high';
|
||||||
|
|
||||||
// 按比例缩放绘制
|
|
||||||
ctx.scale(scale, scale);
|
ctx.scale(scale, scale);
|
||||||
ctx.drawImage(img, 0, 0);
|
ctx.drawImage(img, 0, 0);
|
||||||
|
|
||||||
// 使用更高质量的PNG导出
|
// 转换为Blob
|
||||||
const pngUrl = canvas.toDataURL('image/png', 1.0);
|
const blob = await new Promise<Blob>((resolve) => {
|
||||||
const a = document.createElement('a');
|
canvas.toBlob((blob) => {
|
||||||
a.href = pngUrl;
|
resolve(blob!);
|
||||||
a.download = 'chat-history.png';
|
}, 'image/png', 1.0);
|
||||||
document.body.appendChild(a);
|
});
|
||||||
a.click();
|
|
||||||
document.body.removeChild(a);
|
// 检查是否为移动设备
|
||||||
|
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) {
|
} catch (error) {
|
||||||
console.error('转换图片失败:', error);
|
console.error('转换图片失败:', error);
|
||||||
toast.error('保存图片失败,请重试');
|
toast.error('保存图片失败,请重试');
|
||||||
@@ -154,15 +168,15 @@ export function SharePoster({ isOpen, onClose, chatAreaRef }: SharePosterProps)
|
|||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<DialogContent className="max-w-[95vw] w-full sm:max-w-[90vw] max-h-[90vh] flex flex-col p-0">
|
<DialogContent className="max-w-[100vw] w-full sm:max-w-[100vw] max-h-[90vh] flex flex-col p-0">
|
||||||
{/* 图片容器 */}
|
{/* 图片容器 */}
|
||||||
<div className="flex-1 overflow-auto p-1">
|
<div className="flex-1 overflow-auto ">
|
||||||
{posterImage && (
|
{posterImage && (
|
||||||
<div className="flex items-center justify-center min-h-full">
|
<div className="flex items-center justify-center min-h-full">
|
||||||
<img
|
<img
|
||||||
src={posterImage}
|
src={posterImage}
|
||||||
alt="Share Poster"
|
alt="Share Poster"
|
||||||
className="max-w-full w-auto h-auto"
|
className="w-full w-auto h-auto"
|
||||||
style={{
|
style={{
|
||||||
objectFit: 'contain',
|
objectFit: 'contain',
|
||||||
imageRendering: 'crisp-edges',
|
imageRendering: 'crisp-edges',
|
||||||
|
|||||||
Reference in New Issue
Block a user