From 8b2fbff098ba8d22416f3b80d87aa2e733e0fcdb Mon Sep 17 00:00:00 2001 From: chenpei Date: Mon, 27 Oct 2025 21:17:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DAI=E8=81=8A=E5=A4=A9=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=EF=BC=9A=E8=B0=83=E6=95=B4=E5=B0=BA=E5=AF=B8=E5=88=B0?= =?UTF-8?q?420x680=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=8B=96=E6=8B=BD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E7=A1=AE=E4=BF=9D=E7=AA=97=E5=8F=A3=E5=9C=A8?= =?UTF-8?q?=E8=A7=86=E5=8F=A3=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/AIChatWidget.tsx | 57 +++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/components/AIChatWidget.tsx b/components/AIChatWidget.tsx index a8d4f51e..d649aaee 100644 --- a/components/AIChatWidget.tsx +++ b/components/AIChatWidget.tsx @@ -78,10 +78,48 @@ export default function AIChatWidget() { const [images, setImages] = useState([]) const [imagePreviews, setImagePreviews] = useState([]) const [isDragging, setIsDragging] = useState(false) + const [windowDragging, setWindowDragging] = useState(false) + const [position, setPosition] = useState({ x: 0, y: 0 }) + const [dragStart, setDragStart] = useState({ x: 0, y: 0 }) const messagesEndRef = useRef(null) const fileInputRef = useRef(null) const containerRef = useRef(null) const dropZoneRef = useRef(null) + const headerRef = useRef(null) + + // 窗口拖拽功能 + const handleMouseDown = (e: React.MouseEvent) => { + if (e.button !== 0) return // 只响应左键 + setWindowDragging(true) + setDragStart({ + x: e.clientX - position.x, + y: e.clientY - position.y + }) + } + + useEffect(() => { + const handleMouseMove = (e: MouseEvent) => { + if (!windowDragging) return + setPosition({ + x: e.clientX - dragStart.x, + y: e.clientY - dragStart.y + }) + } + + const handleMouseUp = () => { + setWindowDragging(false) + } + + if (windowDragging) { + document.addEventListener('mousemove', handleMouseMove) + document.addEventListener('mouseup', handleMouseUp) + } + + return () => { + document.removeEventListener('mousemove', handleMouseMove) + document.removeEventListener('mouseup', handleMouseUp) + } + }, [windowDragging, dragStart]) // 点击外部关闭 useEffect(() => { @@ -357,9 +395,22 @@ export default function AIChatWidget() { {isOpen && ( <>