ant-design / ant-design-pro-layout

🌃 Powerful and easy to use beautiful layout
https://prolayout.ant.design/
MIT License
1k stars 238 forks source link

🧐[问题]从服务器拉取的菜单,无法默认展开 #515

Closed guiqide closed 4 years ago

guiqide commented 4 years ago

🧐 问题描述 [详细地描述问题,让大家都能理解]

从服务器拉取菜单数据后通过menuDataRender返回数据,全部折叠。也设置了menu={{ defaultOpenAll: true }}

💻 示例代码 [如果有必要,展示代码,线上示例,或仓库]

<ProLayout menuDataRender={(arg) => menuDataRender(arg, subMenu)} menu={{ defaultOpenAll: true }}

🚑 其他信息 [如截图等其他信息可以贴在这里]

版本: "@ant-design/pro-layout": "^5.0.8" "antd": "4.2.2",

chenshuai2144 commented 4 years ago

defaultOpenAll 不支持动态菜单的,你可以 请求回来之后再渲染

guiqide commented 4 years ago

defaultOpenAll 不支持动态菜单的,你可以 请求回来之后再渲染

我是在subMenu返回后才渲染的,但依然不行。能具体说明一下在什么阶段注入服务器菜单才能使defaultOpenAll生效吗?

guiqide commented 4 years ago

defaultOpenAll 不支持动态菜单的,你可以 请求回来之后再渲染

我尝试请求回来后再访问BasicLayout,但还是无法展开,不知道哪里添加入menuData才会有效

import React, { useEffect } from 'react';
import { connect, Dispatch } from 'umi';
import { ConnectState } from '@/models/connect';
import { LinkTree } from '@/models/submenu';
import { BasicLayoutProps as ProLayoutProps, Settings } from '@ant-design/pro-layout';
import BasicLayout from './BasicLayout';

interface MainLayoutProps extends ProLayoutProps {
  menuData: LinkTree[];
  settings: Settings;
  dispatch: Dispatch;
}

const MainLayout: React.FC<MainLayoutProps> = (props) => {
  const { dispatch, menuData, settings } = props;

  useEffect(() => {
    if (dispatch) {
      if (!menuData) {
        dispatch({
          type: 'subMenu/fetchSubMenu',
        });
      }
    }
  }, []);
  return menuData ? <BasicLayout {...props} {...settings} /> : null;
};

export default connect(({ subMenu, settings }: ConnectState) => ({
  menuData: subMenu.subMenu,
  settings,
}))(MainLayout);

或者有什么其他Hack方法?

beautycss commented 4 years ago

defaultOpenAll 不支持动态菜单的,你可以 请求回来之后再渲染

我尝试请求回来后再访问BasicLayout,但还是无法展开,不知道哪里添加入menuData才会有效

import React, { useEffect } from 'react';
import { connect, Dispatch } from 'umi';
import { ConnectState } from '@/models/connect';
import { LinkTree } from '@/models/submenu';
import { BasicLayoutProps as ProLayoutProps, Settings } from '@ant-design/pro-layout';
import BasicLayout from './BasicLayout';

interface MainLayoutProps extends ProLayoutProps {
  menuData: LinkTree[];
  settings: Settings;
  dispatch: Dispatch;
}

const MainLayout: React.FC<MainLayoutProps> = (props) => {
  const { dispatch, menuData, settings } = props;

  useEffect(() => {
    if (dispatch) {
      if (!menuData) {
        dispatch({
          type: 'subMenu/fetchSubMenu',
        });
      }
    }
  }, []);
  return menuData ? <BasicLayout {...props} {...settings} /> : null;
};

export default connect(({ subMenu, settings }: ConnectState) => ({
  menuData: subMenu.subMenu,
  settings,
}))(MainLayout);

或者有什么其他Hack方法?

同问,遇到同样的问题。

guiqide commented 4 years ago

而且我尝试用$npm create umi创建一个完整的antd pro comple的项目,在defaultOption.json中设置menu.defaultOpenAll=true也是没效的

chenshuai2144 commented 4 years ago

!loading&& ProLayout