| | |
| | | if (e.target.closest('.el-sub-menu__title')) { |
| | | // 按照正确的路径构建层级 |
| | | let currentNode = props.item; |
| | | let pathSegments = []; |
| | | |
| | | // 首先添加当前节点的路径 |
| | | if (currentNode.path) { |
| | | pathSegments.push(currentNode.path); |
| | | console.log('当前点击的菜单项:', JSON.stringify(currentNode, null, 2)); |
| | | console.log('basePath:', props.basePath); |
| | | |
| | | // 获取第一个可见子菜单,如果没有可见子菜单,不进行跳转 |
| | | if (!currentNode.children || currentNode.children.length === 0) { |
| | | return; |
| | | } |
| | | |
| | | // 逐层添加子路径 |
| | | while (currentNode.children && currentNode.children.length > 0) { |
| | | const firstChild = currentNode.children.find(child => !child.hidden); |
| | | if (!firstChild) break; |
| | | |
| | | // 跳过ParentView类型的中间节点 |
| | | if (firstChild.component === 'ParentView' || firstChild.component.name === 'ParentView') { |
| | | currentNode = firstChild; |
| | | pathSegments.push(firstChild.path); |
| | | continue; |
| | | } |
| | | |
| | | // 普通节点处理 |
| | | currentNode = firstChild; |
| | | // 如果路径不是以/开头,则添加到路径片段中 |
| | | if (!firstChild.path.startsWith('/')) { |
| | | pathSegments.push(firstChild.path); |
| | | } else { |
| | | // 如果是绝对路径,则替换之前所有路径 |
| | | pathSegments = [firstChild.path]; |
| | | } |
| | | |
| | | // 如果到达叶子节点,则结束查找 |
| | | if (!firstChild.children || firstChild.children.length === 0) { |
| | | break; |
| | | } |
| | | const firstVisibleChild = currentNode.children.find(child => !child.hidden); |
| | | if (!firstVisibleChild) { |
| | | return; |
| | | } |
| | | |
| | | // 构建最终路径 |
| | | if (pathSegments.length > 0) { |
| | | // 如果第一段不是以/开头,添加/ |
| | | if (!pathSegments[0].startsWith('/')) { |
| | | pathSegments[0] = '/' + pathSegments[0]; |
| | | } |
| | | console.log('第一个可见子菜单:', JSON.stringify(firstVisibleChild, null, 2)); |
| | | |
| | | // 日志管理等三级菜单特殊处理 |
| | | // 检查是否有预先写入的完整路径,如果有则直接使用 |
| | | if (firstVisibleChild.fullPath) { |
| | | console.log('使用预先设置的完整路径:', firstVisibleChild.fullPath); |
| | | router.push({ path: firstVisibleChild.fullPath }); |
| | | return; |
| | | } |
| | | |
| | | // 判断是否是系统/日志管理类型的三级菜单(例如,/system/log/operlog) |
| | | // 这种情况下,直接跳转到第一个子菜单的完整路径 |
| | | if (firstVisibleChild.component === 'ParentView' || |
| | | (typeof firstVisibleChild.component === 'object' && |
| | | firstVisibleChild.component.name === 'ParentView')) { |
| | | console.log('检测到ParentView组件,处理三级菜单'); |
| | | |
| | | // 组合路径 |
| | | const targetPath = pathSegments.reduce((fullPath, segment, index) => { |
| | | if (segment.startsWith('/')) { |
| | | return segment; |
| | | } else if (index === 0) { |
| | | return segment; |
| | | } else { |
| | | return `${fullPath}/${segment}`; |
| | | // 是有三级菜单的情况 |
| | | if (firstVisibleChild.children && firstVisibleChild.children.length > 0) { |
| | | const grandChild = firstVisibleChild.children.find(child => !child.hidden); |
| | | if (grandChild) { |
| | | console.log('找到第三级菜单:', JSON.stringify(grandChild, null, 2)); |
| | | |
| | | // 判断是否应该使用parentPath |
| | | if (firstVisibleChild.parentPath && grandChild.path.startsWith('/')) { |
| | | console.log('使用parentPath属性:', firstVisibleChild.parentPath); |
| | | // 如果子菜单是绝对路径,但有parentPath,则应该使用parentPath作为基础 |
| | | let fullPath = firstVisibleChild.parentPath; |
| | | if (!fullPath.startsWith('/')) { |
| | | fullPath = '/' + fullPath; |
| | | } |
| | | |
| | | // 第二级路径基于根路径 |
| | | if (firstVisibleChild.path.startsWith('/')) { |
| | | // 第二级已经是绝对路径,截取最后部分 |
| | | const pathParts = firstVisibleChild.path.split('/'); |
| | | const lastPart = pathParts[pathParts.length - 1]; |
| | | fullPath = fullPath + '/' + lastPart; |
| | | } else { |
| | | fullPath = buildFullPath(fullPath, firstVisibleChild.path); |
| | | } |
| | | console.log('二级路径:', fullPath); |
| | | |
| | | // 第三级路径基于二级路径 |
| | | if (grandChild.path.startsWith('/')) { |
| | | // 第三级是绝对路径,截取最后部分 |
| | | const pathParts = grandChild.path.split('/'); |
| | | const lastPart = pathParts[pathParts.length - 1]; |
| | | fullPath = fullPath + '/' + lastPart; |
| | | } else { |
| | | fullPath = buildFullPath(fullPath, grandChild.path); |
| | | } |
| | | console.log('三级路径 (最终):', fullPath); |
| | | |
| | | // 导航到第三级菜单 |
| | | if (grandChild.query) { |
| | | router.push({ path: fullPath, query: grandChild.query }); |
| | | } else { |
| | | router.push({ path: fullPath }); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | // 常规路径构建 |
| | | let fullPath; |
| | | |
| | | // 第一级路径必须是完整的(例如/system) |
| | | if (currentNode.path.startsWith('/')) { |
| | | fullPath = currentNode.path; |
| | | } else { |
| | | fullPath = '/' + currentNode.path; |
| | | } |
| | | console.log('一级路径:', fullPath); |
| | | |
| | | // 第二级路径必须基于第一级路径(例如/system/log) |
| | | fullPath = buildFullPath(fullPath, firstVisibleChild.path); |
| | | console.log('二级路径:', fullPath); |
| | | |
| | | // 第三级路径必须基于二级路径(例如/system/log/operlog) |
| | | fullPath = buildFullPath(fullPath, grandChild.path); |
| | | console.log('三级路径 (最终):', fullPath); |
| | | |
| | | // 导航到第三级菜单 |
| | | if (grandChild.query) { |
| | | console.log('跳转到:', fullPath, '带参数:', grandChild.query); |
| | | router.push({ path: fullPath, query: grandChild.query }); |
| | | } else { |
| | | console.log('跳转到:', fullPath); |
| | | router.push({ path: fullPath }); |
| | | } |
| | | return; |
| | | } |
| | | }); |
| | | |
| | | // 导航到目标路由,如果有查询参数则添加 |
| | | if (currentNode.query) { |
| | | router.push({ path: targetPath, query: currentNode.query }); |
| | | } else { |
| | | router.push({ path: targetPath }); |
| | | } |
| | | } |
| | | |
| | | console.log('处理标准二级菜单'); |
| | | |
| | | // 检查是否需要使用parentPath |
| | | if (firstVisibleChild.parentPath && firstVisibleChild.path.startsWith('/')) { |
| | | console.log('使用parentPath属性:', firstVisibleChild.parentPath); |
| | | // 如果子菜单是绝对路径,但有parentPath,则应该使用parentPath作为基础 |
| | | let fullPath = firstVisibleChild.parentPath; |
| | | if (!fullPath.startsWith('/')) { |
| | | fullPath = '/' + fullPath; |
| | | } |
| | | |
| | | // 构建完整路径 |
| | | if (firstVisibleChild.path.startsWith('/')) { |
| | | // 截取子路径的最后部分 |
| | | const pathParts = firstVisibleChild.path.split('/'); |
| | | const lastPart = pathParts[pathParts.length - 1]; |
| | | fullPath = fullPath + '/' + lastPart; |
| | | } else { |
| | | fullPath = buildFullPath(fullPath, firstVisibleChild.path); |
| | | } |
| | | console.log('构建的最终路径:', fullPath); |
| | | |
| | | // 导航到目标路由 |
| | | if (firstVisibleChild.query) { |
| | | router.push({ path: fullPath, query: firstVisibleChild.query }); |
| | | } else { |
| | | router.push({ path: fullPath }); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | // 标准的二级菜单处理 |
| | | // 构建正确的路径 |
| | | let fullPath; |
| | | |
| | | // 处理第一级路径(例如/system)- 必须是完整的路径 |
| | | if (currentNode.path.startsWith('/')) { |
| | | fullPath = currentNode.path; |
| | | } else { |
| | | fullPath = '/' + currentNode.path; |
| | | } |
| | | console.log('一级路径:', fullPath); |
| | | |
| | | // 处理第二级路径(例如/system/user)- 必须基于第一级路径 |
| | | fullPath = buildFullPath(fullPath, firstVisibleChild.path); |
| | | console.log('二级路径 (最终):', fullPath); |
| | | |
| | | // 导航到目标路由 |
| | | if (firstVisibleChild.query) { |
| | | console.log('跳转到:', fullPath, '带参数:', firstVisibleChild.query); |
| | | router.push({ path: fullPath, query: firstVisibleChild.query }); |
| | | } else { |
| | | console.log('跳转到:', fullPath); |
| | | router.push({ path: fullPath }); |
| | | } |
| | | } |
| | | } |
| | |
| | | return getNormalPath(props.basePath + '/' + routePath) |
| | | } |
| | | |
| | | // 正确构建路径 |
| | | function buildFullPath(base, segment) { |
| | | // 如果segment是绝对路径,直接返回 |
| | | if (segment.startsWith('/')) { |
| | | return segment; |
| | | } |
| | | |
| | | // 确保base有正确的开头斜杠 |
| | | const normalizedBase = base.startsWith('/') ? base : '/' + base; |
| | | |
| | | // 拼接路径,避免双斜杠 |
| | | return normalizedBase.endsWith('/') ? normalizedBase + segment : normalizedBase + '/' + segment; |
| | | } |
| | | |
| | | function hasTitle(title){ |
| | | if (title.length > 5) { |
| | | return title; |