瀏覽代碼

全部已读

Renxy 1 年之前
父節點
當前提交
0a7f4a9e46
共有 2 個文件被更改,包括 50 次插入9 次删除
  1. 36 7
      src/pages/MessageCenter/index.js
  2. 14 2
      src/services/message.js

+ 36 - 7
src/pages/MessageCenter/index.js

@@ -1,11 +1,15 @@
 import PageContent from '@/components/PageContent';
 import TabsContent from '@/components/TabsContent';
-import { getNotificationList, readNotification } from '@/services/message';
+import {
+  getAllRead,
+  getNotificationList,
+  readNotification,
+} from '@/services/message';
 import { UnityAction } from '@/utils/utils';
 import { useParams, useRequest, useSearchParams } from '@umijs/max';
 import { Button, Spin } from 'antd';
 import dayjs from 'dayjs';
-import { useState } from 'react';
+import { useRef, useState } from 'react';
 import styles from './index.less';
 const icon1 = require('@/assets/message/work.png');
 const icon2 = require('@/assets/message/check.png');
@@ -15,6 +19,7 @@ const MessageCenter = () => {
   const { projectId } = useParams();
   const [searchParams] = useSearchParams();
   const [tab, setTab] = useState(searchParams.get('type') || '1');
+  const msgTypeRef = useRef();
   //, msgType: 工况:11, 自检:12,  预警:13
   const { data, run, loading } = useRequest(() =>
     getNotificationList({ projectId, msgType: 11 }, { manual: true }),
@@ -34,25 +39,49 @@ const MessageCenter = () => {
     loading: loadingSelf,
   } = useRequest(() => getNotificationList({ projectId, msgType: 12 }));
 
+  const { run: runAllRead } = useRequest(
+    () =>
+      getAllRead({
+        project_id: projectId * 1,
+        msg_type: msgTypeRef.current,
+      }),
+    {
+      manual: true,
+      onSuccess: () => {
+        UnityAction.sendMsg('notiReadAll', '');
+        switch (tab) {
+          case '1':
+            runSelf();
+            break;
+          case '2':
+            runWarning();
+            break;
+          case '3':
+            run();
+            break;
+        }
+      },
+    },
+  );
+
   const handleTabsChange = (tab) => {
     setTab(tab);
     switch (tab) {
       case '1':
+        msgTypeRef.current = 12;
         runSelf();
         break;
       case '2':
+        msgTypeRef.current = 13;
         runWarning();
         break;
       case '3':
+        msgTypeRef.current = 11;
         run();
         break;
     }
   };
 
-  const handleReadClick = () => {
-    UnityAction.sendMsg('notiReadAll', '');
-  };
-
   const handlerSeeClick = (item) => {
     readNotification(item.ID);
     if (tab === '3') {
@@ -145,7 +174,7 @@ const MessageCenter = () => {
           },
         ]}
       />
-      <div className={styles.allRead} onClick={handleReadClick}>
+      <div className={styles.allRead} onClick={runAllRead}>
         全部已读
       </div>
     </PageContent>

+ 14 - 2
src/services/message.js

@@ -16,8 +16,8 @@ export async function getNotificationList(params) {
  * @returns
  */
 export async function readNotification(messageId) {
-  return request(`/api/v1/notification/read/${messageId}`,{
-    method: "PUT"
+  return request(`/api/v1/notification/read/${messageId}`, {
+    method: 'PUT',
   });
 }
 
@@ -29,3 +29,15 @@ export async function readNotification(messageId) {
 export async function getPendingList(params) {
   return request(`/api/v1/pending/list?${stringify(params)}`);
 }
+
+/**
+ * 全部已读
+ * @param {object} project_id
+ * @returns
+ */
+export async function getAllRead(data) {
+  return request(`/api/v1/notification/all_read`, {
+    method: 'POST',
+    data,
+  });
+}