From 3b3fb80231f74eecfe2e98e9a7968bfc405bc37f Mon Sep 17 00:00:00 2001 From: LiuHao <liuhaoai545@gmail.com> Date: 星期日, 18 六月 2023 23:47:10 +0800 Subject: [PATCH] add 新增路由跳转自定义title --- src/store/modules/tagsView.ts | 1 + src/plugins/tab.ts | 18 ++++++++++++------ src/layout/components/TagsView/index.vue | 3 +++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/layout/components/TagsView/index.vue b/src/layout/components/TagsView/index.vue index e65df65..8998ca1 100644 --- a/src/layout/components/TagsView/index.vue +++ b/src/layout/components/TagsView/index.vue @@ -125,6 +125,9 @@ } const addTags = () => { const { name } = route; + if(route.query.title) { + route.meta.title = route.query.title; + } if (name) { useTagsViewStore().addView(route); if (route.meta.link) { diff --git a/src/plugins/tab.ts b/src/plugins/tab.ts index a310154..1c0ab7a 100644 --- a/src/plugins/tab.ts +++ b/src/plugins/tab.ts @@ -17,7 +17,7 @@ } // prettier-ignore await useTagsViewStore().delCachedView(obj) - router.replace({ + await router.replace({ path: '/redirect' + obj.path, query: obj.query }); @@ -34,9 +34,9 @@ if (obj === undefined) { // prettier-ignore const { visitedViews } = await useTagsViewStore().delView(router.currentRoute.value) as any - const latestView = visitedViews.slice(-1)[0] + const latestView = visitedViews.slice(-1)[0]; if (latestView) { - return router.push(latestView.fullPath) + return router.push(latestView.fullPath); } return router.push('/'); } @@ -58,9 +58,15 @@ closeOtherPage(obj: TagView) { return useTagsViewStore().delOthersViews(obj || router.currentRoute.value); }, - // 鎵撳紑tab椤电 - openPage(url: RouteLocationRaw) { - return router.push(url); + /** + * 鎵撳紑tab椤电 + * @param url 璺敱鍦板潃 + * @param title 鏍囬 + * @param query 鍙傛暟 + */ + openPage(url: string, title?: string, query?: any) { + const obj = { path: url, query: { ...query, title } }; + return router.push(obj); }, // 淇敼tab椤电 updatePage(obj: TagView) { diff --git a/src/store/modules/tagsView.ts b/src/store/modules/tagsView.ts index af980ef..064e4ee 100644 --- a/src/store/modules/tagsView.ts +++ b/src/store/modules/tagsView.ts @@ -167,6 +167,7 @@ const addCachedView = (view: TagView): void => { const viewName = view.name as string; + if (!viewName) return; if (cachedViews.value.includes(viewName)) return; if (!view.meta?.noCache) { cachedViews.value.push(viewName); -- Gitblit v1.9.3