diff --git a/src/views/home.vue b/src/views/home.vue index d6421b6..776f667 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -309,6 +309,44 @@ const getPathByQueryId = (queryId) => { return matchedRoutes[0]?.path || null } +// ------------------ 侧边栏拖拽调整宽度 ------------------ +const sidebarWidth = ref(230) // 默认宽度 +const isResizing = ref(false) + +const startResize = (e) => { + // 阻止浏览器默认行为(如文本选择),解决"拖动前几像素无反应"的延迟问题 + e.preventDefault() + + isResizing.value = true + // 记录初始X坐标 + const startX = e.clientX + const startWidth = sidebarWidth.value + + // 动态添加全局事件监听,确保拖拽流畅 + const doDrag = (e) => { + if (!isResizing.value) return + // 计算新宽度 = 初始宽度 + (当前鼠标X - 初始鼠标X) + const newWidth = startWidth + (e.clientX - startX) + // 限制最小最大宽度 + if (newWidth >= 200 && newWidth <= 350) { + sidebarWidth.value = newWidth + } + } + + const stopDrag = () => { + isResizing.value = false + document.removeEventListener('mousemove', doDrag) + document.removeEventListener('mouseup', stopDrag) + document.body.style.cursor = '' // 恢复鼠标样式 + document.body.style.userSelect = '' // 恢复文字选择 + } + + document.addEventListener('mousemove', doDrag) + document.addEventListener('mouseup', stopDrag) + document.body.style.cursor = 'col-resize' // 强制鼠标样式 + document.body.style.userSelect = 'none' // 禁止文字选中 +} + // 点击消息 → 已读 + 跳转 const handleMessageClick = async (item) => { const res = await API({ @@ -350,7 +388,10 @@ onMounted(() => getMessage())