Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧐[问题]ProLayout左侧菜单 #7093

Closed
ZhangMeng2018 opened this issue May 18, 2023 · 2 comments
Closed

🧐[问题]ProLayout左侧菜单 #7093

ZhangMeng2018 opened this issue May 18, 2023 · 2 comments
Labels

Comments

@ZhangMeng2018
Copy link

ZhangMeng2018 commented May 18, 2023

🧐 问题描述

左侧菜单切换时已经折叠或展开的菜单会收到影响,自动切换折叠和展开的状态
希望达到的效果:手动折叠的菜单,在点击其它菜单的时候不要自动展开;手动展开的菜单,点击其它菜单时不要自动折叠

@chenshuai2144
Copy link
Contributor

TAutomatically replying with ChatGPT can be attempted, but it cannot be guaranteed to be completely accurate and may not fully address all issues. Please feel free to reply if you have any further questions or concerns.
此回复基于 ChatGPT 自动生成,可以尝试下方案,官方人员会在一定时间后继续继续处理。

🛠 解决方案

可以通过自定义菜单项的点击事件来实现想要的效果。

首先,需要在 ProLayout 组件中设置菜单的唯一标识符,例如 menuKey

<ProLayout
  menu={{
    // 设置菜单唯一标识符
    menuKey: 'menuItemKey',
  }}
>
  {/* 菜单项 */}
  <Menu.Item key="menu-item-1" onClick={handleMenuClick}>
    菜单项1
  </Menu.Item>
  {/* ...其他菜单项 */}
</ProLayout>

然后,在事件处理函数 handleMenuClick 中判断点击的菜单项是否为当前展开的菜单项,如果是则不执行任何操作;否则,根据菜单项的当前展开状态进行折叠或展开操作。

const handleMenuClick = ({ key }) => {
  // 获取当前展开的菜单项
  const expandedMenuKey = getMenuExpandedKey();

  if (expandedMenuKey !== key) {
    if (!isSubMenuExpanded(key)) {
      // 如果点击的菜单项处于折叠状态,则展开
      toggleSubMenu(key);
    } else {
      // 如果点击的菜单项处于展开状态,则折叠
      toggleSubMenu(key);
    }
  }
};

// 获取当前展开的菜单项
const getMenuExpandedKey = () => {
  // 根据具体项目逻辑获取当前展开的菜单项的 key
};

// 判断菜单项是否处于展开状态
const isSubMenuExpanded = (key) => {
  // 根据菜单项的 key 判断是否展开,返回布尔值
};

// 折叠或展开菜单项
const toggleSubMenu = (key) => {
  // 根据菜单项的 key 进行折叠或展开操作
};

以上代码只是一个示例,具体实现需要根据项目的具体情况来进行调整。由于不知道你项目的具体代码结构,所以无法提供更具体的代码示例。

关于 ProLayout 组件的更多信息,请参考 Ant Design Pro 文档

@chenshuai2144
Copy link
Contributor

chenshuai2144 commented Jul 18, 2023

#7372 一起修复啦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants