PageHeader页头

页头位于页容器中,页容器顶部,起到了内容概览和引导页级操作的作用。包括由面包屑、标题、页面内容简介、页面级操作等、页面级导航组成。

何时使用

当需要使用户快速理解当前页是什么以及方便用户使用页面功能时使用,通常也可被用作页面间导航。

  1. import { NzPageHeaderModule } from 'ng-zorro-antd/page-header';

代码演示

PageHeader页头 - 图1

标准样式

标准页头,适合使用在需要简单描述的场景。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-page-header-basic',
  4. template: `
  5. <nz-page-header class="site-page-header" (nzBack)="onBack()" nzBackIcon nzTitle="Title" nzSubtitle="This is a subtitle">
  6. </nz-page-header>
  7. `
  8. })
  9. export class NzDemoPageHeaderBasicComponent {
  10. onBack(): void {
  11. console.log('onBack');
  12. }
  13. }

PageHeader页头 - 图2

白底模式

默认 PageHeader 是透明底色的。在某些情况下,PageHeader 需要自己的背景颜色。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-page-header-ghost',
  4. template: `
  5. <div class="site-page-header-ghost-wrapper">
  6. <nz-page-header nzBackIcon [nzGhost]="false">
  7. <nz-page-header-title>Title</nz-page-header-title>
  8. <nz-page-header-subtitle>This is a subtitle</nz-page-header-subtitle>
  9. <nz-page-header-extra>
  10. <button nz-button>Operation</button>
  11. <button nz-button>Operation</button>
  12. <button nz-button nzType="primary">Primary</button>
  13. </nz-page-header-extra>
  14. <nz-page-header-content>
  15. <nz-descriptions nzSize="small" [nzColumn]="3">
  16. <nz-descriptions-item nzTitle="Created" [nzSpan]="1">Lili Qu</nz-descriptions-item>
  17. <nz-descriptions-item nzTitle="Association" [nzSpan]="1"><a>421421</a></nz-descriptions-item>
  18. <nz-descriptions-item nzTitle="Creation Time" [nzSpan]="1">2017-01-10</nz-descriptions-item>
  19. <nz-descriptions-item nzTitle="Effective Time" [nzSpan]="1">2017-10-10</nz-descriptions-item>
  20. <nz-descriptions-item nzTitle="Remarks" [nzSpan]="2">
  21. Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
  22. </nz-descriptions-item>
  23. </nz-descriptions>
  24. </nz-page-header-content>
  25. </nz-page-header>
  26. </div>
  27. `
  28. })
  29. export class NzDemoPageHeaderGhostComponent {}

PageHeader页头 - 图3

带面包屑页头

带面包屑页头,适合层级比较深的页面,让用户可以快速导航。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-page-header-breadcrumb',
  4. template: `
  5. <nz-page-header class="site-page-header" nzTitle="Title" nzSubtitle="This is a subtitle">
  6. <nz-breadcrumb nz-page-header-breadcrumb>
  7. <nz-breadcrumb-item>First-level Menu</nz-breadcrumb-item>
  8. <nz-breadcrumb-item>
  9. <a>Second-level Menu</a>
  10. </nz-breadcrumb-item>
  11. <nz-breadcrumb-item>Third-level Menu</nz-breadcrumb-item>
  12. </nz-breadcrumb>
  13. </nz-page-header>
  14. `
  15. })
  16. export class NzDemoPageHeaderBreadcrumbComponent {}

PageHeader页头 - 图4

组合示例

使用了 PageHeader 提供的所有能力。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-page-header-content',
  4. template: `
  5. <nz-page-header class="site-page-header">
  6. <!--breadcrumb-->
  7. <nz-breadcrumb nz-page-header-breadcrumb>
  8. <nz-breadcrumb-item>First-level Menu</nz-breadcrumb-item>
  9. <nz-breadcrumb-item>
  10. <a>Second-level Menu</a>
  11. </nz-breadcrumb-item>
  12. <nz-breadcrumb-item>Third-level Menu</nz-breadcrumb-item>
  13. </nz-breadcrumb>
  14. <!--avatar-->
  15. <nz-avatar nz-page-header-avatar nzSrc="https://avatars0.githubusercontent.com/u/22736418?s=88&v=4"> </nz-avatar>
  16. <!--title-->
  17. <nz-page-header-title>Title</nz-page-header-title>
  18. <!--subtitle-->
  19. <nz-page-header-subtitle>This is a subtitle</nz-page-header-subtitle>
  20. <!--tags-->
  21. <nz-page-header-tags>
  22. <nz-tag [nzColor]="'blue'">Running</nz-tag>
  23. </nz-page-header-tags>
  24. <!--extra-->
  25. <nz-page-header-extra>
  26. <button nz-button>Operation</button>
  27. <button nz-button>Operation</button>
  28. <button nz-button nzType="primary">Primary</button>
  29. <button nz-button nzNoAnimation nz-dropdown [nzDropdownMenu]="menu" style="border: none; padding: 0">
  30. <i nz-icon nzType="ellipsis" nzTheme="outline" style="font-size: 20px; vertical-align: top;"></i>
  31. </button>
  32. <nz-dropdown-menu #menu="nzDropdownMenu">
  33. <ul nz-menu>
  34. <li nz-menu-item>1st menu item length</li>
  35. <li nz-menu-item>2nd menu item length</li>
  36. <li nz-menu-item>3rd menu item length</li>
  37. </ul>
  38. </nz-dropdown-menu>
  39. </nz-page-header-extra>
  40. <!--content-->
  41. <nz-page-header-content>
  42. <div nz-row>
  43. <div class="content">
  44. <p nz-paragraph>
  45. Ant Design interprets the color system into two levels: a system-level color system and a product-level color system.
  46. </p>
  47. <p nz-paragraph>
  48. Ant Design's design team preferred to design with the HSB color model, which makes it easier for designers to have a clear
  49. psychological expectation of color when adjusting colors, as well as facilitate communication in teams.
  50. </p>
  51. <div class="content-link">
  52. <a> <img src="https://gw.alipayobjects.com/zos/rmsportal/MjEImQtenlyueSmVEfUD.svg" alt="start" />Quick Start </a>
  53. <a> <img src="https://gw.alipayobjects.com/zos/rmsportal/NbuDUAuBlIApFuDvWiND.svg" alt="info" />Product Info </a>
  54. <a> <img src="https://gw.alipayobjects.com/zos/rmsportal/ohOEPSYdDTNnyMbGuyLb.svg" alt="doc" />Product Doc </a>
  55. </div>
  56. </div>
  57. <div class="content-image">
  58. <img src="https://gw.alipayobjects.com/zos/antfincdn/K%24NnlsB%26hz/pageHeader.svg" alt="content" />
  59. </div>
  60. </div>
  61. </nz-page-header-content>
  62. </nz-page-header>
  63. `,
  64. styles: [
  65. `
  66. .content {
  67. flex: 1;
  68. }
  69. .content p {
  70. margin-bottom: 1em;
  71. }
  72. .content-link a {
  73. margin-right: 16px;
  74. }
  75. .content-link a img {
  76. margin-right: 8px;
  77. }
  78. .content-image {
  79. margin: 0 0 0 60px;
  80. display: flex;
  81. align-items: center;
  82. }
  83. .content-image img {
  84. width: 100%;
  85. }
  86. @media (max-width: 768px) {
  87. .content-image {
  88. flex: 100%;
  89. margin: 24px 0 0;
  90. }
  91. }
  92. `
  93. ]
  94. })
  95. export class NzDemoPageHeaderContentComponent {}

PageHeader页头 - 图5

多种形态的 PageHeader

使用操作区,并自定义子节点,适合使用在需要展示一些复杂的信息,帮助用户快速了解这个页面的信息和操作。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-page-header-actions',
  4. template: `
  5. <nz-page-header class="site-page-header" nzBackIcon>
  6. <nz-page-header-title>Title</nz-page-header-title>
  7. <nz-page-header-subtitle>This is a subtitle</nz-page-header-subtitle>
  8. <nz-page-header-extra>
  9. <button nz-button>Operation</button>
  10. <button nz-button>Operation</button>
  11. <button nz-button nzType="primary">Primary</button>
  12. </nz-page-header-extra>
  13. <nz-page-header-content>
  14. <nz-descriptions nzSize="small" [nzColumn]="3">
  15. <nz-descriptions-item nzTitle="Created" [nzSpan]="1">Lili Qu</nz-descriptions-item>
  16. <nz-descriptions-item nzTitle="Association" [nzSpan]="1"><a>421421</a></nz-descriptions-item>
  17. <nz-descriptions-item nzTitle="Creation Time" [nzSpan]="1">2017-01-10</nz-descriptions-item>
  18. <nz-descriptions-item nzTitle="Effective Time" [nzSpan]="1">2017-10-10</nz-descriptions-item>
  19. <nz-descriptions-item nzTitle="Remarks" [nzSpan]="2">
  20. Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
  21. </nz-descriptions-item>
  22. </nz-descriptions>
  23. </nz-page-header-content>
  24. </nz-page-header>
  25. <br />
  26. <nz-page-header nzBackIcon>
  27. <nz-page-header-title>Title</nz-page-header-title>
  28. <nz-page-header-subtitle>This is a subtitle</nz-page-header-subtitle>
  29. <nz-page-header-tags>
  30. <nz-tag nzColor="blue">Runing</nz-tag>
  31. </nz-page-header-tags>
  32. <nz-page-header-extra>
  33. <button nz-button>Operation</button>
  34. <button nz-button>Operation</button>
  35. <button nz-button nzType="primary">Primary</button>
  36. </nz-page-header-extra>
  37. <nz-page-header-content>
  38. <nz-row nzType="flex">
  39. <nz-statistic nzTitle="Status" nzValue="Pending"></nz-statistic>
  40. <nz-statistic nzTitle="Price" [nzValue]="568.08" nzPrefix="$" style="margin: 0 32px"></nz-statistic>
  41. <nz-statistic nzTitle="Balance" [nzValue]="3345.08" nzPrefix="$"></nz-statistic>
  42. </nz-row>
  43. </nz-page-header-content>
  44. </nz-page-header>
  45. `
  46. })
  47. export class NzDemoPageHeaderActionsComponent {}

PageHeader页头 - 图6

响应式

在不同大小的屏幕下,应该有不同的表现

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'nz-demo-page-header-responsive',
  4. template: `
  5. <nz-page-header class="site-page-header" nzBackIcon>
  6. <nz-page-header-title>Title</nz-page-header-title>
  7. <nz-page-header-subtitle>This is a subtitle</nz-page-header-subtitle>
  8. <nz-page-header-extra>
  9. <button nz-button>Operation</button>
  10. <button nz-button>Operation</button>
  11. <button nz-button nzType="primary">Primary</button>
  12. </nz-page-header-extra>
  13. <nz-page-header-content>
  14. <div class="content">
  15. <div class="main">
  16. <nz-descriptions nzSize="small" [nzColumn]="2">
  17. <nz-descriptions-item nzTitle="Created" [nzSpan]="1">Lili Qu</nz-descriptions-item>
  18. <nz-descriptions-item nzTitle="Association" [nzSpan]="1"><a>421421</a></nz-descriptions-item>
  19. <nz-descriptions-item nzTitle="Creation Time" [nzSpan]="1">2017-01-10</nz-descriptions-item>
  20. <nz-descriptions-item nzTitle="Effective Time" [nzSpan]="1">2017-10-10</nz-descriptions-item>
  21. <nz-descriptions-item nzTitle="Remarks" [nzSpan]="2">
  22. Gonghu Road, Xihu District, Hangzhou, Zhejiang, China
  23. </nz-descriptions-item>
  24. </nz-descriptions>
  25. </div>
  26. <div class="extra">
  27. <div>
  28. <nz-statistic nzTitle="Status" nzValue="Pending"></nz-statistic>
  29. <nz-statistic nzTitle="Price" [nzValue]="568.08" nzPrefix="$" style="margin: 0 32px"></nz-statistic>
  30. </div>
  31. </div>
  32. </div>
  33. </nz-page-header-content>
  34. <nz-page-header-footer>
  35. <nz-tabset [nzSelectedIndex]="1">
  36. <nz-tab nzTitle="Details"></nz-tab>
  37. <nz-tab nzTitle="Rule"></nz-tab>
  38. </nz-tabset>
  39. </nz-page-header-footer>
  40. </nz-page-header>
  41. `,
  42. styles: [
  43. `
  44. .content {
  45. display: flex;
  46. }
  47. .extra > div {
  48. display: flex;
  49. width: max-content;
  50. justify-content: flex-end;
  51. }
  52. @media (max-width: 576px) {
  53. .content {
  54. display: block;
  55. }
  56. .main {
  57. width: 100%;
  58. margin-bottom: 12px;
  59. }
  60. .extra {
  61. width: 100%;
  62. margin-left: 0;
  63. text-align: left;
  64. }
  65. }
  66. `
  67. ]
  68. })
  69. export class NzDemoPageHeaderResponsiveComponent {}

API

  1. <nz-page-header nzTitle="Page Title"></nz-page-header>

nz-page-headercomponent

参数说明类型默认值全局配置
[nzGhost]使背景色透明booleantrue
[nzTitle]title 文字string | TemplateRef<void>--
[nzSubtitle]subTitle 文字string | TemplateRef<void>--
[nzBackIcon]自定义 back iconstring | TemplateRef<void>--
(nzBack)返回按钮的点击事件EventEmitter<void>未订阅该事件时默认调用 Location[back](需要引入 RouterModule 或者注册 Location))-

Page header 组成部分

元素说明
nz-page-header-titletitle 部分,[nzTitle] 优先级更高
nz-page-header-subtitlesubtitle 部分,[nzSubtitle] 优先级更高
nz-page-header-content内容部分
nz-page-header-footer底部部分
nz-page-header-tagstitle 旁的 tag 列表容器
nz-page-header-extratitle 的行尾操作区部分
nz-breadcrumb[nz-page-header-breadcrumb]面包屑部分
nz-avatar[nz-page-header-avatar]头像部分