fix: 修正扩展页默认打开标签

This commit is contained in:
Wenjie Zhang 2026-06-03 20:10:55 +08:00
parent 1842c8da85
commit f54abbd631
3 changed files with 18 additions and 11 deletions

View File

@ -137,7 +137,7 @@ const mainList = computed(() => {
items.push({ items.push({
name: '智能体扩展', name: '智能体扩展',
path: '/extensions?tab=skills', path: '/extensions',
activePaths: ['/extensions'], activePaths: ['/extensions'],
icon: LibraryBig, icon: LibraryBig,
activeIcon: LibraryBig activeIcon: LibraryBig

View File

@ -137,11 +137,6 @@ const router = createRouter({
} }
] ]
}, },
{
path: '/skills',
name: 'skills',
redirect: '/extensions?tab=skills'
},
{ {
path: '/:pathMatch(.*)*', path: '/:pathMatch(.*)*',
name: 'NotFound', name: 'NotFound',

View File

@ -42,7 +42,7 @@ import { useUserStore } from '@/stores/user'
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
const userStore = useUserStore() const userStore = useUserStore()
const activeTab = ref('skills') const activeTab = ref(null)
const knowledgeRef = ref(null) const knowledgeRef = ref(null)
const skillsRef = ref(null) const skillsRef = ref(null)
const mcpRef = ref(null) const mcpRef = ref(null)
@ -57,10 +57,21 @@ const adminExtensionTabs = [
const userExtensionTabs = [{ key: 'skills', label: 'Skills' }] const userExtensionTabs = [{ key: 'skills', label: 'Skills' }]
const extensionTabs = computed(() => (userStore.isAdmin ? adminExtensionTabs : userExtensionTabs)) const extensionTabs = computed(() => (userStore.isAdmin ? adminExtensionTabs : userExtensionTabs))
const allowedTabKeys = computed(() => extensionTabs.value.map((tab) => tab.key)) const allowedTabKeys = computed(() => extensionTabs.value.map((tab) => tab.key))
const defaultTabKey = computed(() => extensionTabs.value[0]?.key || 'skills')
const normalizeTab = (tab) => { const normalizeTab = (tab) => {
if (allowedTabKeys.value.includes(tab)) return tab if (allowedTabKeys.value.includes(tab)) return tab
return userStore.isAdmin ? 'knowledge' : 'skills' return defaultTabKey.value
}
const replaceTabQuery = (tab) => {
const query = { ...route.query }
if (tab === defaultTabKey.value) {
delete query.tab
} else {
query.tab = tab
}
router.replace({ query })
} }
const isDetailPage = computed(() => { const isDetailPage = computed(() => {
@ -87,19 +98,20 @@ watch(
([tab]) => { ([tab]) => {
const nextTab = normalizeTab(tab) const nextTab = normalizeTab(tab)
if (activeTab.value !== nextTab) activeTab.value = nextTab if (activeTab.value !== nextTab) activeTab.value = nextTab
if (route.query.tab !== nextTab) router.replace({ query: { ...route.query, tab: nextTab } }) if (tab && tab !== nextTab) replaceTabQuery(nextTab)
}, },
{ immediate: true } { immediate: true }
) )
watch(activeTab, (tab) => { watch(activeTab, (tab) => {
if (!tab) return
const nextTab = normalizeTab(tab) const nextTab = normalizeTab(tab)
if (nextTab !== tab) { if (nextTab !== tab) {
activeTab.value = nextTab activeTab.value = nextTab
return return
} }
if (route.query.tab === nextTab) return if (route.query.tab === nextTab || (!route.query.tab && nextTab === defaultTabKey.value)) return
router.replace({ query: { ...route.query, tab: nextTab } }) replaceTabQuery(nextTab)
}) })
</script> </script>