| | |
| | | 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', |
| | | () => { |
| | |
| | | } |
| | | 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 { |
| | |
| | | current.value = newTab |
| | | } else { |
| | | const existingTab = opened.value[existingIndex] |
| | | opened.value[existingIndex] = { |
| | | opened.value[existingIndex] = normalizeTabState({ |
| | | ...existingTab, |
| | | path: tab.path, |
| | | params: tab.params, |
| | |
| | | keepAlive: tab.keepAlive ?? existingTab.keepAlive, |
| | | name: tab.name || existingTab.name, |
| | | icon: tab.icon || existingTab.icon |
| | | } |
| | | }) |
| | | current.value = opened.value[existingIndex] |
| | | } |
| | | } |
| | |
| | | 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 = {} |
| | | } |