@@ -34,6 +34,7 @@ export class MenuManager {
3434 private showTimeout : any = null ;
3535 private submenuShowDelay = 100 ;
3636 private submenuHideDelay = 500 ;
37+ private menuInitializationDelay = 200 ; // 菜单初始化延迟时间(毫秒)
3738
3839 /**
3940 * 显示菜单
@@ -50,13 +51,27 @@ export class MenuManager {
5051 this . menuContainer = createElement ( 'div' , MENU_CONTAINER_CLASS ) ;
5152 applyStyles ( this . menuContainer , MENU_STYLES . menuContainer ) ;
5253 document . body . appendChild ( this . menuContainer ) ;
54+ this . menuContainer . addEventListener ( 'contextmenu' , ( e : MouseEvent ) => {
55+ e . preventDefault ( ) ;
56+ } ) ;
5357
5458 // 创建菜单项
5559 this . createMenuItems ( menuItems , this . menuContainer ) ;
5660
5761 // 调整菜单位置
5862 this . positionMenu ( this . menuContainer , x , y ) ;
5963
64+ // 临时禁用指针事件,防止位置调整后立即触发 mouseenter
65+ // 这可以避免菜单位置调整到鼠标下方时意外触发二级菜单
66+ this . menuContainer . style . pointerEvents = 'none' ;
67+
68+ // 延迟启用指针事件
69+ setTimeout ( ( ) => {
70+ if ( this . menuContainer ) {
71+ this . menuContainer . style . pointerEvents = 'auto' ;
72+ }
73+ } , this . menuInitializationDelay ) ;
74+
6075 // 添加全局点击事件,用于关闭菜单
6176 setTimeout ( ( ) => {
6277 vglobal . addEventListener ( 'click' , this . handleDocumentClick ) ;
@@ -390,6 +405,10 @@ export class MenuManager {
390405 clearTimeout ( this . hideTimeout ) ;
391406 this . hideTimeout = null ;
392407 }
408+ if ( this . showTimeout !== null ) {
409+ clearTimeout ( this . showTimeout ) ;
410+ this . showTimeout = null ;
411+ }
393412
394413 // 移除全局事件监听
395414 vglobal . removeEventListener ( 'click' , this . handleDocumentClick ) ;
0 commit comments