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>
42 lines
1.2 KiB
TypeScript
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 ...
|