提交 bcfa3382 编写于 作者: 无木

feat: add `updatePath` for `useTabs`

添加更新标签path的方法

close: #1068
上级 b1f31762
...@@ -46,6 +46,15 @@ export function useTabs(_router?: Router) { ...@@ -46,6 +46,15 @@ export function useTabs(_router?: Router) {
await tabStore.setTabTitle(title, targetTab); 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) { async function handleTabAction(action: TableActionEnum, tab?: RouteLocationNormalized) {
const canIUse = canIUseTabs; const canIUse = canIUseTabs;
if (!canIUse) { if (!canIUse) {
...@@ -87,9 +96,8 @@ export function useTabs(_router?: Router) { ...@@ -87,9 +96,8 @@ export function useTabs(_router?: Router) {
closeRight: () => handleTabAction(TableActionEnum.CLOSE_RIGHT), closeRight: () => handleTabAction(TableActionEnum.CLOSE_RIGHT),
closeOther: () => handleTabAction(TableActionEnum.CLOSE_OTHER), closeOther: () => handleTabAction(TableActionEnum.CLOSE_OTHER),
closeCurrent: () => handleTabAction(TableActionEnum.CLOSE_CURRENT), closeCurrent: () => handleTabAction(TableActionEnum.CLOSE_CURRENT),
close: (tab?: RouteLocationNormalized) => { close: (tab?: RouteLocationNormalized) => handleTabAction(TableActionEnum.CLOSE, tab),
handleTabAction(TableActionEnum.CLOSE, tab);
},
setTitle: (title: string, tab?: RouteLocationNormalized) => updateTabTitle(title, tab), setTitle: (title: string, tab?: RouteLocationNormalized) => updateTabTitle(title, tab),
updatePath: (fullPath: string, tab?: RouteLocationNormalized) => updateTabPath(fullPath, tab),
}; };
} }
...@@ -300,6 +300,17 @@ export const useMultipleTabStore = defineStore({ ...@@ -300,6 +300,17 @@ export const useMultipleTabStore = defineStore({
await this.updateCacheTab(); 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();
}
},
}, },
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册