@@ -116,6 +116,14 @@ export default defineComponent({
116116 if ( loopInPopup ( related ) ) return ;
117117 handleMouseLeavePopup ( e ) ;
118118 } ,
119+ keepParentPopupVisible : ( ) => {
120+ // 保持当前 popup 显示,同时递归通知父级
121+ isCursorInPopup . value = true ;
122+ popupVisible . value = true ;
123+ if ( submenu ?. keepParentPopupVisible ) {
124+ submenu . keepParentPopupVisible ( ) ;
125+ }
126+ } ,
119127 } ) ;
120128
121129 const passSubPopupRefToParent = ( val : HTMLElement ) => {
@@ -136,13 +144,8 @@ export default defineComponent({
136144 // 如果父 popup 可见,还需要检查鼠标是否真的在父 popup 内
137145 // 避免父 popup 延迟关闭时,鼠标已经移出但子菜单仍被触发
138146 if ( e && subPopupRef . value ) {
139- const parentPopupRect = subPopupRef . value . getBoundingClientRect ( ) ;
140- const { clientX, clientY } = e ;
141- const isInParentPopup =
142- clientX >= parentPopupRect . left &&
143- clientX <= parentPopupRect . right &&
144- clientY >= parentPopupRect . top &&
145- clientY <= parentPopupRect . bottom ;
147+ const elementAtCursor = document . elementFromPoint ( e . clientX , e . clientY ) ;
148+ const isInParentPopup = elementAtCursor && subPopupRef . value . contains ( elementAtCursor ) ;
146149
147150 if ( ! isInParentPopup ) {
148151 return ;
@@ -199,6 +202,10 @@ export default defineComponent({
199202 } ;
200203 const handleEnterPopup = ( ) => {
201204 isCursorInPopup . value = true ;
205+ // 当鼠标进入子 popup 时,通知所有父级 popup 保持显示状态,防止父级延迟关闭
206+ if ( submenu ?. keepParentPopupVisible ) {
207+ submenu . keepParentPopupVisible ( ) ;
208+ }
202209 } ;
203210
204211 const handleSubmenuItemClick = ( ) => {
0 commit comments