| | |
| | | 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 handleCloseAll = () => { |
| | | 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); |
| | |
| | | <span>{getTabLabel(tab)}</span> |
| | | {tab.closable && ( |
| | | <Tooltip title="关闭"> |
| | | <IconButton |
| | | size="small" |
| | | <Box |
| | | component="span" |
| | | onClick={(e) => handleCloseTab(e, tab.path)} |
| | | sx={{ |
| | | display: 'inline-flex', |
| | | alignItems: 'center', |
| | | justifyContent: 'center', |
| | | p: 0.25, |
| | | ml: 0.5, |
| | | borderRadius: '50%', |
| | | cursor: 'pointer', |
| | | '&:hover': { |
| | | backgroundColor: 'rgba(0, 0, 0, 0.1)', |
| | | }, |
| | | }} |
| | | > |
| | | <CloseIcon sx={{ fontSize: 14 }} /> |
| | | </IconButton> |
| | | </Box> |
| | | </Tooltip> |
| | | )} |
| | | </Box> |