From 20e38183bfa3a42397250066960433cec9bdcade Mon Sep 17 00:00:00 2001 From: Penguin-Lin <956209866@qq.com> Date: Fri, 29 Mar 2024 18:03:41 +0800 Subject: [PATCH 1/3] feat: add closeAllTabs CloseAllTabs can be used to close all keepalive tabs --- packages/plugins/src/keepalive.ts | 5 ++++- packages/plugins/templates/keepalive/context.tpl | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/plugins/src/keepalive.ts b/packages/plugins/src/keepalive.ts index 5b35f227..cfc005b7 100644 --- a/packages/plugins/src/keepalive.ts +++ b/packages/plugins/src/keepalive.ts @@ -94,6 +94,9 @@ export function closeTab(path: string) { path }}); } +export function closeAllTabs() { + keepaliveEmitter.emit({type:'closeAllTabs'}); +} `, }); // index.ts for export @@ -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'; `, }); }); diff --git a/packages/plugins/templates/keepalive/context.tpl b/packages/plugins/templates/keepalive/context.tpl index 73a2e0f5..7b0cf8e5 100644 --- a/packages/plugins/templates/keepalive/context.tpl +++ b/packages/plugins/templates/keepalive/context.tpl @@ -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(() => { @@ -275,6 +281,9 @@ export function useKeepOutlets() { case 'closeTab': closeTab(payload?.path?.toLowerCase()); break; + case 'closeAllTabs': + closeAllTabs(); + break; {{/hasTabsLayout}} default: break; From 3a1a8d7afd7a503f8f2e3edb40045a095239c759 Mon Sep 17 00:00:00 2001 From: Penguin-Lin <956209866@qq.com> Date: Mon, 1 Apr 2024 11:19:56 +0800 Subject: [PATCH 2/3] feat(@alita/plugins): add closeAllTabs closeAllTabs can be used to close all keepalive tabs --- .changeset/red-fishes-report.md | 5 +++++ packages/plugins/src/keepalive.ts | 5 +---- packages/plugins/templates/keepalive/context.tpl | 9 --------- 3 files changed, 6 insertions(+), 13 deletions(-) create mode 100644 .changeset/red-fishes-report.md diff --git a/.changeset/red-fishes-report.md b/.changeset/red-fishes-report.md new file mode 100644 index 00000000..f3e0625b --- /dev/null +++ b/.changeset/red-fishes-report.md @@ -0,0 +1,5 @@ +--- +'@alita/plugins': patch +--- + +closeAllTabs can be used to close all keepalive tabs diff --git a/packages/plugins/src/keepalive.ts b/packages/plugins/src/keepalive.ts index cfc005b7..5b35f227 100644 --- a/packages/plugins/src/keepalive.ts +++ b/packages/plugins/src/keepalive.ts @@ -94,9 +94,6 @@ export function closeTab(path: string) { path }}); } -export function closeAllTabs() { - keepaliveEmitter.emit({type:'closeAllTabs'}); -} `, }); // index.ts for export @@ -105,7 +102,7 @@ export function closeAllTabs() { path: `${DIR_NAME}/index.tsx`, content: ` export { KeepAliveContext,useKeepOutlets } from './context'; -export { dropByCacheKey, closeTab, closeAllTabs } from './support'; +export { dropByCacheKey, closeTab } from './support'; `, }); }); diff --git a/packages/plugins/templates/keepalive/context.tpl b/packages/plugins/templates/keepalive/context.tpl index 7b0cf8e5..73a2e0f5 100644 --- a/packages/plugins/templates/keepalive/context.tpl +++ b/packages/plugins/templates/keepalive/context.tpl @@ -198,12 +198,6 @@ 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(() => { @@ -281,9 +275,6 @@ export function useKeepOutlets() { case 'closeTab': closeTab(payload?.path?.toLowerCase()); break; - case 'closeAllTabs': - closeAllTabs(); - break; {{/hasTabsLayout}} default: break; From 573ff34aa8c5e0381614b4987beea587543f3fc4 Mon Sep 17 00:00:00 2001 From: Penguin-Lin <956209866@qq.com> Date: Tue, 2 Apr 2024 16:06:47 +0800 Subject: [PATCH 3/3] feat(@alita/plugins): add closeAllTabs --- packages/plugins/src/keepalive.ts | 5 ++++- packages/plugins/templates/keepalive/context.tpl | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/plugins/src/keepalive.ts b/packages/plugins/src/keepalive.ts index 5b35f227..cfc005b7 100644 --- a/packages/plugins/src/keepalive.ts +++ b/packages/plugins/src/keepalive.ts @@ -94,6 +94,9 @@ export function closeTab(path: string) { path }}); } +export function closeAllTabs() { + keepaliveEmitter.emit({type:'closeAllTabs'}); +} `, }); // index.ts for export @@ -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'; `, }); }); diff --git a/packages/plugins/templates/keepalive/context.tpl b/packages/plugins/templates/keepalive/context.tpl index 73a2e0f5..7b0cf8e5 100644 --- a/packages/plugins/templates/keepalive/context.tpl +++ b/packages/plugins/templates/keepalive/context.tpl @@ -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(() => { @@ -275,6 +281,9 @@ export function useKeepOutlets() { case 'closeTab': closeTab(payload?.path?.toLowerCase()); break; + case 'closeAllTabs': + closeAllTabs(); + break; {{/hasTabsLayout}} default: break;