Badge徽标数

图标右上角的红点、数字或者文字。用于告知用户,该区域的状态变化或者待处理任务的数量。

规则

  • 当用户只需知道大致有内容更新时,应该使用红点型,如:社交中的群消息通知。
  • 当用户有必要知晓每条更新时,应该使用数字型。如:社交中的一对一的消息通知。

代码演示

基本用法

最简单的用法。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'demo-badge-basic',
  4. template: `
  5. <List [renderHeader]="renderHeader">
  6. <ListItem [extra]="'extra content'" [arrow]="'horizontal'">
  7. <Badge [dot]="true" [text]="77" class="dot-badge">
  8. <span style="width:26px ; height: 26px; background:#ddd; display:inline-block"></span>
  9. </Badge>
  10. <span style="margin-left:12px">Dot badge</span>
  11. </ListItem>
  12. <ListItem
  13. [thumb]="'https://zos.alipayobjects.com/rmsportal/faMhXAxhCzLvveJ.png'"
  14. [extra]="customBadage"
  15. [arrow]="'horizontal'"
  16. >Content
  17. </ListItem>
  18. <ListItem>
  19. <Badge [text]="'促'" [corner]="true">
  20. <div class="corner-badge">Use corner prop</div>
  21. </Badge>
  22. </ListItem>
  23. <ListItem [className]="'special-badge'" [extra]="customSpecialBadage">
  24. Custom corner
  25. </ListItem>
  26. <ListItem [extra]="'extra'" [arrow]="'horizontal'">
  27. <Badge [text]="0">Text number 0</Badge>
  28. <Badge [text]="'new'" style="margin-left:12px;"></Badge>
  29. </ListItem>
  30. <ListItem>
  31. Marketing:
  32. <Badge [text]="'减'" [hot]="true" style="margin-left:12px;"></Badge>
  33. <Badge [text]="'惠'" [hot]="true" style="margin-left:12px;"></Badge>
  34. <Badge [text]="'免'" [hot]="true" style="margin-left:12px;"></Badge>
  35. <Badge [text]="'反'" [hot]="true" style="margin-left:12px;"></Badge>
  36. <Badge [text]="'HOT'" [hot]="true" style="margin-left:12px;"></Badge>
  37. </ListItem>
  38. <ListItem>
  39. Customize
  40. <Badge class="quan" [text]="'券'" [setStyle]="quanStyle"></Badge>
  41. <Badge class="new" [text]="'NEW'" [setStyle]="newStyle"></Badge>
  42. <Badge class="autopay" [text]="'自动缴费'" [setStyle]="autopayStyle"></Badge>
  43. </ListItem>
  44. </List>
  45. <ng-template #customBadage>
  46. <Badge [text]="77" [overflowCount]="55"></Badge>
  47. </ng-template>
  48. <ng-template #customSpecialBadage>
  49. <Badge [text]="'促'" [size]="'large'"></Badge>
  50. </ng-template>
  51. `,
  52. styles: [
  53. `
  54. /deep/ .dot-badge .am-badge-dot {
  55. right: -8px;
  56. }
  57. .corner-badge {
  58. height: 50px;
  59. width: 200px;
  60. text-align: left;
  61. font-size: 17px;
  62. color: #000;
  63. }
  64. /deep/ .special-badge .am-list-line {
  65. padding-right: 0;
  66. }
  67. /deep/ .special-badge .am-list-line .am-list-extra {
  68. padding: 0;
  69. height: 44px;
  70. }
  71. /deep/ .special-badge .am-badge {
  72. transform: rotate(45deg);
  73. transform-origin: right bottom;
  74. right: 0px;
  75. top: 13px;
  76. width: 50px;
  77. }
  78. /deep/ .special-badge .am-badge-text {
  79. border-radius: 1px;
  80. }
  81. /deep/ .am-badge {
  82. text-align: right;
  83. font-size: 17px;
  84. color: #000;
  85. }
  86. `
  87. ]
  88. })
  89. export class DemoBadgeBasicComponent {
  90. quanStyle = {
  91. 'margin-left': '12px',
  92. padding: '0 3px',
  93. 'background-color': '#f19736',
  94. 'border-radius': '2px'
  95. };
  96. newStyle = {
  97. 'margin-left': '12px',
  98. padding: '0 3px',
  99. 'background-color': '#21b68a',
  100. 'border-radius': '2px'
  101. };
  102. autopayStyle = {
  103. 'margin-left': '12px',
  104. padding: '0 3px',
  105. 'background-color': '#fff',
  106. 'border-radius': '2px',
  107. color: '#f19736',
  108. border: '1px solid #f19736'
  109. };
  110. renderHeader() {
  111. return 'Basic';
  112. }
  113. }

Badge徽标数 - 图1

API

参数说明类型默认值
[size]大小‘large’ | ‘small’‘small’
[text]展示的数字或文案,当为数字时候,大于 overflowCount
时显示为 ${overflowCount}+,为 0 时隐藏
string | number-
[corner]置于角落booleanfalse
[dot]不展示数字,只有一个小红点booleanfalse
[overflowCount]展示封顶的数字值number99
[hot]营销样式booleanfalse