|
@@ -4,7 +4,7 @@ import { useState, useEffect } from 'react';
|
|
|
import { useSelector, useDispatch } from 'react-redux';
|
|
|
import MyMessage from "../MyMessage";
|
|
|
import { panesNow } from '@reducers/tabPanes.js';
|
|
|
-import utils from '@utils/index';
|
|
|
+import { getTimeDetail,getCookie,setCookie } from '@utils/index';
|
|
|
import logo from '@images/logo.png';
|
|
|
import msg from '@images/msg.png';
|
|
|
import me from '@images/me.png';
|
|
@@ -12,7 +12,7 @@ import down from '@images/down.png';
|
|
|
import './index.less'
|
|
|
import { message } from "antd/lib/index";
|
|
|
import { add, active } from '@reducers/tabPanes'
|
|
|
-import { setSys, setUser, setUnReadNum} from '@reducers/userInfo.js';
|
|
|
+import { setSys, setUser} from '@reducers/userInfo.js';
|
|
|
import apiObj from '@api/index';
|
|
|
|
|
|
const { post, api, xPost } = apiObj;
|
|
@@ -21,7 +21,7 @@ const propTypes = {
|
|
|
}
|
|
|
const defaultProps = {};
|
|
|
const { Header } = Layout;
|
|
|
-const { getTimeDetail } = utils;
|
|
|
+
|
|
|
function AHeader({ history, hideName }) {
|
|
|
const dispatch = useDispatch();//当前选中的菜单
|
|
|
const { panes } = useSelector(state => {
|
|
@@ -30,14 +30,17 @@ function AHeader({ history, hideName }) {
|
|
|
const [form] = Form.useForm();
|
|
|
const [dateTime, setDateTime] = useState('');
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
- const { user, sysName,unReadNum } = useSelector((state) => {
|
|
|
+ //const [socket,setSocket] = useState(null);
|
|
|
+ const [unReadNum,setUnReadNum] = useState(0);
|
|
|
+ const { user, sysName } = useSelector((state) => {
|
|
|
return state.userInfo;
|
|
|
});
|
|
|
//退出
|
|
|
function loginOut() {
|
|
|
localStorage.removeItem("token");
|
|
|
- localStorage.removeItem("systemId");
|
|
|
- localStorage.removeItem("hospitalId");
|
|
|
+ setCookie();
|
|
|
+ /*localStorage.removeItem("systemId");
|
|
|
+ localStorage.removeItem("hospitalId");*/
|
|
|
dispatch(panesNow([]));
|
|
|
history.push('/login');
|
|
|
}
|
|
@@ -45,9 +48,12 @@ function AHeader({ history, hideName }) {
|
|
|
function getNotNoticeCount(){
|
|
|
xPost(api.getNotNoticeCount).then((res) => {
|
|
|
if (res.data.code === 200) {
|
|
|
- let count = res.data.count;
|
|
|
+ const data = res.data.data||{};
|
|
|
+ let count = data.count;
|
|
|
count = count>99?'99+':count;
|
|
|
- dispatch(setUnReadNum(count));
|
|
|
+ setUnReadNum(count)
|
|
|
+ initWebsocket(count);
|
|
|
+ //dispatch(setUnReadNum(count));
|
|
|
} else {
|
|
|
//message.warning(res.data.msg || '请求失败');
|
|
|
}
|
|
@@ -64,23 +70,45 @@ function AHeader({ history, hideName }) {
|
|
|
add({ title: '我的通知', content: <MyMessage />, key: 'ZNTZ-WDTZ&我的通知',isUnRead:true})
|
|
|
)
|
|
|
}
|
|
|
- //获取组织列表
|
|
|
- function getOrgList() {
|
|
|
- xPost(api.getUserHospitals).then((res) => {
|
|
|
- if (res.data.code === 200) {
|
|
|
- const data = res.data.data;
|
|
|
- const { userInfo, software } = data;
|
|
|
- const sysId = localStorage.getItem("systemId");
|
|
|
- const hisId = localStorage.getItem("hospitalId");
|
|
|
- const sys = software.find((it) => {
|
|
|
- return +it.id === +sysId
|
|
|
- });
|
|
|
- dispatch(setUser(userInfo));
|
|
|
- sys && dispatch(setSys({ sysId, sysName: sys.name, hisId }));
|
|
|
- } else {
|
|
|
- message.warning(res.data.msg || '获取医院列表失败');
|
|
|
- }
|
|
|
+ async function initWebsocket(num){
|
|
|
+ const mqtt = require('mqtt');
|
|
|
+ const client = mqtt.connect('ws://192.168.2.237:15675/ws');
|
|
|
+ //const userInfo = await getUserHos();
|
|
|
+ //const userdata = userInfo.data.data;
|
|
|
+ //handleUserInfo(userdata);
|
|
|
+ const hisId = getCookie("hospitalId");
|
|
|
+ //setSocket(client)
|
|
|
+ client.on('connect', function () {
|
|
|
+ client.subscribe(hisId+"-"+user.id, function (err) {
|
|
|
+ if (!err) {
|
|
|
+ console.log(hisId+"-"+user.id+"订阅成功")
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
+
|
|
|
+ client.on('message', function (topic, message) {
|
|
|
+ let n = num>unReadNum?num:unReadNum;
|
|
|
+ setUnReadNum(+n+1)
|
|
|
+ console.log('收到消息+1:',message.toString())
|
|
|
+ })
|
|
|
+ }
|
|
|
+ function handleUserInfo(data){
|
|
|
+ const { userInfo, software } = data;
|
|
|
+ const sysId = getCookie("systemId");
|
|
|
+ const hisId = getCookie("hospitalId");
|
|
|
+ const sys = software.find((it) => {
|
|
|
+ return +it.id === +sysId
|
|
|
+ });
|
|
|
+ dispatch(setUser(userInfo));
|
|
|
+ sys && dispatch(setSys({ sysId, sysName: sys.name, hisId }));
|
|
|
+ }
|
|
|
+ //获取组织列表
|
|
|
+ function getUserHos() {
|
|
|
+ return new Promise((resolve)=>{
|
|
|
+ xPost(api.getUserHospitals).then((res)=>{
|
|
|
+ resolve(res);
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
//修改密码
|
|
|
function changePsd() {
|
|
@@ -108,9 +136,11 @@ function AHeader({ history, hideName }) {
|
|
|
useEffect(() => {
|
|
|
countTime();
|
|
|
getNotNoticeCount();
|
|
|
- if (!user.name) {
|
|
|
- getOrgList();
|
|
|
- }
|
|
|
+ //initWebsocket();
|
|
|
+ /*if (!user.name) {
|
|
|
+ //刷新操作时重新获取数据
|
|
|
+ //getOrgList();
|
|
|
+ }*/
|
|
|
return function clearUp() {
|
|
|
clearInterval(interVal)
|
|
|
}
|