Files
2026-01-27 20:02:57 +08:00

34 lines
978 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { TabItem, MenuItem } from '../types.uts'
export function makeTabFromPath(menuList: MenuItem[], path: string): TabItem {
// path 可能带 query用于 tab 的 id 也要稳定
const pure = path.split('?')[0]
// 先找子页面
for (const m of menuList) {
const groups = m.groups || []
for (const g of groups) {
for (const c of g.children) {
if (c.path.split('?')[0] === pure) {
return { id: c.id, title: c.title, path: c.path }
}
}
}
if (m.path.split('?')[0] === pure) {
return { id: m.id, title: m.title, path: m.path }
}
}
// 找不到就兜底
return { id: pure, title: '页面', path }
}
export function upsertTab(tabs: TabItem[], tab: TabItem): TabItem[] {
const idx = tabs.findIndex(t => t.id === tab.id)
if (idx >= 0) return tabs
return [...tabs, tab]
}
export function removeTab(tabs: TabItem[], tabId: string): TabItem[] {
return tabs.filter(t => t.id !== tabId)
}