Commit bcfa33822736b761757a2673d977f752cb5c4f7c
1 parent
b1f31762
feat: add `updatePath` for `useTabs`
添加更新标签path的方法 close: #1068
Showing
2 changed files
with
22 additions
and
3 deletions
src/hooks/web/useTabs.ts
@@ -46,6 +46,15 @@ export function useTabs(_router?: Router) { | @@ -46,6 +46,15 @@ export function useTabs(_router?: Router) { | ||
46 | await tabStore.setTabTitle(title, targetTab); | 46 | await tabStore.setTabTitle(title, targetTab); |
47 | } | 47 | } |
48 | 48 | ||
49 | + async function updateTabPath(path: string, tab?: RouteLocationNormalized) { | ||
50 | + const canIUse = canIUseTabs; | ||
51 | + if (!canIUse) { | ||
52 | + return; | ||
53 | + } | ||
54 | + const targetTab = tab || getCurrentTab(); | ||
55 | + await tabStore.updateTabPath(path, targetTab); | ||
56 | + } | ||
57 | + | ||
49 | async function handleTabAction(action: TableActionEnum, tab?: RouteLocationNormalized) { | 58 | async function handleTabAction(action: TableActionEnum, tab?: RouteLocationNormalized) { |
50 | const canIUse = canIUseTabs; | 59 | const canIUse = canIUseTabs; |
51 | if (!canIUse) { | 60 | if (!canIUse) { |
@@ -87,9 +96,8 @@ export function useTabs(_router?: Router) { | @@ -87,9 +96,8 @@ export function useTabs(_router?: Router) { | ||
87 | closeRight: () => handleTabAction(TableActionEnum.CLOSE_RIGHT), | 96 | closeRight: () => handleTabAction(TableActionEnum.CLOSE_RIGHT), |
88 | closeOther: () => handleTabAction(TableActionEnum.CLOSE_OTHER), | 97 | closeOther: () => handleTabAction(TableActionEnum.CLOSE_OTHER), |
89 | closeCurrent: () => handleTabAction(TableActionEnum.CLOSE_CURRENT), | 98 | closeCurrent: () => handleTabAction(TableActionEnum.CLOSE_CURRENT), |
90 | - close: (tab?: RouteLocationNormalized) => { | ||
91 | - handleTabAction(TableActionEnum.CLOSE, tab); | ||
92 | - }, | 99 | + close: (tab?: RouteLocationNormalized) => handleTabAction(TableActionEnum.CLOSE, tab), |
93 | setTitle: (title: string, tab?: RouteLocationNormalized) => updateTabTitle(title, tab), | 100 | setTitle: (title: string, tab?: RouteLocationNormalized) => updateTabTitle(title, tab), |
101 | + updatePath: (fullPath: string, tab?: RouteLocationNormalized) => updateTabPath(fullPath, tab), | ||
94 | }; | 102 | }; |
95 | } | 103 | } |
src/store/modules/multipleTab.ts
@@ -300,6 +300,17 @@ export const useMultipleTabStore = defineStore({ | @@ -300,6 +300,17 @@ export const useMultipleTabStore = defineStore({ | ||
300 | await this.updateCacheTab(); | 300 | await this.updateCacheTab(); |
301 | } | 301 | } |
302 | }, | 302 | }, |
303 | + /** | ||
304 | + * replace tab's path | ||
305 | + * **/ | ||
306 | + async updateTabPath(fullPath: string, route: RouteLocationNormalized) { | ||
307 | + const findTab = this.getTabList.find((item) => item === route); | ||
308 | + if (findTab) { | ||
309 | + findTab.fullPath = fullPath; | ||
310 | + findTab.path = fullPath; | ||
311 | + await this.updateCacheTab(); | ||
312 | + } | ||
313 | + }, | ||
303 | }, | 314 | }, |
304 | }); | 315 | }); |
305 | 316 |