董国庆
5 小时以前 63ecd83a0f17442cb1ce3b497f4c7932fda4177f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { outLogin, getUnreadCount } from './service';
import { LogoutOutlined } from '@ant-design/icons';
import { useModel } from '@umijs/max';
import React, { useEffect, useState } from 'react';
import { Access, history, useAccess } from 'umi';
import { flushSync } from 'react-dom';
import './style.less';
 
export type GlobalHeaderRightProps = {
  menu?: boolean;
  children?: React.ReactNode;
};
 
export const AvatarName = () => {
  const { initialState } = useModel('@@initialState');
  // 
 
  const { currentUser } = initialState || {};
  console.log('currentUser currentUser currentUser currentUser',currentUser)
  return <span className="anticon">{currentUser?.userName || '超级管理员'}</span>;
};
 
export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu, children }) => {
 
  const { initialState, setInitialState } = useModel('@@initialState');
 
  const [unreadCount, setUnreadCount] = useState(0);
  const { currentUser } = initialState || {};
  useEffect(() => {
    // const timer = setInterval(() => {
    //   getUnreadCount().then((res: any) => {
    //     setUnreadCount(res.data || 0);
    //   });
    // }, 1000 * 5)
 
    // return () => clearInterval(timer);
  }, []);
 
 
  const onMenuClick = async () => {
    await outLogin();
    localStorage.clear();
    history.push('/login');
    flushSync(() => {
      setInitialState((s) => ({ ...s, currentUser: undefined }));
    });
 
  }
 
  return <div style={{ display: 'flex', alignItems: 'center', color: '#000' }}>
    {
      unreadCount > 0 &&
      <div className='unread' onClick={() => { history.push('/message-notification/list') }}>
        <div>未读提醒</div>
        <div style={{ border: '1px solid red', borderRadius: '50%', width: '18px', lineHeight: '16px', marginLeft: '5px', textAlign: 'center', color: 'red', flexShrink: 0 }}>{unreadCount}</div>
      </div>
    }
    <div style={{ marginRight: '25px' }} >{currentUser?.userName || '超级管理员'}</div>
    <div className="logoOut" onClick={onMenuClick}>退出登录<LogoutOutlined style={{ marginLeft: '5px' }} /></div>
  </div>
};