Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 左侧菜单无法打开 #496

Open
nighon opened this issue Dec 12, 2024 · 8 comments
Open

[BUG] 左侧菜单无法打开 #496

nighon opened this issue Dec 12, 2024 · 8 comments
Assignees
Labels

Comments

@nighon
Copy link

nighon commented Dec 12, 2024

移动端页面宽度下,点击左侧菜单按钮,菜单打开后,鼠标放上去,很快菜单就收回去了。

发现 handleResize.ts 里面的 isOutside.value 为 true

if (settingStore.getMobileSubmenuState() && isOutside.value) {

Copy link

boring-cyborg bot commented Dec 12, 2024

Thanks for opening your first issue here! Be sure to follow the issue template! 感谢您在这里反馈第一个问题!请务必遵循问题模板!

@dosubot dosubot bot added the bug label Dec 12, 2024
Copy link

dosubot bot commented Dec 12, 2024

Hey @nighon, I'm here to help you with any bugs, questions, or becoming a contributor. Let's squash those bugs together! 😉

要防止移动端子菜单在打开后快速收回,可以修改 checkMobileSubAside 函数中的 listenerEvent 函数,添加一个延迟或条件来防止菜单立即收回。以下是一个可能的修改:

function checkMobileSubAside(el: Ref<HTMLElement>) {
  const { isOutside } = useMouseInElement(el)
  const settingStore = useSettingStore()
  const listenerEvent = () => {
    if (settingStore.getMobileSubmenuState() && isOutside.value) {
      // 添加延迟或条件以防止立即收回
      setTimeout(() => {
        if (isOutside.value) { // 在延迟后重新检查条件
          settingStore.setMobileSubmenuState(false)
        }
      }, 300) // 延迟时间(毫秒)
    }
  }

  settingStore.getMobileState()
    ? document.addEventListener('mousemove', listenerEvent)
    : document.removeEventListener('mousemove', listenerEvent)
}

此外,可以使用 @vueuse/core 中的 useTimeoutFn 来更有效地管理事件的时机,确保子菜单不会过快收回。以下是如何集成它的示例:

import { useTimeoutFn } from '@vueuse/core'

function checkMobileSubAside(el: Ref<HTMLElement>) {
  const { isOutside } = useMouseInElement(el)
  const settingStore = useSettingStore()
  let timeout: (() => void) | undefined

  const listenerEvent = () => {
    if (settingStore.getMobileSubmenuState() && isOutside.value) {
      timeout?.()
      ;({ stop: timeout } = useTimeoutFn(() => {
        if (isOutside.value) {
          settingStore.setMobileSubmenuState(false)
        }
      }, 300))
    }
  }

  settingStore.getMobileState()
    ? document.addEventListener('mousemove', listenerEvent)
    : document.removeEventListener('mousemove', listenerEvent)
}

这种方法使用 useTimeoutFn 来管理延迟,为处理子菜单的可见性状态提供了更稳健的解决方案。根据具体需求调整延迟时间[1][2]

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@zds-s
Copy link
Member

zds-s commented Dec 13, 2024

解决了吗?

@kanyxmo
Copy link
Member

kanyxmo commented Dec 13, 2024

待复查一下

@nighon nighon changed the title 左侧菜单无法打开 [BUG] 左侧菜单无法打开 Dec 21, 2024
@nighon
Copy link
Author

nighon commented Dec 21, 2024

补充:用了 useTimeoutFn 的办法后,还是不能彻底解决,偶尔会复现。

@kanyxmo
Copy link
Member

kanyxmo commented Dec 25, 2024

发现进入过用户中心后会出现这个问题,近期修复

@DUAN2004
Copy link

为什么获取不到 const appSettings = settingStore.getSettings('app');,一直登不进去

@kanyxmo
Copy link
Member

kanyxmo commented Jan 8, 2025

为什么获取不到 const appSettings = settingStore.getSettings('app');,一直登不进去

这个是必须得有的,前端有一系列默认参数。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants