Skip to content

Commit

Permalink
feat: add closeAllTabs
Browse files Browse the repository at this point in the history
feat: add closeAllTabs
  • Loading branch information
xiaohuoni authored Apr 3, 2024
2 parents 8047bb1 + 573ff34 commit fb80f8f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/red-fishes-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alita/plugins': patch
---

closeAllTabs can be used to close all keepalive tabs
5 changes: 4 additions & 1 deletion packages/plugins/src/keepalive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export function closeTab(path: string) {
path
}});
}
export function closeAllTabs() {
keepaliveEmitter.emit({type:'closeAllTabs'});
}
`,
});
// index.ts for export
Expand All @@ -102,7 +105,7 @@ export function closeTab(path: string) {
path: `${DIR_NAME}/index.tsx`,
content: `
export { KeepAliveContext,useKeepOutlets } from './context';
export { dropByCacheKey, closeTab } from './support';
export { dropByCacheKey, closeTab, closeAllTabs } from './support';
`,
});
});
Expand Down
9 changes: 9 additions & 0 deletions packages/plugins/templates/keepalive/context.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ export function useKeepOutlets() {
navigate(`${pathname}${search}${hash}`);
}
};
const closeAllTabs = () => {
const pathList = Object.keys(keepElements.current);
pathList.forEach(targetKey => {
dropByCacheKey(targetKey?.toLowerCase());
});
};
const navigate = useNavigate();
{{#isPluginModelEnable}}
const localConfig = React.useMemo(() => {
Expand Down Expand Up @@ -275,6 +281,9 @@ export function useKeepOutlets() {
case 'closeTab':
closeTab(payload?.path?.toLowerCase());
break;
case 'closeAllTabs':
closeAllTabs();
break;
{{/hasTabsLayout}}
default:
break;
Expand Down

0 comments on commit fb80f8f

Please sign in to comment.