import React, { useEffect, useState } from 'react'; import axios from 'axios'; import { groupBy } from 'lodash'; import { Dropdown, Badge, Tabs, Menu, Avatar, Spin } from '@arco-design/web-react'; import { IconNotification, IconMessage, IconCustomerService, IconFile, IconDesktop, } from '@arco-design/web-react/icon'; import useLocale from '../../utils/useLocale'; import MessageList, { MessageListType } from './list'; import styles from './style/index.module.less'; function DropContent() { const locale = useLocale(); const [loading, setLoading] = useState(false); const [groupData, setGroupData] = useState<{ [key: string]: MessageListType }>({}); const [sourceData, setSourceData] = useState([]); function fetchSourceData(showLoading = true) { showLoading && setLoading(true); axios .get('/api/message/list') .then((res) => { setSourceData(res.data); }) .finally(() => { showLoading && setLoading(false); }); } function readMessage(data: MessageListType) { const ids = data.map((item) => item.id); axios .post('/api/message/read', { ids, }) .then(() => { fetchSourceData(); }); } useEffect(() => { fetchSourceData(); }, []); useEffect(() => { const groupData: { [key: string]: MessageListType } = groupBy(sourceData, 'type'); setGroupData(groupData); }, [sourceData]); const tabList = [ { key: 'message', title: locale['messageBox.tab.title.message'], titleIcon: , }, { key: 'notice', title: locale['messageBox.tab.title.notice'], titleIcon: , }, { key: 'approve', title: locale['messageBox.tab.title.approve'], titleIcon: , avatar: ( ), }, ]; return ( {tabList.map((item) => { const { key, title, titleIcon, avatar } = item; const data = groupData[key] || []; const unReadData = data.filter((item) => !item.status); return ( {titleIcon} {title} {unReadData.length ? `(${unReadData.length})` : ''} } > { readMessage([item]); }} onAllBtnClick={(unReadData) => { readMessage(unReadData); }} /> ); })} ); } function MessageBox() { return ( } position="br" triggerProps={{ autoFitPosition: false, }} >
); } export default MessageBox;