From b24e2f889d681efea086eec4da7a42588a724bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=82=85=E5=AD=90=E6=B9=98?= Date: Sun, 9 Oct 2022 15:35:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=B7=E6=96=B0=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8tab=E6=A0=87=E7=AD=BE=E6=A0=8F=E6=B6=88?= =?UTF-8?q?=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/composable/useTab.ts | 28 +++++++++++++++++++++++++--- src/router/module/base-routes.ts | 8 ++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/layouts/composable/useTab.ts b/src/layouts/composable/useTab.ts index 5bc4b10..63e33df 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 b2557df..b45450a 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 +] -- Gitee