Files
shanxia2.0/mobile-h5/src/utils/jump.ts
T
zlwuandCursor a4b13fa2bc chore(mobile-h5): add existing H5 app sources to the monorepo
Track the weighbridge mobile-h5 codebase (excluding node_modules, dist, and local .env) so subsequent adaptation tasks can evolve it in-repo.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-03 22:28:53 +08:00

42 lines
1.2 KiB
TypeScript

import { MenuListType } from '@/types/menu'
import { router } from '@/router'
// 打开外部链接
export const openExternalLink = (link: string) => {
window.open(link, '_blank')
}
/**
* 菜单跳转
* @param item 菜单项
* @param jumpToFirst 是否跳转到第一个子菜单
* @returns
*/
export const handleMenuJump = (item: MenuListType, jumpToFirst: boolean = false) => {
// 处理外部链接
const link = item.meta?.link || item.meta?.isLink
const isIframe = item.meta?.isIframe
if (link && !isIframe) {
return openExternalLink(link)
}
// 如果不需要跳转到第一个子菜单,或者没有子菜单,直接跳转当前路径
if (!jumpToFirst || !item.children?.length) {
return router.push(item.path)
}
// 获取第一个可见的子菜单,如果没有则取第一个子菜单
const firstChild = item.children.find((child: MenuListType) => !child.meta?.isHide) || item.children[0]
// 如果第一个子菜单是外部链接则打开新窗口
const childLink = firstChild.meta?.link || firstChild.meta?.isLink
if (childLink) {
return openExternalLink(childLink)
}
// 跳转到子菜单路径
router.push(firstChild.path)
}
// ... existing code ...