Skip to content

Commit

Permalink
feat: add updatePath for useTabs
Browse files Browse the repository at this point in the history
添加更新标签path的方法

close: #1068
  • Loading branch information
mynetfan committed Aug 13, 2021
1 parent b1f3176 commit bcfa338
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/hooks/web/useTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export function useTabs(_router?: Router) {
await tabStore.setTabTitle(title, targetTab);
}

async function updateTabPath(path: string, tab?: RouteLocationNormalized) {
const canIUse = canIUseTabs;
if (!canIUse) {
return;
}
const targetTab = tab || getCurrentTab();
await tabStore.updateTabPath(path, targetTab);
}

async function handleTabAction(action: TableActionEnum, tab?: RouteLocationNormalized) {
const canIUse = canIUseTabs;
if (!canIUse) {
Expand Down Expand Up @@ -87,9 +96,8 @@ export function useTabs(_router?: Router) {
closeRight: () => handleTabAction(TableActionEnum.CLOSE_RIGHT),
closeOther: () => handleTabAction(TableActionEnum.CLOSE_OTHER),
closeCurrent: () => handleTabAction(TableActionEnum.CLOSE_CURRENT),
close: (tab?: RouteLocationNormalized) => {
handleTabAction(TableActionEnum.CLOSE, tab);
},
close: (tab?: RouteLocationNormalized) => handleTabAction(TableActionEnum.CLOSE, tab),
setTitle: (title: string, tab?: RouteLocationNormalized) => updateTabTitle(title, tab),
updatePath: (fullPath: string, tab?: RouteLocationNormalized) => updateTabPath(fullPath, tab),
};
}
11 changes: 11 additions & 0 deletions src/store/modules/multipleTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ export const useMultipleTabStore = defineStore({
await this.updateCacheTab();
}
},
/**
* replace tab's path
* **/
async updateTabPath(fullPath: string, route: RouteLocationNormalized) {
const findTab = this.getTabList.find((item) => item === route);
if (findTab) {
findTab.fullPath = fullPath;
findTab.path = fullPath;
await this.updateCacheTab();
}
},
},
});

Expand Down

0 comments on commit bcfa338

Please sign in to comment.