Browse Source

Merge branch 'dev' of http://192.168.1.41:3000/outaozhen/cldV2react into dev

outaozhen 4 years ago
parent
commit
62f4e0ddb2
4 changed files with 27 additions and 10 deletions
  1. 2 2
      config/routes.js
  2. 19 6
      src/components/RightContent/NoticeIcon/index.tsx
  3. 4 0
      src/global.less
  4. 2 2
      src/services/login.js

+ 2 - 2
config/routes.js

@@ -191,8 +191,8 @@ export default [
         path: '/hr/notification',
         name: 'notification',
         icon: 'icon-commentingo',
-        component: './Hr/Notification'
-        // access: 'authRouteFilter'
+        component: './Hr/Notification',
+        access: 'authRouteFilter'
       }
     ]
   },

+ 19 - 6
src/components/RightContent/NoticeIcon/index.tsx

@@ -1,7 +1,7 @@
 import { useCallback, useEffect, useState } from 'react'
 import { Tag, message } from 'antd'
 import { groupBy } from 'lodash-es'
-import { useModel } from 'umi'
+import { useModel, history } from 'umi'
 
 import NoticeIcon from './NoticeIcon'
 import styles from './index.less'
@@ -72,7 +72,7 @@ const getUnreadData = (noticeData: Record<string, API.NoticeIconItem[]>) => {
 }
 
 const NoticeIconView = () => {
-  const { initialState } = useModel('@@initialState')
+  const { initialState, setInitialState } = useModel('@@initialState')
   const { currentUser } = initialState || {}
   const [notices, setNotices] = useState([])
   const getNotices = useCallback(async () => {
@@ -89,7 +89,7 @@ const NoticeIconView = () => {
   const unreadMsg = getUnreadData(noticeData || {})
 
   const changeReadState = async (id: string) => {
-    const { code = -1 } = await updateNotice({ id })
+    const { code = -1 } = await updateNotice({ ids: [id] })
     if (code === consts.RET_CODE.SUCCESS) {
       setNotices(
         notices.map(item => {
@@ -100,20 +100,33 @@ const NoticeIconView = () => {
           return notice
         })
       )
+      setInitialState({
+        ...initialState,
+        currentUser: { ...currentUser, unreadCount: currentUser.unreadCount - 1 }
+      })
     }
   }
 
-  const clearReadState = (title: string, key: string) => {
+  const clearReadState = async (title: string, key: string) => {
+    const ids = []
     setNotices(
       notices.map(item => {
         const notice = { ...item }
         if (notice.msgType === key) {
           notice.isRead = true
+          ids.push(item.id)
         }
         return notice
       })
     )
-    message.success(`${'清空了'} ${title}`)
+    const { code = -1 } = await updateNotice({ ids })
+    if (code === consts.RET_CODE.SUCCESS) {
+      message.success(`${'清空了'} ${title}`)
+      setInitialState({
+        ...initialState,
+        currentUser: { ...currentUser, unreadCount: currentUser.unreadCount - notices.length }
+      })
+    }
   }
 
   return (
@@ -127,7 +140,7 @@ const NoticeIconView = () => {
       loading={false}
       clearText="清空"
       viewMoreText="查看更多"
-      onViewMore={() => message.info('Click on view more')}
+      onViewMore={() => history.push('/hr/notification')}
       clearClose
     >
       <NoticeIcon.Tab

+ 4 - 0
src/global.less

@@ -78,6 +78,10 @@ ol {
   list-style: none;
 }
 
+.vditor-reset ul,
+.vditor-reset ol {
+  list-style-type: decimal !important;
+}
 @media (max-width: @screen-xs) {
   .ant-table {
     width: 100%;

+ 2 - 2
src/services/login.js

@@ -14,8 +14,8 @@ export async function queryUnreadNotice() {
 }
 
 /** 获取消息列表 */
-export async function queryNoticeList() {
-  return request('/message/list')
+export async function queryNoticeList(params) {
+  return request('/message/list', { params })
 }
 
 /** 消息设置已读 */