|
@@ -2,6 +2,7 @@ import { Layout, Dropdown, Menu, Modal, Input, Form, Space, Button } from 'antd'
|
|
|
import { withRouter } from 'react-router'
|
|
|
import { useState, useEffect } from 'react';
|
|
|
import { useSelector, useDispatch } from 'react-redux';
|
|
|
+import { RedoOutlined } from '@ant-design/icons';
|
|
|
import MyMessage from "../MyMessage";
|
|
|
import { panesNow } from '@reducers/tabPanes.js';
|
|
|
import { getTimeDetail } from '@utils/index';
|
|
@@ -12,7 +13,7 @@ import down from '@images/down.png';
|
|
|
import './index.less'
|
|
|
import { message } from "antd/lib/index";
|
|
|
import { add, active } from '@reducers/tabPanes'
|
|
|
-import { setUnReadNum} from '@reducers/userInfo.js';
|
|
|
+import { setUnReadNum, setRegularNum, setRulerNum, setProblemNum, setLossNum } from '@reducers/userInfo.js';
|
|
|
import apiObj from '@api/index';
|
|
|
|
|
|
const { post, api, xPost } = apiObj;
|
|
@@ -24,20 +25,20 @@ const { Header } = Layout;
|
|
|
|
|
|
function AHeader({ history, hideName }) {
|
|
|
const dispatch = useDispatch();//当前选中的菜单
|
|
|
- const { panes } = useSelector(state => {
|
|
|
+ const { panes, activeTab } = useSelector(state => {
|
|
|
return state.tabPanes;
|
|
|
});
|
|
|
const [form] = Form.useForm();
|
|
|
const [dateTime, setDateTime] = useState('');
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
//const [unReadNum,setUnReadNum] = useState(0);
|
|
|
- const [systemName,setSystemName] = useState("");
|
|
|
+ const [systemName, setSystemName] = useState("");
|
|
|
//const [userName,setUserName] = useState("");
|
|
|
const userName = localStorage.getItem("userName");
|
|
|
const hospitalId = localStorage.getItem("hospitalId");
|
|
|
const softwareArr = JSON.parse(localStorage.getItem("software"));
|
|
|
|
|
|
- const { user, unReadNum } = useSelector((state) => {
|
|
|
+ const { user, unReadNum, regularNum, rulerNum, problemNum, lossNum } = useSelector((state) => {
|
|
|
return state.userInfo;
|
|
|
});
|
|
|
//退出
|
|
@@ -49,14 +50,35 @@ function AHeader({ history, hideName }) {
|
|
|
dispatch(panesNow([]));
|
|
|
history.push('/login');
|
|
|
}
|
|
|
+ function getRefresh() {
|
|
|
+ console.log(activeTab);
|
|
|
+ let count
|
|
|
+ if (activeTab.split('&')[0] == "SJZL-ZZSWH") {
|
|
|
+ count = regularNum
|
|
|
+ count++
|
|
|
+ dispatch(setRegularNum(count));
|
|
|
+ } else if (activeTab.split('&')[0] == "SJZL-ZDJYGZWH") {
|
|
|
+ count = rulerNum
|
|
|
+ count++
|
|
|
+ dispatch(setRulerNum(count));
|
|
|
+ } else if (activeTab.split('&')[0] == "SJZL-ZDJYWTMX") {
|
|
|
+ count = problemNum
|
|
|
+ count++
|
|
|
+ dispatch(setProblemNum(count));
|
|
|
+ } else if (activeTab.split('&')[0] == "SJZL-BLSJDSMX") {
|
|
|
+ count = lossNum
|
|
|
+ count++
|
|
|
+ dispatch(setLossNum(count));
|
|
|
+ }
|
|
|
+ }
|
|
|
//获取未读消息数量
|
|
|
- function getNotNoticeCount(){
|
|
|
+ function getNotNoticeCount() {
|
|
|
xPost(api.getNotNoticeCount).then((res) => {
|
|
|
if (res.data.code === 200) {
|
|
|
- const data = res.data.data||{};
|
|
|
+ const data = res.data.data || {};
|
|
|
let count = data.count;
|
|
|
- count = count>99?'99+':count;
|
|
|
- dispatch(setUnReadNum(count));
|
|
|
+ count = count > 99 ? '99+' : count;
|
|
|
+ dispatch(setUnReadNum(count));
|
|
|
initWebsocket(count);
|
|
|
} else {
|
|
|
//message.warning(res.data.msg || '请求失败');
|
|
@@ -64,38 +86,38 @@ function AHeader({ history, hideName }) {
|
|
|
})
|
|
|
}
|
|
|
//未读消息页面显示并带入未读筛选条件
|
|
|
- function showMyMsgPage(){
|
|
|
+ function showMyMsgPage() {
|
|
|
const pageKey = 'ZNTZ-WDTZ&我的通知';
|
|
|
const item = panes.find((it) => it.key === pageKey);
|
|
|
if (item) { //已存在当前tab,则定位即可不增加
|
|
|
- dispatch(active({idName:pageKey,isUnRead:true}));
|
|
|
+ dispatch(active({ idName: pageKey, isUnRead: true }));
|
|
|
return;
|
|
|
}
|
|
|
dispatch(
|
|
|
- add({ title: '我的通知', content: <MyMessage />, key: pageKey,isUnRead:true})
|
|
|
+ add({ title: '我的通知', content: <MyMessage />, key: pageKey, isUnRead: true })
|
|
|
)
|
|
|
}
|
|
|
- async function initWebsocket(num){
|
|
|
+ async function initWebsocket(num) {
|
|
|
const mqtt = require('mqtt');
|
|
|
- const client = mqtt.connect(api.websocketUrl);
|
|
|
+ const client = mqtt.connect(api.websocketUrl);
|
|
|
//const hisId = getCookie("hospitalId");
|
|
|
client.on('connect', function () {
|
|
|
- client.subscribe(hospitalId+"-"+user.id, function (err) {
|
|
|
+ client.subscribe(hospitalId + "-" + user.id, function (err) {
|
|
|
if (!err) {
|
|
|
- console.log(hospitalId+"-"+user.id+"订阅成功")
|
|
|
+ console.log(hospitalId + "-" + user.id + "订阅成功")
|
|
|
}
|
|
|
})
|
|
|
})
|
|
|
|
|
|
client.on('message', function (topic, message) {
|
|
|
- let n = num>unReadNum?num:unReadNum;
|
|
|
+ let n = num > unReadNum ? num : unReadNum;
|
|
|
setUnReadNum(+n)
|
|
|
- console.log('收到消息+1:',message.toString())
|
|
|
+ console.log('收到消息+1:', message.toString())
|
|
|
})
|
|
|
}
|
|
|
//获取系统、用户名称用于页头显示
|
|
|
- function getSysName(){
|
|
|
- setSystemName(localStorage.getItem("systemName"));
|
|
|
+ function getSysName() {
|
|
|
+ setSystemName(localStorage.getItem("systemName"));
|
|
|
}
|
|
|
/*function handleUserInfo(data){
|
|
|
const { userInfo, software } = data;
|
|
@@ -139,7 +161,7 @@ function AHeader({ history, hideName }) {
|
|
|
})
|
|
|
}
|
|
|
useEffect(() => {
|
|
|
- getSysName();
|
|
|
+ getSysName();
|
|
|
countTime();
|
|
|
getNotNoticeCount();
|
|
|
return function clearUp() {
|
|
@@ -159,13 +181,13 @@ function AHeader({ history, hideName }) {
|
|
|
<Header className='page-header'>
|
|
|
<img className='logo' src={logo} alt="" />
|
|
|
{hideName ? '' : <><span className='break-line'>|</span>
|
|
|
- <span className='sys-name'>{systemName}</span></>}
|
|
|
+ <span className='sys-name'>{systemName}<span className='refresh' onClick={getRefresh}><RedoOutlined /></span></span></>}
|
|
|
<div className='infos'>
|
|
|
<span className='time'>{dateTime}</span>
|
|
|
<span className='break-line'>|</span>
|
|
|
<div className="unRead-msg-cont" onClick={showMyMsgPage}>
|
|
|
- <img className='msg-icon' src={msg} alt="未读消息"/>
|
|
|
- {unReadNum?<span className='unRead-msg'>{unReadNum}</span>:''}
|
|
|
+ <img className='msg-icon' src={msg} alt="未读消息" />
|
|
|
+ {unReadNum ? <span className='unRead-msg'>{unReadNum}</span> : ''}
|
|
|
</div>
|
|
|
<div className="user">
|
|
|
<Dropdown overlay={menu} trigger={['click']}>
|