diff --git a/src/pages/HomeView.tsx b/src/pages/HomeView.tsx index 7b4fa2b..ebb1b66 100644 --- a/src/pages/HomeView.tsx +++ b/src/pages/HomeView.tsx @@ -1,4 +1,4 @@ -import React, {useState, useEffect} from 'react'; +import React, {useState, useEffect, useRef} from 'react'; import {UploadOutlined, UserOutlined, BellOutlined, CloseOutlined} from '@ant-design/icons'; import {Layout, Menu, theme, Typography, Button, Dropdown, MenuProps, Popover, Badge} from 'antd'; import {useAppDispatch, useAppSelector} from "../models/hooks"; @@ -149,6 +149,8 @@ function HomeView() { const [messageCount, setMessageCount] = useState(0) const [reimbursementCount, setReimbursementCount] = useState(0) + const messageCountRef = useRef(messageCount); + const reimbursementCountRef = useRef(reimbursementCount); const [badgeTop, setBadgeTop] = useState(66 + 3 * 44) const [eventSource, setEventSource] = useState(null) @@ -172,13 +174,15 @@ function HomeView() { source.addEventListener("reimbursement", (e) => { console.log("reimbursement==>", e) // @ts-ignore - setReimbursementCount(reimbursementCount + Number(e.data)) + reimbursementCountRef.current+=Number(e.data) + setReimbursementCount(reimbursementCountRef.current ) }) source.addEventListener("notice", (e) => { console.log("notice==>", e) // @ts-ignore - setMessageCount(messageCount + Number(e.data)) + messageCountRef.current+=Number(e.data) + setMessageCount(messageCountRef.current) }) source.addEventListener("error", (e) => { @@ -278,7 +282,8 @@ function HomeView() { let unreadCount = 0 for (const notice of data.records) if (!notice.alreadyRead) unreadCount++ - setMessageCount(unreadCount) + messageCountRef.current = unreadCount + setMessageCount( messageCountRef.current ) }).catch(function (error) { console.log(error) }) @@ -291,7 +296,8 @@ function HomeView() { }, {skipNulls: true, arrayFormat: 'indices'}), method: 'get' }).then(response => { - setReimbursementCount(response.data.total) + reimbursementCountRef.current=response.data.total + setReimbursementCount( reimbursementCountRef.current) }).catch(function (error) { console.log(error) }) @@ -347,7 +353,7 @@ function HomeView() {
- - - setMessageCount(count)}/> + { + messageCountRef.current = count + setMessageCount(messageCountRef.current) + }}/> diff --git a/src/pages/Invoice/InvoiceDetailModal.tsx b/src/pages/Invoice/InvoiceDetailModal.tsx index 6541a14..3dac4c3 100644 --- a/src/pages/Invoice/InvoiceDetailModal.tsx +++ b/src/pages/Invoice/InvoiceDetailModal.tsx @@ -14,7 +14,7 @@ import qs from "qs"; const {Text, Paragraph} = Typography; -function InvoiceDetailModal(props: any) { +function InvoiceDetailModal(props: { invoiceDetail: any, open: boolean, onClose: () => void, needRefresh?: () => void, isBase64?:boolean }) { //const [open, setOpen] = useState(false) const [loading, setLoading] = useState(false) const [invoice, setInvoice] = useState(null as any) @@ -88,7 +88,8 @@ function InvoiceDetailModal(props: any) { console.log(response.data) setLoading(false) props.onClose() - props.needRefresh() + if (props.needRefresh) + props.needRefresh() }).catch(function (error) { console.log(error) setLoading(false) @@ -99,7 +100,7 @@ function InvoiceDetailModal(props: any) { @@ -139,11 +140,8 @@ function InvoiceDetailModal(props: any) { - {/*
- -
*/}
) diff --git a/src/pages/Invoice/InvoiceListView.tsx b/src/pages/Invoice/InvoiceListView.tsx index e6859d8..57bd770 100644 --- a/src/pages/Invoice/InvoiceListView.tsx +++ b/src/pages/Invoice/InvoiceListView.tsx @@ -420,7 +420,7 @@ function InvoiceListView(props: { isManagement: boolean }) { searchInvoiceContent(invoiceSearchOption) }} invoiceDetail={invoiceDetail} open={detailModalOpen} onClose={() => { setDetailModalOpen(false) - }} showFooter={true}/> + }}/> ) diff --git a/src/pages/MessageList.css b/src/pages/MessageList.css new file mode 100644 index 0000000..3100f83 --- /dev/null +++ b/src/pages/MessageList.css @@ -0,0 +1,12 @@ +.MessageList::-webkit-scrollbar { + width: 4px; +} +.MessageList::-webkit-scrollbar-thumb { + border-radius: 10px; + box-shadow: inset 0 0 5px rgba(0,0,0,0.2); + background: rgba(0,0,0,0.2); +} +.MessageList::-webkit-scrollbar-track { + border-radius: 0; + background: rgba(0,0,0,0); +} \ No newline at end of file diff --git a/src/pages/MessageList.tsx b/src/pages/MessageList.tsx index 9f193ea..507f0da 100644 --- a/src/pages/MessageList.tsx +++ b/src/pages/MessageList.tsx @@ -7,16 +7,27 @@ import 'dayjs/locale/zh-cn' import axiosInstance from "../utils/axiosInstance"; import {setStaff, setToken} from "../models/store"; import {Staff} from "../models/Staff"; -import {invoiceTypeNameMap} from "../models/Invoice"; +import {InvoiceDetail, invoiceTypeNameMap} from "../models/Invoice"; +import './MessageList.css'; +import InvoiceDetailModal from "./Invoice/InvoiceDetailModal"; const {Text, Title, Paragraph} = Typography const relativeTime = require('dayjs/plugin/relativeTime') dayjs.locale('zh-cn') dayjs.extend(relativeTime) -function MessageList(props: { count: number, onCountChange: (count: number) => void}) { + +function MessageList(props: { count: number, onCountChange: (count: number) => void }) { + const [popoverOpen, setPopoverOpen] = useState(false) const [list, setList] = useState([]) + const [initLoading, setInitLoading] = useState(false) const [loading, setLoading] = useState(false) + const [showLoadMore, setShowLoadMore] = useState(false) + const [index, setIndex] = useState(0) + const [invoiceModalOpen, setInvoiceModalOpen] = useState(false) + const [invoiceDetail, setInvoiceDetail] = useState() + + const pageSize = 10 const getTitle = (notice: Notice) => { switch (notice.data.noticeType) { @@ -78,188 +89,197 @@ function MessageList(props: { count: number, onCountChange: (count: number) => v } const onMessageListOpen = () => { - setLoading(true) + setInitLoading(true) axiosInstance({ url: 'common/notice', method: 'get', params: { pageNum: 0, - pageSize: 10 + pageSize: pageSize } }).then(response => { console.log(response.data) const data: NoticeResponse = response.data setList(data.records) - setLoading(false) + setIndex(pageSize) + setShowLoadMore(pageSize < data.total) + setInitLoading(false) }).catch(function (error) { console.log(error) }) } - useEffect(() => { - /*setList([ - { - "noticeTargetId": "50", - "noticeTime": "1981-10-04 06:37:59", - "data": { - "noticeType": 1, - "count": 16 - }, - "noticeId": "48" - }, - { - "noticeTargetId": "45", - "noticeTime": "1980-05-09 20:10:06", - "data": { - "invoice": { - "invoiceId": 23, - "invoiceNo": "deserunt enim anim ex voluptate", - "invoiceCode": "6", - "invoiceDate": "2016-05-11", - "invoiceUploadTime": "2019-12-01 07:17:16", - "invoiceNote": "consequat laborum", - "invoiceKind": 82, - "invoiceAmount": 51, - "modified": false, - "invoiceFileBase64": "nulla enim", - "invoiceDeparture": "ea enim fugiat do", - "invoiceDestination": null, - "invoiceName": "号度前事她状报" - }, - "rejectStaff": { - "staffName": "飞百亲治头油手", - "staffId": "49", - "staffPassword": "velit in incididunt", - "staffBase": "eiusmod voluptate Ut Lorem occaecat" - }, - "rejectOpinion": "dolore exercitation irure do", - "noticeType": 1 - }, - "noticeId": "93" - }, - { - "noticeTargetId": "32", - "noticeTime": "2014-12-30 09:02:43", - "data": { - "noticeType": 0, - "count": 6 - }, - "noticeId": "58" - }, - { - "noticeTargetId": "16", - "noticeTime": "2014-01-18 21:30:34", - "data": { - "noticeType": 0, - "count": 93 - }, - "noticeId": "42" - }, - { - "noticeTargetId": "9", - "noticeTime": "1997-12-03 08:45:39", - "data": { - "noticeType": 1, - "count": 2 - }, - "noticeId": "40" + const onLoadMore = () => { + setLoading(true); + axiosInstance({ + url: 'common/notice', + method: 'get', + params: { + pageNum: index, + pageSize: pageSize } - ])*/ - }, []); + }).then(response => { + console.log(response.data) + const data: NoticeResponse = response.data + setList(list.concat(data.records)) + setShowLoadMore(index + pageSize < data.total) + setIndex(index + pageSize) + setLoading(false) + }).catch(function (error) { + console.log(error) + }) + }; + + const loadMore = + !initLoading && showLoadMore ? ( +
+ +
+ ) : null; + + const readMessage = (item: Notice) => { + axiosInstance({ + url: 'common/notice/' + item.noticeId + '/read', + method: 'put', + }).then(response => { + props.onCountChange(props.count - 1); + setList(list.map((value, index, array) => { + if (value === item) + value.alreadyRead = true; + return value; + })); + }).catch(function (error) { + console.log(error); + }); + } + + const onMessageClick = (item: Notice, e: any) => { + if (e.target.innerText === '标为已读') + return + console.log('onMessageClick') + switch (item.data.noticeType) { + case 0: + const reimbursementId = item.data.reimbursement?.reimbursementId + if (reimbursementId) { + + } + break + case 1: + let invoice: any = item.data.invoice + if (invoice) { + invoice.invoiceAmount /= 100. + invoice.invoiceState = -1 + setInvoiceDetail(invoice) + setInvoiceModalOpen(true) + } + break + } + setPopoverOpen(false) + readMessage(item) + } return ( - ( -
- - + -
+ }}> + + + - )} - /> - } title="我的消息" arrowPointAtCenter onOpenChange={onMessageListOpen}> - - - -
+ )}/>} title="我的消息" arrowPointAtCenter> + + + + + setInvoiceModalOpen(false)} isBase64={true}/> + ) } diff --git a/src/pages/stat/StatView.tsx b/src/pages/stat/StatView.tsx index 857a9dc..06a5b76 100644 --- a/src/pages/stat/StatView.tsx +++ b/src/pages/stat/StatView.tsx @@ -180,7 +180,7 @@ function StatView() { for (const departmentStat of temporalDepartmentStat.departmentStats) { let valueMap = departmentAmountMap.get(departmentStat.departmentId) if (valueMap) { - valueMap.set(temporalDepartmentStat.value, departmentStat.reimbursementAmount) + valueMap.set(temporalDepartmentStat.value, departmentStat.reimbursementAmount/100.) departmentAmountMap.set(departmentStat.departmentId, valueMap) } } @@ -590,7 +590,7 @@ function StatView() { }, emphasis: { label: { - show: true, + show: false, fontSize: 40, fontWeight: 'bold' } @@ -637,7 +637,7 @@ function StatView() { }, emphasis: { label: { - show: true, + show: false, fontSize: 40, fontWeight: 'bold' }