Commit bcfa33822736b761757a2673d977f752cb5c4f7c

Authored by 无木
1 parent b1f31762

feat: add `updatePath` for `useTabs`

添加更新标签path的方法

close: #1068
src/hooks/web/useTabs.ts
... ... @@ -46,6 +46,15 @@ export function useTabs(_router?: Router) {
46 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 58 async function handleTabAction(action: TableActionEnum, tab?: RouteLocationNormalized) {
50 59 const canIUse = canIUseTabs;
51 60 if (!canIUse) {
... ... @@ -87,9 +96,8 @@ export function useTabs(_router?: Router) {
87 96 closeRight: () => handleTabAction(TableActionEnum.CLOSE_RIGHT),
88 97 closeOther: () => handleTabAction(TableActionEnum.CLOSE_OTHER),
89 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 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 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  
... ...