数据可视化大屏
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

229 wiersze
7.6KB

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