简体   繁体   English

如何在 ant-design-pro v5 中启用 SettingDrawer

[英]How to enable SettingDrawer in ant-design-pro v5

With Ant Design Pro v4, when init project, by choosing the option complete scaffolding , you'll get the Setting Drawer out of the box.使用Ant Design Pro v4,在初始化项目时,通过选择选项complete scaffolding ,您将获得开箱即用的设置抽屉 在此处输入图像描述 But in v5, you won't be able to select the complete option (you can refer to this demo video , no Do you need all the blocks or a simple scaffold there), and the default scaffold of v5 has no SettingDrawer .但是在 v5 中,你将无法使用 select 的complete选项(你可以参考这个演示视频,没有你需要那里的所有块或简单的脚手架),并且v5 的默认脚手架没有SettingDrawer

How to enable it in Ant Design Pro v5?如何在 Ant Design Pro v5 中启用它? I've read this but not helpful because in v5 the Layout configuration code is quite different from v4.我读过这个但没有帮助,因为在 v5 中布局配置代码与 v4 完全不同。 You may init the project in v5 here and v4 here to see what I mean by "quite different".您可以在此处以v5 和此处v4启动项目,以了解我所说的“完全不同”是什么意思。

In And Design Pro v5, use various features by umi plugins.在 And Design Pro v5 中,通过 umi 插件使用各种功能。 As for this feature, /src/app.tsx should like below:至于此功能, /src/app.tsx应该如下所示:

// /src/app.tsx
import type { RunTimeLayoutConfig } from 'umi';
import { SettingDrawer } from '@ant-design/pro-layout';

import defaultSettings from '../config/defaultSettings';

// https://umijs.org/zh-CN/plugins/plugin-initial-state
export async function getInitialState() {
  // ...
  return {
    // others state
    settings: defaultSettings,
  }
}

// https://umijs.org/zh-CN/plugins/plugin-layout
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
  return {
    // others props
    childrenRender: (dom) => {
      return (
        <>
          {dom}
          <SettingDrawer
            settings={initialState?.settings}
            disableUrlParams
            onSettingChange={(nextSettings) =>
              setInitialState({
                ...initialState,
                settings: nextSettings,
              })
            }
          />
        </>
      );
    },
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM