Drawer抽屉

    • 当需要一个附加的面板来控制父窗体内容,这个面板在需要时呼出。比如,控制界面展示样式,往界面中添加内容。
    • 当需要在当前任务流中插入临时任务,创建或预览附加内容。比如展示协议条款,创建子对象。

    基础抽屉

    基础抽屉,点击触发按钮抽屉从右滑出,点击遮罩区关闭

    1. @Component({
    2. selector: 'nz-demo-drawer-basic-right',
    3. template: `
    4. <button nz-button nzType="primary" (click)="open()">Open</button>
    5. <nz-drawer [nzClosable]="false" [nzVisible]="visible" nzPlacement="right" nzTitle="Basic Drawer" (nzOnClose)="close()">
    6. <p>Some contents...</p>
    7. <p>Some contents...</p>
    8. <p>Some contents...</p>
    9. </nz-drawer>
    10. `
    11. })
    12. export class NzDemoDrawerBasicRightComponent {
    13. visible = false;
    14. open(): void {
    15. this.visible = true;
    16. }
    17. close(): void {
    18. this.visible = false;
    19. }
    20. }

    Drawer抽屉 - 图2

    对象编辑

    多层抽屉

    在抽屉内打开新的抽屉,用以解决多分支任务的复杂状况。

    1. import { Component } from '@angular/core';
    2. @Component({
    3. selector: 'nz-demo-drawer-multi-level-drawer',
    4. template: `
    5. <button nz-button nzType="primary" (click)="open()">New Cookbook</button>
    6. <nz-drawer
    7. [nzClosable]="false"
    8. [nzOffsetX]="childrenVisible ? 180 : 0"
    9. [nzWidth]="320"
    10. [nzVisible]="visible"
    11. nzTitle="Cookbook"
    12. (nzOnClose)="close()"
    13. >
    14. <form nz-form>
    15. <div nz-row>
    16. <div nz-col nzSpan="24">
    17. <nz-form-item>
    18. <nz-form-label>Name</nz-form-label>
    19. <nz-form-control>
    20. <input nz-input placeholder="please enter cookbook name" />
    21. </nz-form-control>
    22. </nz-form-item>
    23. </div>
    24. </div>
    25. <div nz-row>
    26. <div nz-col nzSpan="24">
    27. <nz-form-item>
    28. <nz-form-label>Food</nz-form-label>
    29. <nz-form-control>
    30. <nz-tag>potato</nz-tag>
    31. <nz-tag>eggplant</nz-tag>
    32. </nz-form-control>
    33. </nz-form-item>
    34. </div>
    35. </div>
    36. </form>
    37. <nz-drawer [nzClosable]="false" [nzVisible]="childrenVisible" nzTitle="Food" (nzOnClose)="closeChildren()">
    38. <nz-list [nzDataSource]="vegetables" [nzRenderItem]="item">
    39. <ng-template #item let-item>
    40. <nz-list-item [nzContent]="item"></nz-list-item>
    41. </ng-template>
    42. </nz-list>
    43. </nz-drawer>
    44. </nz-drawer>
    45. `
    46. })
    47. export class NzDemoDrawerMultiLevelDrawerComponent {
    48. visible = false;
    49. childrenVisible = false;
    50. vegetables = ['asparagus', 'bamboo', 'potato', 'carrot', 'cilantro', 'potato', 'eggplant'];
    51. open(): void {
    52. this.visible = true;
    53. }
    54. close(): void {
    55. this.visible = false;
    56. }
    57. openChildren(): void {
    58. this.childrenVisible = true;
    59. }
    60. closeChildren(): void {
    61. this.childrenVisible = false;
    62. }
    63. }

    Drawer抽屉 - 图4

    自定义位置

    信息预览抽屉

    需要快速预览对象概要时使用,点击遮罩区关闭。

    1. import { Component } from '@angular/core';
    2. @Component({
    3. selector: 'nz-demo-drawer-user-profile',
    4. template: `
    5. <nz-list [nzDataSource]="data" [nzRenderItem]="item" [nzItemLayout]="'horizontal'">
    6. <ng-template #item let-item>
    7. <nz-list-item [nzActions]="[viewAction]">
    8. <ng-template #viewAction>
    9. <a (click)="open()">View Profile</a>
    10. </ng-template>
    11. <nz-list-item-meta
    12. [nzTitle]="nzTitle"
    13. nzDescription="Progresser AFX"
    14. >
    15. <ng-template #nzTitle>
    16. <a href="https://ng.ant.design">{{ item.name }}</a>
    17. </ng-template>
    18. </nz-list-item-meta>
    19. </nz-list-item>
    20. </ng-template>
    21. </nz-list>
    22. <nz-drawer [nzVisible]="visible" [nzWidth]="640" [nzClosable]="false" (nzOnClose)="close()">
    23. <p class="title" style=" margin-bottom: 24px;">User Profile</p>
    24. <nz-descriptions [nzColumn]="2" nzTitle="Personal">
    25. <nz-descriptions-item nzTitle="Full Name" [nzSpan]="1">Lily</nz-descriptions-item>
    26. <nz-descriptions-item nzTitle="Account" [nzSpan]="1">AntDesign@example.com</nz-descriptions-item>
    27. <nz-descriptions-item nzTitle="City" [nzSpan]="1">HangZhou</nz-descriptions-item>
    28. <nz-descriptions-item nzTitle="Country" [nzSpan]="1">China🇨🇳</nz-descriptions-item>
    29. <nz-descriptions-item nzTitle="Website" [nzSpan]="1"> - </nz-descriptions-item>
    30. <nz-descriptions-item nzTitle="Message" [nzSpan]="2">
    31. Make things as simple as possible but no simpler.
    32. </nz-descriptions-item>
    33. </nz-descriptions>
    34. <nz-divider></nz-divider>
    35. <nz-descriptions [nzColumn]="2" nzTitle="Company">
    36. <nz-descriptions-item nzTitle="Position" [nzSpan]="1">Programmer</nz-descriptions-item>
    37. <nz-descriptions-item nzTitle="Responsibilities" [nzSpan]="1">Coding</nz-descriptions-item>
    38. <nz-descriptions-item nzTitle="Department" [nzSpan]="1">AFX</nz-descriptions-item>
    39. <nz-descriptions-item nzTitle="Supervisor" [nzSpan]="1">Lin</nz-descriptions-item>
    40. <nz-descriptions-item nzTitle="Skills" [nzSpan]="2">
    41. C / C + +, data structures, software engineering, operating systems, computer networks, databases, compiler theory, computer
    42. architecture, Microcomputer Principle and Interface Technology, Computer English, Java, ASP, etc.
    43. </nz-descriptions-item>
    44. </nz-descriptions>
    45. <nz-divider></nz-divider>
    46. <nz-descriptions [nzColumn]="2" nzTitle="Contacts">
    47. <nz-descriptions-item nzTitle="Email" [nzSpan]="1">AntDesign@example.com</nz-descriptions-item>
    48. <nz-descriptions-item nzTitle="Phone Number" [nzSpan]="1">+86 181 0000 0000</nz-descriptions-item>
    49. <nz-descriptions-item nzTitle="Github" [nzSpan]="2">
    50. <a href="https://github.com/NG-ZORRO/ng-zorro-antd" target="_blank">github.com/NG-ZORRO/ng-zorro-antd</a>
    51. </nz-descriptions-item>
    52. </nz-descriptions>
    53. </nz-drawer>
    54. `,
    55. styles: [
    56. `
    57. .title {
    58. font-size: 16px;
    59. color: rgba(0, 0, 0, 0.85);
    60. line-height: 24px;
    61. display: block;
    62. margin-bottom: 16px;
    63. }
    64. .item-wrap {
    65. font-size: 14px;
    66. line-height: 22px;
    67. margin-bottom: 7px;
    68. color: rgba(0, 0, 0, 0.65);
    69. }
    70. .label {
    71. margin-right: 8px;
    72. display: inline-block;
    73. color: rgba(0, 0, 0, 0.85);
    74. }
    75. `
    76. ]
    77. })
    78. export class NzDemoDrawerUserProfileComponent {
    79. data = [
    80. {
    81. name: 'Lily'
    82. },
    83. {
    84. name: 'Lily'
    85. }
    86. ];
    87. visible = false;
    88. open(): void {
    89. this.visible = true;
    90. }
    91. close(): void {
    92. this.visible = false;
    93. }

    Drawer抽屉 - 图6

    服务方式创建

    方法

    属性