| | |
| | | }; |
| | | |
| | | // 判断指定标签页是否可以关闭左侧标签 |
| | | // const canCloseLeftForTab = (tabPath) => { |
| | | // const tabIndex = tabs.findIndex(tab => tab.path === tabPath); |
| | | // if (tabIndex <= 0) { |
| | | // return false; // 没有左侧标签或这是第一个标签 |
| | | // } |
| | | // // 检查左侧是否有可关闭的标签(排除dashboard) |
| | | // return tabs.slice(0, tabIndex).some(tab => tab.closable); |
| | | // }; |
| | | const canCloseLeftForTab = (tabPath) => { |
| | | const tabIndex = tabs.findIndex(tab => tab.path === tabPath || isSameResource(tab.path, tabPath)); |
| | | if (tabIndex <= 0) { |
| | | return false; // 没有左侧标签或这是第一个标签 |
| | | } |
| | | // 检查左侧是否有可关闭的标签(排除dashboard) |
| | | return tabs.slice(0, tabIndex).some(tab => tab.closable); |
| | | }; |
| | | |
| | | // 判断指定标签页是否可以关闭右侧标签 |
| | | // const canCloseRightForTab = (tabPath) => { |
| | | // const tabIndex = tabs.findIndex(tab => tab.path === tabPath); |
| | | // if (tabIndex < 0 || tabIndex >= tabs.length - 1) { |
| | | // return false; // 没有右侧标签或这是最后一个标签 |
| | | // } |
| | | // // 检查右侧是否有可关闭的标签 |
| | | // return tabs.slice(tabIndex + 1).some(tab => tab.closable); |
| | | // }; |
| | | const canCloseRightForTab = (tabPath) => { |
| | | const tabIndex = tabs.findIndex(tab => tab.path === tabPath || isSameResource(tab.path, tabPath)); |
| | | if (tabIndex < 0 || tabIndex >= tabs.length - 1) { |
| | | return false; // 没有右侧标签或这是最后一个标签 |
| | | } |
| | | // 检查右侧是否有可关闭的标签 |
| | | return tabs.slice(tabIndex + 1).some(tab => tab.closable); |
| | | }; |
| | | |
| | | return ( |
| | | <Box |
| | |
| | | display: 'inline-flex', |
| | | alignItems: 'center', |
| | | justifyContent: 'center', |
| | | p: 0.25, |
| | | p: 0.35, |
| | | ml: 0.5, |
| | | borderRadius: '50%', |
| | | cursor: 'pointer', |
| | | color: 'inherit', |
| | | '&:hover': { |
| | | backgroundColor: 'rgba(0, 0, 0, 0.1)', |
| | | color: '#d32f2f', |
| | | }, |
| | | }} |
| | | > |
| | | <CloseIcon sx={{ fontSize: 14 }} /> |
| | | <CloseIcon sx={{ fontSize: 16 }} /> |
| | | </Box> |
| | | </Tooltip> |
| | | )} |
| | |
| | | sx: { py: 0 }, |
| | | }} |
| | | > |
| | | {/* 关闭当前标签 |
| | | {contextMenuTab && contextMenuTab.closable && ( |
| | | <MenuItem |
| | | onClick={handleCloseCurrentTab} |
| | |
| | | {t('ra.action.close', '关闭当前标签')} |
| | | </MenuItem> |
| | | )} |
| | | */} |
| | | {contextMenuTab && canCloseLeftForTab(contextMenuTab.path) && ( |
| | | <MenuItem onClick={handleCloseLeftTabs}> |
| | | <MenuItem |
| | | onClick={handleCloseLeftTabs} |
| | | sx={{ |
| | | fontSize: '0.8125rem', |
| | | py: 0.75, |
| | | px: 1.5, |
| | | minHeight: 'auto', |
| | | }} |
| | | > |
| | | {t('ra.action.closeLeft', '关闭左侧标签')} |
| | | </MenuItem> |
| | | )} |
| | | {contextMenuTab && canCloseRightForTab(contextMenuTab.path) && ( |
| | | <MenuItem onClick={handleCloseRightTabs}> |
| | | <MenuItem |
| | | onClick={handleCloseRightTabs} |
| | | sx={{ |
| | | fontSize: '0.8125rem', |
| | | py: 0.75, |
| | | px: 1.5, |
| | | minHeight: 'auto', |
| | | }} |
| | | > |
| | | {t('ra.action.closeRight', '关闭右侧标签')} |
| | | </MenuItem> |
| | | )} |