index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import PageContent from '@/components/PageContent';
  2. import TabsContent from '@/components/TabsContent';
  3. import { getNotificationList } from '@/services/message';
  4. import { UnityAction } from '@/utils/utils';
  5. import { useParams, useRequest } from '@umijs/max';
  6. import { Button, Spin } from 'antd';
  7. import dayjs from 'dayjs';
  8. import { useState } from 'react';
  9. import styles from './index.less';
  10. const icon1 = require('@/assets/message/work.png');
  11. const icon2 = require('@/assets/message/check.png');
  12. const icon3 = require('@/assets/message/warning.png');
  13. const MessageCenter = () => {
  14. const { projectId } = useParams();
  15. const [tab, setTab] = useState('2');
  16. //, msgType: 工况:11, 自检:12, 预警:13
  17. const { data, run, loading } = useRequest(() =>
  18. getNotificationList({ projectId, msgType: 11 }, { manual: true }),
  19. );
  20. const {
  21. data: dataWarning,
  22. run: runWarning,
  23. loading: loadingWarning,
  24. } = useRequest(() =>
  25. getNotificationList({ projectId, msgType: 13 }, { manual: true }),
  26. );
  27. const {
  28. data: dataSelf,
  29. run: runSelf,
  30. loading: loadingSelf,
  31. } = useRequest(() => getNotificationList({ projectId, msgType: 12 }));
  32. const handleTabsChange = (tab) => {
  33. setTab(tab);
  34. switch (tab) {
  35. case '1':
  36. run();
  37. break;
  38. case '2':
  39. runSelf();
  40. break;
  41. case '3':
  42. runWarning();
  43. break;
  44. }
  45. };
  46. const handleReadClick = () => {
  47. UnityAction.sendMsg('notiReadAll', '');
  48. };
  49. const handlerSeeClick = (item) => {
  50. if (tab === '1') {
  51. // if (item?.MandateId) {
  52. UnityAction.sendMsg('OpenTaskModal', `mandate_id=${item.MandateId}`);
  53. // }
  54. } else {
  55. UnityAction.sendMsg('notiZiJian', item.PatrolId);
  56. }
  57. };
  58. const renderItem = (item) => {
  59. const time = item?.CreatedOn
  60. ? dayjs(item.CreatedOn).format('YYYY-MM-DD HH:mm')
  61. : '';
  62. let icon = '';
  63. switch (tab) {
  64. case '1':
  65. icon = icon1;
  66. break;
  67. case '2':
  68. icon = icon2;
  69. break;
  70. case '3':
  71. icon = icon3;
  72. break;
  73. }
  74. return (
  75. <div className={`card-box ${styles.itemContent}`}>
  76. <div className={styles.left}>
  77. <img className={styles.img} src={icon} />
  78. <div>
  79. <div className={styles.text}>{item.MsgBody}</div>
  80. <div className={styles.time}>{time}</div>
  81. </div>
  82. </div>
  83. <div className={styles.right}>
  84. <div
  85. className={item?.ReadStatus ? styles.redPoint : styles.nonePoint}
  86. />
  87. <Button
  88. className={styles.btn}
  89. type="primary"
  90. onClick={() => handlerSeeClick(item)}
  91. >
  92. 查看
  93. </Button>
  94. </div>
  95. </div>
  96. );
  97. };
  98. return (
  99. <PageContent tabs>
  100. <TabsContent
  101. center={false}
  102. defaultActiveKey="2"
  103. onChange={handleTabsChange}
  104. items={[
  105. {
  106. label: `系统自检`,
  107. key: '2',
  108. children: (
  109. <Spin spinning={loadingSelf}>
  110. {dataSelf?.list?.map((item) => renderItem(item))}
  111. </Spin>
  112. ),
  113. },
  114. {
  115. label: `预警数据`,
  116. key: '3',
  117. children: (
  118. <Spin spinning={loadingWarning}>
  119. {dataWarning?.list?.map((item) => renderItem(item))}
  120. </Spin>
  121. ),
  122. },
  123. {
  124. label: `水厂工况`,
  125. key: '1',
  126. children: (
  127. <Spin spinning={loading}>
  128. {data?.list?.map((item) => renderItem(item))}
  129. </Spin>
  130. ),
  131. },
  132. ]}
  133. />
  134. <div className={styles.allRead} onClick={handleReadClick}>
  135. 全部已读
  136. </div>
  137. </PageContent>
  138. );
  139. };
  140. export default MessageCenter;