diff --git a/src/layouts/composable/useTab.ts b/src/layouts/composable/useTab.ts index 5bc4b103827ee287b03dd1c7d75546504d058a3b..63e33df2765a3fade22b59ef3800ae964f49cad1 100644 --- a/src/layouts/composable/useTab.ts +++ b/src/layouts/composable/useTab.ts @@ -4,10 +4,32 @@ import { useRoute, useRouter } from "vue-router"; export function useTab() { const route = useRoute(); const router = useRouter(); + const routes = router.getRoutes() const currentPath = computed(() => route.path); - const tabs: Ref = ref([ - { title: "工作台", id: "/workspace/workbench", closable: false }, - ]); + + const tabs: Ref = ref([]); + const tabsCache: string[] = [] + // 从路由筛出自定义tab + if (routes) { + routes.forEach(route => { + if (route.meta && route.meta.affix) { + tabs.value.push({ + ...route.meta, + id: route.path, + }) + tabsCache.push(route.path) + } + }) + } + + // 刷新后tabs保留最后一个页面 + if (route.path && !tabsCache.includes(route.path)) { + const path = routes.find(item => item.path === route.path) + path && tabs.value.push({ + ...path.meta, + id: route.path, + }) + } const to = (id: string) => { router.push(id); diff --git a/src/router/module/base-routes.ts b/src/router/module/base-routes.ts index b2557dfc084f7dce2e5f49b89e3be331b6d9fd42..b45450a8c92f8ff610198d7cc9b2655b13babd2d 100644 --- a/src/router/module/base-routes.ts +++ b/src/router/module/base-routes.ts @@ -2,7 +2,7 @@ import BaseLayout from '../../layouts/BaseLayout.vue'; import Login from '../../views/login/index.vue'; -export default [ +export default [ { path: '/', redirect: '/workSpace' @@ -21,7 +21,7 @@ export default [ { path: '/workspace/workbench', component: () => import('../../views/workSpace/workbench/index.vue'), - meta: { title: '工作台', requireAuth: true }, + meta: { title: '工作台', requireAuth: true, affix: true, closable: false }, }, { path: '/workspace/console', @@ -122,7 +122,7 @@ export default [ path: '/form/base', component: () => import('../../views/form/base.vue'), meta: { title: '基础表单', requireAuth: true }, - }, + }, { path: '/form/step', component: () => import('../../views/form/step.vue'), @@ -146,4 +146,4 @@ export default [ }, ] } -] \ No newline at end of file +]