Skip to content

Commit 573ff34

Browse files
committed
feat(@alita/plugins): add closeAllTabs
1 parent 3a1a8d7 commit 573ff34

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/plugins/src/keepalive.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export function closeTab(path: string) {
9494
path
9595
}});
9696
}
97+
export function closeAllTabs() {
98+
keepaliveEmitter.emit({type:'closeAllTabs'});
99+
}
97100
`,
98101
});
99102
// index.ts for export
@@ -102,7 +105,7 @@ export function closeTab(path: string) {
102105
path: `${DIR_NAME}/index.tsx`,
103106
content: `
104107
export { KeepAliveContext,useKeepOutlets } from './context';
105-
export { dropByCacheKey, closeTab } from './support';
108+
export { dropByCacheKey, closeTab, closeAllTabs } from './support';
106109
`,
107110
});
108111
});

packages/plugins/templates/keepalive/context.tpl

+9
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ export function useKeepOutlets() {
198198
navigate(`${pathname}${search}${hash}`);
199199
}
200200
};
201+
const closeAllTabs = () => {
202+
const pathList = Object.keys(keepElements.current);
203+
pathList.forEach(targetKey => {
204+
dropByCacheKey(targetKey?.toLowerCase());
205+
});
206+
};
201207
const navigate = useNavigate();
202208
{{#isPluginModelEnable}}
203209
const localConfig = React.useMemo(() => {
@@ -275,6 +281,9 @@ export function useKeepOutlets() {
275281
case 'closeTab':
276282
closeTab(payload?.path?.toLowerCase());
277283
break;
284+
case 'closeAllTabs':
285+
closeAllTabs();
286+
break;
278287
{{/hasTabsLayout}}
279288
default:
280289
break;

0 commit comments

Comments
 (0)