zhou zhou
16 小时以前 40905cbd04c2e332cd4bc2b9e0c5b3e1da9cccfa
rsf-design/src/store/modules/worktab.js
@@ -2,6 +2,19 @@
import { ref, computed } from 'vue'
import { router } from '@/router'
import { useCommon } from '@/hooks/core/useCommon'
import { normalizeIcon } from '@/router/adapters/backendMenuAdapter.js'
const normalizeTabState = (tab) => {
  if (!tab || typeof tab !== 'object') {
    return tab
  }
  return {
    ...tab,
    icon: normalizeIcon(tab.icon)
  }
}
const useWorktabStore = defineStore(
  'worktabStore',
  () => {
@@ -53,7 +66,7 @@
      }
      if (existingIndex === -1) {
        const insertIndex = tab.fixedTab ? findFixedTabInsertIndex() : opened.value.length
        const newTab = { ...tab }
        const newTab = normalizeTabState(tab)
        if (tab.fixedTab) {
          opened.value.splice(insertIndex, 0, newTab)
        } else {
@@ -62,7 +75,7 @@
        current.value = newTab
      } else {
        const existingTab = opened.value[existingIndex]
        opened.value[existingIndex] = {
        opened.value[existingIndex] = normalizeTabState({
          ...existingTab,
          path: tab.path,
          params: tab.params,
@@ -72,7 +85,7 @@
          keepAlive: tab.keepAlive ?? existingTab.keepAlive,
          name: tab.name || existingTab.name,
          icon: tab.icon || existingTab.icon
        }
        })
        current.value = opened.value[existingIndex]
      }
    }
@@ -257,15 +270,22 @@
            return false
          }
        }
        const validTabs = opened.value.filter((tab) => isTabRouteValid(tab))
        const validTabs = opened.value.filter((tab) => isTabRouteValid(tab)).map(normalizeTabState)
        if (validTabs.length !== opened.value.length) {
          console.warn('发现无效的标签页路由,已自动清理')
        }
        if (
          validTabs.length !== opened.value.length ||
          validTabs.some((tab, index) => tab.icon !== opened.value[index]?.icon)
        ) {
          opened.value = validTabs
        }
        const isCurrentValid = current.value && isTabRouteValid(current.value)
        if (!isCurrentValid && validTabs.length > 0) {
          console.warn('当前激活标签无效,已自动切换')
          current.value = validTabs[0]
        } else if (isCurrentValid) {
          current.value = normalizeTabState(current.value)
        } else if (!isCurrentValid) {
          current.value = {}
        }