修复AI聊天窗口:调整尺寸到420x680,添加拖拽功能,确保窗口在视口内
This commit is contained in:
parent
720ed40b59
commit
8b2fbff098
@ -78,10 +78,48 @@ export default function AIChatWidget() {
|
||||
const [images, setImages] = useState<File[]>([])
|
||||
const [imagePreviews, setImagePreviews] = useState<string[]>([])
|
||||
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<HTMLDivElement>(null)
|
||||
const fileInputRef = useRef<HTMLInputElement>(null)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const dropZoneRef = useRef<HTMLDivElement>(null)
|
||||
const headerRef = useRef<HTMLDivElement>(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 && (
|
||||
<>
|
||||
<style dangerouslySetInnerHTML={{ __html: shimmerStyle }} />
|
||||
<div className="absolute bottom-16 right-0 w-[546px] h-[884px] bg-white dark:bg-gray-900 rounded-lg shadow-xl border border-gray-200 dark:border-gray-700 overflow-hidden flex flex-col">
|
||||
{/* 头部 - 简洁风格 */}
|
||||
<div className="px-6 py-4 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between">
|
||||
<div
|
||||
className="fixed w-[420px] h-[680px] bg-white dark:bg-gray-900 rounded-lg shadow-xl border border-gray-200 dark:border-gray-700 overflow-hidden flex flex-col"
|
||||
style={{
|
||||
left: position.x ? `${position.x}px` : 'auto',
|
||||
top: position.y ? `${position.y}px` : 'auto',
|
||||
right: position.x ? 'auto' : '24px',
|
||||
bottom: position.y ? 'auto' : '96px',
|
||||
maxHeight: '80vh'
|
||||
}}
|
||||
>
|
||||
{/* 头部 - 简洁风格 - 可拖拽 */}
|
||||
<div
|
||||
ref={headerRef}
|
||||
onMouseDown={handleMouseDown}
|
||||
className="px-6 py-4 bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between cursor-move select-none"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-lg bg-blue-500 flex items-center justify-center">
|
||||
<svg className="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user