From efe0d2fdb1fb817dcd29938c317c854a722bb15f Mon Sep 17 00:00:00 2001 From: zhangrenyuan <18990852002@163.com> Date: Wed, 11 Feb 2026 15:23:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(home):=20=E6=B7=BB=E5=8A=A0=E4=BE=A7?= =?UTF-8?q?=E8=BE=B9=E6=A0=8F=E5=AE=BD=E5=BA=A6=E6=8B=96=E6=8B=BD=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增侧边栏拖拽手柄,支持在200px至350px范围内调整宽度 - 优化菜单项文本显示,添加标题提示并启用文本溢出省略 - 调整滚动条样式,提升视觉体验 - 拖拽时禁用过渡动画以解决卡顿问题,优化交互流畅度 --- src/views/home.vue | 105 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 12 deletions(-) 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())