zhou zhou
2 天以前 aaf8a50511d77dbc209ca93bbba308c21179a8bc
rsf-design/src/store/modules/worktab.js
@@ -4,6 +4,14 @@
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
@@ -11,6 +19,7 @@
  return {
    ...tab,
    path: normalizeLegacyTabPath(tab.path),
    icon: normalizeIcon(tab.icon)
  }
}
@@ -24,25 +33,30 @@
    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) {
@@ -50,7 +64,8 @@
      }
    }
    const openTab = (tab) => {
      if (!tab.path) {
      const resolvedPath = normalizeLegacyTabPath(tab.path)
      if (!resolvedPath) {
        console.warn('尝试打开无效的标签页')
        return
      }
@@ -62,11 +77,14 @@
        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 {
@@ -77,7 +95,7 @@
        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,
@@ -259,8 +277,9 @@
              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