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 && ( <>