Commit cad021c34b71fa109640af75a0c2b72179e9e257

Authored by 无木
1 parent 5ceeefd1

fix(menu): fix mix-menu incorrect jumping in `hover` mode

修复悬停触发模式下左侧混合菜单会在没有子菜单且被激活时直接跳转路由
CHANGELOG.zh_CN.md
@@ -8,12 +8,14 @@ @@ -8,12 +8,14 @@
8 - **TableAction** 仅在 action.tooltip 存在的情况下 才包裹 Tooltip 组件 8 - **TableAction** 仅在 action.tooltip 存在的情况下 才包裹 Tooltip 组件
9 - **BasicUpload** 修复处理非`array`值时报错的问题 9 - **BasicUpload** 修复处理非`array`值时报错的问题
10 - **Form** 修复`FormItem`的`suffix`插槽样式问题 10 - **Form** 修复`FormItem`的`suffix`插槽样式问题
  11 +- **Menu**
  12 + - 修复左侧混合菜单的悬停触发逻辑
  13 + - 修复顶栏菜单在显示包含需要隐藏的菜单项目时出错的问题
  14 + - 修复悬停触发模式下左侧混合菜单会在没有子菜单且被激活时直接跳转路由
11 - **其它** 15 - **其它**
12 - 修复菜单默认折叠的配置不起作用的问题 16 - 修复菜单默认折叠的配置不起作用的问题
13 - 修复`safari`浏览器报错导致网站打不开 17 - 修复`safari`浏览器报错导致网站打不开
14 - 修复在 window 上,拉取代码后 eslint 因 endOfLine 而保错问题 18 - 修复在 window 上,拉取代码后 eslint 因 endOfLine 而保错问题
15 - - 修复左侧混合菜单的悬停触发逻辑  
16 - - 修复顶栏菜单在显示包含需要隐藏的菜单项目时出错的问题  
17 19
18 ### 🎫 Chores 20 ### 🎫 Chores
19 21
src/layouts/default/sider/MixSider.vue
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
63 </div> 63 </div>
64 <ScrollContainer :class="`${prefixCls}-menu-list__content`"> 64 <ScrollContainer :class="`${prefixCls}-menu-list__content`">
65 <SimpleMenu 65 <SimpleMenu
66 - :items="chilrenMenus" 66 + :items="childrenMenus"
67 :theme="getMenuTheme" 67 :theme="getMenuTheme"
68 mixSider 68 mixSider
69 @menuClick="handleMenuClick" 69 @menuClick="handleMenuClick"
@@ -114,7 +114,7 @@ @@ -114,7 +114,7 @@
114 setup() { 114 setup() {
115 let menuModules = ref<Menu[]>([]); 115 let menuModules = ref<Menu[]>([]);
116 const activePath = ref(''); 116 const activePath = ref('');
117 - const chilrenMenus = ref<Menu[]>([]); 117 + const childrenMenus = ref<Menu[]>([]);
118 const openMenu = ref(false); 118 const openMenu = ref(false);
119 const dragBarRef = ref<ElRef>(null); 119 const dragBarRef = ref<ElRef>(null);
120 const sideRef = ref<ElRef>(null); 120 const sideRef = ref<ElRef>(null);
@@ -150,7 +150,7 @@ @@ -150,7 +150,7 @@
150 150
151 const getIsFixed = computed(() => { 151 const getIsFixed = computed(() => {
152 /* eslint-disable-next-line */ 152 /* eslint-disable-next-line */
153 - mixSideHasChildren.value = unref(chilrenMenus).length > 0; 153 + mixSideHasChildren.value = unref(childrenMenus).length > 0;
154 const isFixed = unref(getMixSideFixed) && unref(mixSideHasChildren); 154 const isFixed = unref(getMixSideFixed) && unref(mixSideHasChildren);
155 if (isFixed) { 155 if (isFixed) {
156 /* eslint-disable-next-line */ 156 /* eslint-disable-next-line */
@@ -209,9 +209,8 @@ @@ -209,9 +209,8 @@
209 } 209 }
210 210
211 // Process module menu click 211 // Process module menu click
212 - async function hanldeModuleClick(path: string, hover = false) { 212 + async function handleModuleClick(path: string, hover = false) {
213 const children = await getChildrenMenus(path); 213 const children = await getChildrenMenus(path);
214 -  
215 if (unref(activePath) === path) { 214 if (unref(activePath) === path) {
216 if (!hover) { 215 if (!hover) {
217 if (!unref(openMenu)) { 216 if (!unref(openMenu)) {
@@ -233,12 +232,12 @@ @@ -233,12 +232,12 @@
233 } 232 }
234 233
235 if (!children || children.length === 0) { 234 if (!children || children.length === 0) {
236 - go(path);  
237 - chilrenMenus.value = []; 235 + if (!hover) go(path);
  236 + childrenMenus.value = [];
238 closeMenu(); 237 closeMenu();
239 return; 238 return;
240 } 239 }
241 - chilrenMenus.value = children; 240 + childrenMenus.value = children;
242 } 241 }
243 242
244 // Set the currently active menu and submenu 243 // Set the currently active menu and submenu
@@ -253,14 +252,14 @@ @@ -253,14 +252,14 @@
253 if (p) { 252 if (p) {
254 const children = await getChildrenMenus(p); 253 const children = await getChildrenMenus(p);
255 if (setChildren) { 254 if (setChildren) {
256 - chilrenMenus.value = children; 255 + childrenMenus.value = children;
257 256
258 if (unref(getMixSideFixed)) { 257 if (unref(getMixSideFixed)) {
259 openMenu.value = children.length > 0; 258 openMenu.value = children.length > 0;
260 } 259 }
261 } 260 }
262 if (children.length === 0) { 261 if (children.length === 0) {
263 - chilrenMenus.value = []; 262 + childrenMenus.value = [];
264 } 263 }
265 } 264 }
266 } 265 }
@@ -278,11 +277,15 @@ @@ -278,11 +277,15 @@
278 function getItemEvents(item: Menu) { 277 function getItemEvents(item: Menu) {
279 if (unref(getMixSideTrigger) === 'hover') { 278 if (unref(getMixSideTrigger) === 'hover') {
280 return { 279 return {
281 - onMouseenter: () => hanldeModuleClick(item.path, true), 280 + onMouseenter: () => handleModuleClick(item.path, true),
  281 + onClick: async () => {
  282 + const children = await getChildrenMenus(item.path);
  283 + if (item.path && (!children || children.length === 0)) go(item.path);
  284 + },
282 }; 285 };
283 } 286 }
284 return { 287 return {
285 - onClick: () => hanldeModuleClick(item.path), 288 + onClick: () => handleModuleClick(item.path),
286 }; 289 };
287 } 290 }
288 291
@@ -303,9 +306,9 @@ @@ -303,9 +306,9 @@
303 t, 306 t,
304 prefixCls, 307 prefixCls,
305 menuModules, 308 menuModules,
306 - hanldeModuleClick, 309 + handleModuleClick: handleModuleClick,
307 activePath, 310 activePath,
308 - chilrenMenus, 311 + childrenMenus: childrenMenus,
309 getShowDragBar, 312 getShowDragBar,
310 handleMenuClick, 313 handleMenuClick,
311 getMenuStyle, 314 getMenuStyle,