| | |
| | | const tabIndex = tabs.findIndex(tab => tab.path === tabPath); |
| | | const newTabs = tabs.filter(tab => tab.path !== tabPath); |
| | | |
| | | // 清除 KeepAlive 缓存 |
| | | if (window.__keepAliveController?.drop) { |
| | | try { |
| | | window.__keepAliveController.drop(tabPath); |
| | | } catch (e) { |
| | | console.warn('Failed to drop KeepAlive cache:', e); |
| | | } |
| | | } |
| | | |
| | | // 如果关闭的是当前标签页,需要导航到其他标签页 |
| | | if (location.pathname === tabPath || isSameResource(location.pathname, tabPath)) { |
| | | // 优先导航到左边的标签页,否则导航到右边的 |
| | |
| | | const dashboardTab = tabs.find(tab => tab.path === '/dashboard'); |
| | | const newTabs = [dashboardTab || { ...FIXED_TABS[0] }]; |
| | | |
| | | // 清除所有 KeepAlive 缓存(dashboard 除外) |
| | | if (window.__keepAliveController?.drop) { |
| | | tabs.forEach(tab => { |
| | | if (tab.path !== '/dashboard') { |
| | | try { |
| | | window.__keepAliveController.drop(tab.path); |
| | | } catch (e) { |
| | | // ignore |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | saveTabs(newTabs); |
| | | setTabs(newTabs); |
| | | |