• 中文
  • PageContainer - 页容器

    PageContainer 是一个页面容器组件,提供了统一的页面布局结构。它包含了页面标题、面包屑导航、页面操作区等标准化的页面元素,让您可以快速构建具有一致性的页面布局。

    • 自动处理页面标题和面包屑导航
    • 支持页面级别的操作按钮和工具栏
    • 提供标准化的页面布局结构
    • 支持水印、加载状态等高级功能

    何时使用

    • 需要统一的页面标题、面包屑导航时
    • 需要页面级别的操作按钮时
    • 需要标准化的页面布局时
    • 需要页面级别的加载状态时
    • 需要页面水印功能时

    代码演示

    基础用法
    import { EllipsisOutlined } from '@ant-design/icons';
    import { PageContainer, ProCard } from '@ant-design/pro-components';
    import { Button, Dropdown, message } from 'antd';
    
    const Demo = () => (
      <div
        style={{
          background: '#F5F7FA',
        }}
      >
        <PageContainer
          onBack={()=>{}}
          header={{
            title: 'Page Title',
            ghost: true,
            breadcrumb: {
              items: [
                {
                  path: '',
                  title: 'Primary page',
                },
                {
                  path: '',
                  title: 'Secondary page',
                },
                {
                  path: '',
                  title: 'Current page',
                },
              ],
            },
            extra: [
              <Button key="1">Secondary button</Button>,
              <Button key="2">Secondary button</Button>,
              <Button key="3" type="primary">
                Primary button
              </Button>,
              <Dropdown
                key="dropdown"
                trigger={['click']}
                menu={{
                  items: [
                    {
                      label: 'Dropdown menu',
                      key: '1',
                    },
                    {
                      label: 'Dropdown menu 2',
                      key: '2',
                    },
                    {
                      label: 'Dropdown menu 3',
                      key: '3',
                    },
                  ],
                }}
              >
                <Button key="4" style={{ padding: '0 8px' }}>
                  <EllipsisOutlined />
                </Button>
              </Dropdown>,
            ],
          }}
          tabBarExtraContent="Test tabBarExtraContent"
          tabList={[
            {
              tab: 'Basic information',
              key: 'base',
              closable: false,
            },
            {
              tab: 'Detailed information',
              key: 'info',
            },
          ]}
          tabProps={{
            type: 'editable-card',
            hideAdd: true,
            onEdit: (_targetKey, action) => {
              message.info(`tab ${action}`);
            },
          }}
          footer={[
            <Button key="3">Reset</Button>,
            <Button key="2" type="primary">
              Submit
            </Button>,
          ]}
        >
          <ProCard direction="column" ghost gutter={[0, 16]}>
            <ProCard style={{ height: 200 }} />
            <ProCard gutter={16} ghost style={{ height: 200 }}>
              <ProCard colSpan={16} />
              <ProCard colSpan={8} />
            </ProCard>
          </ProCard>
        </PageContainer>
      </div>
    );
    
    export default () => (
      <div style={{ padding: 24 }}>
        <Demo />
      </div>
    );
    
    固定头部
    import { PageContainer, ProCard } from '@ant-design/pro-components';
    
    const Demo = () => (
      <div
        style={{
          background: '#F5F7FA',
        }}
      >
        <PageContainer
          fixedHeader
          header={{
            title: 'Page Title',
            breadcrumb: {
              items: [
                {
                  path: '',
                  title: 'Primary page',
                },
                {
                  path: '',
                  title: 'Secondary page',
                },
                {
                  path: '',
                  title: 'Current page',
                },
              ],
            },
          }}
          tabList={[
            {
              tab: 'Selected',
              key: '1',
            },
            {
              tab: 'Clickable',
              key: '2',
            },
            {
              tab: 'Disabled',
              key: '3',
              disabled: true,
            },
          ]}
        >
          <ProCard direction="column" ghost gutter={[0, 16]}>
            <ProCard style={{ height: 200 }} />
            <ProCard gutter={16} ghost>
              <ProCard colSpan={16} style={{ height: 200 }} />
              <ProCard colSpan={8} style={{ height: 200 }} />
            </ProCard>
            <ProCard gutter={16} ghost>
              <ProCard colSpan={8} style={{ height: 200 }} />
              <ProCard colSpan={16} style={{ height: 200 }} />
            </ProCard>
          </ProCard>
        </PageContainer>
      </div>
    );
    
    export default () => (
      <div style={{ padding: 24 }}>
        <Demo />
      </div>
    );
    
    Page Title
    Creator逄一
    Associated form421421
    Creation Date2017-01-10
    Document remarks浙江省杭州市西湖区工专路
    隐藏面包屑
    import { PageContainer, ProCard } from '@ant-design/pro-components';
    import { Descriptions } from 'antd';
    
    const Demo = () => (
      <div
        style={{
          background: '#F5F7FA',
        }}
      >
        <PageContainer
          ghost
          header={{
            title: 'Page Title',
            breadcrumb: {},
          }}
          content={
            <Descriptions column={2} style={{ marginBlockEnd: -16 }}>
              <Descriptions.Item label="Creator">逄一</Descriptions.Item>
              <Descriptions.Item label="Associated form">
                <a>421421</a>
              </Descriptions.Item>
              <Descriptions.Item label="Creation Date">
                2017-01-10
              </Descriptions.Item>
              <Descriptions.Item label="Document remarks">
                浙江省杭州市西湖区工专路
              </Descriptions.Item>
            </Descriptions>
          }
        >
          <ProCard direction="column" ghost gutter={[0, 16]}>
            <ProCard style={{ height: 200 }} />
            <ProCard gutter={16} ghost style={{ height: 200 }}>
              <ProCard colSpan={16} />
              <ProCard colSpan={8} />
            </ProCard>
          </ProCard>
        </PageContainer>
      </div>
    );
    
    export default () => (
      <div style={{ padding: 24 }}>
        <Demo />
      </div>
    );
    

    API

    PageContainer

    参数说明类型默认值
    title页面标题,false 时不展示ReactNode | false-
    subTitle页面副标题ReactNode-
    extra页面操作区ReactNode-
    extraContent操作区旁边的额外内容ReactNode-
    content页面内容ReactNode-
    footer页脚工具栏(数组中的元素会靠右排列)ReactNode[]-
    loading加载状态boolean | SpinProps | ReactNodefalse
    header头部配置Partial<PageHeaderProps> & { children?: ReactNode }-
    pageHeaderRender自定义 pageHeader,返回 false 不展示(props: PageContainerProps) => ReactNode | false-
    affixProps固钉的配置,与 antd 完全相同Omit<AffixProps, 'children'>-
    breadcrumb面包屑配置BreadcrumbProps-
    breadcrumbRender自定义面包屑渲染,返回 false 不展示PageHeaderProps['breadcrumbRender'] | false-
    waterMarkProps水印配置WatermarkProps-
    token自定义的 tokenpageContainerToken-
    stylish样式配置GenerateStyle<PageContainerToken>-
    footerStylish页脚样式配置GenerateStyle<PageContainerToken>-
    footerToolBarProps页脚工具栏配置FooterToolbarProps-
    tabList标签页配置(透传 PageHeader tabs)(TabPaneProps & { key?: React.Key })[]-
    tabActiveKey当前选中标签页TabsProps['activeKey']-
    onTabChange标签页切换回调TabsProps['onChange']-
    tabBarExtraContenttab 上额外的区域TabsProps['tabBarExtraContent']-
    tabPropstabs 的其他配置TabsProps-
    fixedHeader固定 PageHeader 到页面顶部boolean-
    children子元素ReactNode-

    PageHeaderProps

    参数说明类型默认值
    title标题ReactNode-
    subTitle副标题ReactNode-
    extra操作区ReactNode-
    breadcrumb面包屑BreadcrumbProps-
    tags标签TagProps[]-
    avatar头像AvatarProps-
    backIcon返回图标ReactNode-
    onBack返回事件() => void-

    设计规范

    PageContainer 提供了标准化的页面布局,确保整个应用的页面结构一致性。它遵循 Ant Design 的设计规范,提供了一致的用户体验。