| | |
| | | setContextMenuTab(null); |
| | | }; |
| | | |
| | | // 关闭左侧标签页(保留指定标签页及其右侧的所有标签页) |
| | | // const handleCloseLeft = (keepTabPath) => { |
| | | // const keepTabIndex = tabs.findIndex(tab => tab.path === keepTabPath); |
| | | // if (keepTabIndex < 0) { |
| | | // return; |
| | | // } |
| | | //关闭左侧标签页(保留指定标签页及其右侧的所有标签页) |
| | | const handleCloseLeft = (keepTabPath) => { |
| | | const keepTabIndex = tabs.findIndex(tab => tab.path === keepTabPath); |
| | | if (keepTabIndex < 0) { |
| | | return; |
| | | } |
| | | |
| | | // // 保留指定标签页及其右侧的所有标签页 |
| | | // const newTabs = tabs.slice(keepTabIndex); |
| | | // 保留指定标签页及其右侧的所有标签页 |
| | | const newTabs = tabs.slice(keepTabIndex); |
| | | |
| | | // // 确保dashboard始终在第一位(如果存在) |
| | | // const dashboardTab = newTabs.find(tab => tab.path === '/dashboard'); |
| | | // if (dashboardTab && newTabs[0].path !== '/dashboard') { |
| | | // const dashboardIndex = newTabs.findIndex(tab => tab.path === '/dashboard'); |
| | | // if (dashboardIndex > 0) { |
| | | // newTabs.splice(dashboardIndex, 1); |
| | | // newTabs.unshift(dashboardTab); |
| | | // } |
| | | // } |
| | | // 确保dashboard始终在第一位(如果存在) |
| | | const dashboardTab = newTabs.find(tab => tab.path === '/dashboard'); |
| | | if (dashboardTab && newTabs[0].path !== '/dashboard') { |
| | | const dashboardIndex = newTabs.findIndex(tab => tab.path === '/dashboard'); |
| | | if (dashboardIndex > 0) { |
| | | newTabs.splice(dashboardIndex, 1); |
| | | newTabs.unshift(dashboardTab); |
| | | } |
| | | } |
| | | |
| | | // saveTabs(newTabs); |
| | | // setTabs(newTabs); |
| | | // setContextMenu(null); |
| | | // setContextMenuTab(null); |
| | | // }; |
| | | saveTabs(newTabs); |
| | | setTabs(newTabs); |
| | | setContextMenu(null); |
| | | setContextMenuTab(null); |
| | | }; |
| | | |
| | | // 关闭右侧标签页(保留指定标签页及其左侧的所有标签页) |
| | | // const handleCloseRight = (keepTabPath) => { |
| | | // const keepTabIndex = tabs.findIndex(tab => tab.path === keepTabPath); |
| | | // if (keepTabIndex < 0) { |
| | | // return; |
| | | // } |
| | | const handleCloseRight = (keepTabPath) => { |
| | | const keepTabIndex = tabs.findIndex(tab => tab.path === keepTabPath); |
| | | if (keepTabIndex < 0) { |
| | | return; |
| | | } |
| | | |
| | | // // 保留指定标签页及其左侧的所有标签页 |
| | | // const newTabs = tabs.slice(0, keepTabIndex + 1); |
| | | // 保留指定标签页及其左侧的所有标签页 |
| | | const newTabs = tabs.slice(0, keepTabIndex + 1); |
| | | |
| | | // saveTabs(newTabs); |
| | | // setTabs(newTabs); |
| | | // setContextMenu(null); |
| | | // setContextMenuTab(null); |
| | | // }; |
| | | saveTabs(newTabs); |
| | | setTabs(newTabs); |
| | | setContextMenu(null); |
| | | setContextMenuTab(null); |
| | | }; |
| | | |
| | | // 处理右键菜单 |
| | | const handleContextMenu = (event, tab) => { |
| | |
| | | }; |
| | | |
| | | // 右键菜单:关闭左侧标签 |
| | | // const handleCloseLeftTabs = () => { |
| | | // if (contextMenuTab) { |
| | | // handleCloseLeft(contextMenuTab.path); |
| | | // } |
| | | // }; |
| | | const handleCloseLeftTabs = () => { |
| | | if (contextMenuTab) { |
| | | handleCloseLeft(contextMenuTab.path); |
| | | } |
| | | }; |
| | | |
| | | // 右键菜单:关闭右侧标签 |
| | | // const handleCloseRightTabs = () => { |
| | | // if (contextMenuTab) { |
| | | // handleCloseRight(contextMenuTab.path); |
| | | // } |
| | | // }; |
| | | const handleCloseRightTabs = () => { |
| | | if (contextMenuTab) { |
| | | handleCloseRight(contextMenuTab.path); |
| | | } |
| | | }; |
| | | |
| | | |
| | | // 获取当前标签页索引 |
| | |
| | | ? { top: contextMenu.mouseY, left: contextMenu.mouseX } |
| | | : undefined |
| | | } |
| | | PaperProps={{ |
| | | sx: { |
| | | minWidth: 120, |
| | | borderRadius: '8px', |
| | | boxShadow: '0 4px 20px rgba(0,0,0,0.08)', |
| | | mt: 0.5, |
| | | py: 0.5, |
| | | }, |
| | | }} |
| | | MenuListProps={{ |
| | | sx: { py: 0 }, |
| | | }} |
| | | > |
| | | {contextMenuTab && contextMenuTab.closable && ( |
| | | <MenuItem onClick={handleCloseCurrentTab}> |
| | | <MenuItem |
| | | onClick={handleCloseCurrentTab} |
| | | sx={{ |
| | | fontSize: '0.8125rem', |
| | | py: 0.75, |
| | | px: 1.5, |
| | | minHeight: 'auto', |
| | | }} |
| | | > |
| | | {t('ra.action.close', '关闭当前标签')} |
| | | </MenuItem> |
| | | )} |
| | | {/* {contextMenuTab && canCloseLeftForTab(contextMenuTab.path) && ( |
| | | {contextMenuTab && canCloseLeftForTab(contextMenuTab.path) && ( |
| | | <MenuItem onClick={handleCloseLeftTabs}> |
| | | {t('ra.action.closeLeft', '关闭左侧标签')} |
| | | </MenuItem> |
| | |
| | | <MenuItem onClick={handleCloseRightTabs}> |
| | | {t('ra.action.closeRight', '关闭右侧标签')} |
| | | </MenuItem> |
| | | )} */} |
| | | )} |
| | | {contextMenuTab && canCloseOthersForTab(contextMenuTab.path) && ( |
| | | <MenuItem onClick={handleCloseOtherTabs}> |
| | | <MenuItem |
| | | onClick={handleCloseOtherTabs} |
| | | sx={{ |
| | | fontSize: '0.8125rem', |
| | | py: 0.75, |
| | | px: 1.5, |
| | | minHeight: 'auto', |
| | | }} |
| | | > |
| | | {t('ra.action.closeOthers', '关闭其他标签')} |
| | | </MenuItem> |
| | | )} |