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({
name: '智能体扩展',
path: '/extensions?tab=skills',
path: '/extensions',
activePaths: ['/extensions'],
icon: LibraryBig,
activeIcon: LibraryBig

View File

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

View File

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