| | |
| | | import { useCommon } from '@/hooks/core/useCommon' |
| | | import { normalizeIcon } from '@/router/adapters/backendMenuAdapter.js' |
| | | |
| | | function normalizeLegacyTabPath(path) { |
| | | if (path === '/dashboard') { |
| | | return '/dashboard/console' |
| | | } |
| | | |
| | | return path |
| | | } |
| | | |
| | | const normalizeTabState = (tab) => { |
| | | if (!tab || typeof tab !== 'object') { |
| | | return tab |
| | |
| | | |
| | | return { |
| | | ...tab, |
| | | path: normalizeLegacyTabPath(tab.path), |
| | | icon: normalizeIcon(tab.icon) |
| | | } |
| | | } |
| | |
| | | const hasOpenedTabs = computed(() => opened.value.length > 0) |
| | | const hasMultipleTabs = computed(() => opened.value.length > 1) |
| | | const currentTabIndex = computed(() => |
| | | current.value.path ? opened.value.findIndex((tab) => tab.path === current.value.path) : -1 |
| | | current.value.path |
| | | ? opened.value.findIndex((tab) => tab.path === normalizeLegacyTabPath(current.value.path)) |
| | | : -1 |
| | | ) |
| | | const findTabIndex = (path) => { |
| | | return opened.value.findIndex((tab) => tab.path === path) |
| | | const resolvedPath = normalizeLegacyTabPath(path) |
| | | return opened.value.findIndex((tab) => tab.path === resolvedPath) |
| | | } |
| | | const getTab = (path) => { |
| | | return opened.value.find((tab) => tab.path === path) |
| | | const resolvedPath = normalizeLegacyTabPath(path) |
| | | return opened.value.find((tab) => tab.path === resolvedPath) |
| | | } |
| | | const isTabClosable = (tab) => { |
| | | return !tab.fixedTab |
| | | } |
| | | const safeRouterPush = (tab) => { |
| | | if (!tab.path) { |
| | | const resolvedPath = normalizeLegacyTabPath(tab.path) |
| | | if (!resolvedPath) { |
| | | console.warn('尝试跳转到无效路径的标签页') |
| | | return |
| | | } |
| | | try { |
| | | router.push({ |
| | | path: tab.path, |
| | | path: resolvedPath, |
| | | query: tab.query |
| | | }) |
| | | } catch (error) { |
| | |
| | | } |
| | | } |
| | | const openTab = (tab) => { |
| | | if (!tab.path) { |
| | | const resolvedPath = normalizeLegacyTabPath(tab.path) |
| | | if (!resolvedPath) { |
| | | console.warn('尝试打开无效的标签页') |
| | | return |
| | | } |
| | |
| | | existingIndex = opened.value.findIndex((t) => t.name === tab.name) |
| | | } |
| | | if (existingIndex === -1) { |
| | | existingIndex = findTabIndex(tab.path) |
| | | existingIndex = findTabIndex(resolvedPath) |
| | | } |
| | | if (existingIndex === -1) { |
| | | const insertIndex = tab.fixedTab ? findFixedTabInsertIndex() : opened.value.length |
| | | const newTab = normalizeTabState(tab) |
| | | const newTab = normalizeTabState({ |
| | | ...tab, |
| | | path: resolvedPath |
| | | }) |
| | | if (tab.fixedTab) { |
| | | opened.value.splice(insertIndex, 0, newTab) |
| | | } else { |
| | |
| | | const existingTab = opened.value[existingIndex] |
| | | opened.value[existingIndex] = normalizeTabState({ |
| | | ...existingTab, |
| | | path: tab.path, |
| | | path: resolvedPath, |
| | | params: tab.params, |
| | | query: tab.query, |
| | | title: tab.title || existingTab.title, |
| | |
| | | if (routes.some((r) => r.name === tab.name)) return true |
| | | } |
| | | if (tab.path) { |
| | | const resolvedPath = normalizeLegacyTabPath(tab.path) |
| | | const resolved = routerInstance.resolve({ |
| | | path: tab.path, |
| | | path: resolvedPath, |
| | | query: tab.query || void 0 |
| | | }) |
| | | return resolved.matched.length > 0 |