notice-icon 通知菜单 - 图1 This article has not been translated, hope that your can PR to translated it. Help us!notice-icon 通知菜单 - 图2

notice-icon 通知菜单

用在导航工具栏上,作为整个产品统一的通知中心。

  1. import { NoticeIconModule } from '@delon/abc/notice-icon';

代码演示

notice-icon 通知菜单 - 图3

通知图标

通常用在导航工具栏上。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'components-notice-icon-basic',
  4. template: `
  5. <notice-icon count="5"></notice-icon>
  6. `
  7. })
  8. export class ComponentsNoticeIconBasicComponent {
  9. }

notice-icon 通知菜单 - 图4

带浮层卡片

点击展开通知卡片,展现多种类型的通知,通常放在导航工具栏。

  1. import { Component } from '@angular/core';
  2. import { NoticeIconList, NoticeItem } from '@delon/abc/notice-icon';
  3. import add from 'date-fns/add';
  4. import formatDistanceToNow from 'date-fns/formatDistanceToNow';
  5. import parse from 'date-fns/parse';
  6. import { NzI18nService } from 'ng-zorro-antd/i18n';
  7. import { NzMessageService } from 'ng-zorro-antd/message';
  8. @Component({
  9. selector: 'components-notice-icon-popover',
  10. template: `
  11. <div
  12. style="text-align: right; height: 64px; line-height: 64px; box-shadow: rgba(0, 21, 41, 0.12) 0 1px 4px; padding: 0 32px; width: 400px;"
  13. >
  14. <notice-icon
  15. [data]="data"
  16. [count]="count"
  17. [loading]="loading"
  18. (select)="select($event)"
  19. (clear)="clear($event)"
  20. (popoverVisibleChange)="loadData()"
  21. ></notice-icon>
  22. </div>
  23. `,
  24. })
  25. export class ComponentsNoticeIconPopoverComponent {
  26. data: NoticeItem[] = [
  27. {
  28. title: '通知',
  29. list: [],
  30. emptyText: '你已查看所有通知',
  31. emptyImage: 'https://gw.alipayobjects.com/zos/rmsportal/wAhyIChODzsoKIOBHcBk.svg',
  32. clearText: '清空通知',
  33. },
  34. {
  35. title: '消息',
  36. list: [],
  37. emptyText: '您已读完所有消息',
  38. emptyImage: 'https://gw.alipayobjects.com/zos/rmsportal/sAuJeJzSKbUmHfBQRzmZ.svg',
  39. clearText: '清空消息',
  40. },
  41. {
  42. title: '待办',
  43. list: [],
  44. emptyText: '你已完成所有待办',
  45. emptyImage: 'https://gw.alipayobjects.com/zos/rmsportal/HsIsxMZiWKrNUavQUXqx.svg',
  46. clearText: '清空待办',
  47. },
  48. ];
  49. count = 5;
  50. loading = false;
  51. constructor(private msg: NzMessageService, private nzI18n: NzI18nService) {}
  52. updateNoticeData(notices: NoticeIconList[]): NoticeItem[] {
  53. const data = this.data.slice();
  54. data.forEach(i => (i.list = []));
  55. notices.forEach(item => {
  56. const newItem = { ...item };
  57. if (typeof newItem.datetime === 'string') {
  58. newItem.datetime = parse(newItem.datetime, 'yyyy-MM-dd', new Date());
  59. }
  60. if (newItem.datetime) {
  61. newItem.datetime = formatDistanceToNow(newItem.datetime as Date, { locale: this.nzI18n.getDateLocale() });
  62. }
  63. if (newItem.extra && newItem.status) {
  64. newItem.color = ({
  65. todo: undefined,
  66. processing: 'blue',
  67. urgent: 'red',
  68. doing: 'gold',
  69. } as { [key: string]: string | undefined })[newItem.status];
  70. }
  71. data.find(w => w.title === newItem.type)!.list.push(newItem);
  72. });
  73. return data;
  74. }
  75. loadData() {
  76. if (this.loading) return;
  77. this.loading = true;
  78. setTimeout(() => {
  79. const now = new Date();
  80. this.data = this.updateNoticeData([
  81. {
  82. id: '000000001',
  83. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
  84. title: '你收到了 14 份新周报',
  85. datetime: add(now, { days: 10 }),
  86. type: '通知',
  87. },
  88. {
  89. id: '000000002',
  90. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png',
  91. title: '你推荐的 曲妮妮 已通过第三轮面试',
  92. datetime: add(now, { days: -3 }),
  93. type: '通知',
  94. },
  95. {
  96. id: '000000003',
  97. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/kISTdvpyTAhtGxpovNWd.png',
  98. title: '这种模板可以区分多种通知类型',
  99. datetime: add(now, { months: -3 }),
  100. read: true,
  101. type: '通知',
  102. },
  103. {
  104. id: '000000004',
  105. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/GvqBnKhFgObvnSGkDsje.png',
  106. title: '左侧图标用于区分不同的类型',
  107. datetime: add(now, { years: -1 }),
  108. type: '通知',
  109. },
  110. {
  111. id: '000000005',
  112. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png',
  113. title: '内容不要超过两行字,超出时自动截断',
  114. datetime: '2017-08-07',
  115. type: '通知',
  116. },
  117. {
  118. id: '000000006',
  119. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  120. title: '曲丽丽 评论了你',
  121. description: '描述信息描述信息描述信息',
  122. datetime: '2017-08-07',
  123. type: '消息',
  124. },
  125. {
  126. id: '000000007',
  127. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  128. title: '朱偏右 回复了你',
  129. description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
  130. datetime: '2017-08-07',
  131. type: '消息',
  132. },
  133. {
  134. id: '000000008',
  135. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
  136. title: '标题',
  137. description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
  138. datetime: '2017-08-07',
  139. type: '消息',
  140. },
  141. {
  142. id: '000000009',
  143. title: '任务名称',
  144. description: '任务需要在 2017-01-12 20:00 前启动',
  145. extra: '未开始',
  146. status: 'todo',
  147. type: '待办',
  148. },
  149. {
  150. id: '000000010',
  151. title: '第三方紧急代码变更',
  152. description: '冠霖提交于 2017-01-06,需在 2017-01-07 前完成代码变更任务',
  153. extra: '马上到期',
  154. status: 'urgent',
  155. type: '待办',
  156. },
  157. {
  158. id: '000000011',
  159. title: '信息安全考试',
  160. description: '指派竹尔于 2017-01-09 前完成更新并发布',
  161. extra: '已耗时 8 天',
  162. status: 'doing',
  163. type: '待办',
  164. },
  165. {
  166. id: '000000012',
  167. title: 'ABCD 版本发布',
  168. description: '冠霖提交于 2017-01-06,需在 2017-01-07 前完成代码变更任务',
  169. extra: '进行中',
  170. status: 'processing',
  171. type: '待办',
  172. },
  173. ]);
  174. this.loading = false;
  175. }, 500);
  176. }
  177. clear(type: string) {
  178. this.msg.success(`清空了 ${type}`);
  179. }
  180. select(res: any) {
  181. this.msg.success(`点击了 ${res.title} 的 ${res.item.title}`);
  182. }
  183. }

API

notice-icon

参数说明类型默认值
[data]数据NoticeItem[]-
[count]图标上的消息总数number-
[loading]弹出卡片加载状态booleanfalse
(select)点击列表项的回调EventEmitter<NoticeIconSelect>-
(clear)点击清空按钮的回调EventEmitter<string>-
[popoverVisible]手动控制Popover显示booleanfalse
(popoverVisibleChange)Popover显隐回调EventEmitter<boolean>-

NoticeItem

参数说明类型默认值
[title]标题string-
[list]列表数据,格式参照下表NoticeIconList[]-
[emptyText]针对每个 Tab 定制空数据文案string无通知
[emptyImage]针对每个 Tab 定制空数据图片string-
[clearText]针对每个 Tab 清空按钮文本string清空

NoticeIconList

参数说明类型默认值
[avatar]头像图片链接string-
[title]标题string-
[description]描述信息string-
[datetime]时间戳string-
[extra]额外信息,在列表项右上角string-
[read]是否已读状态boolean-

NoticeIconSelect

参数说明类型默认值
[title]标题string-
[item]数据项NoticeItem-