shimai
9 days ago 88a31d5a960bd10f3799bc00f8aa24461567d06e
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
 * AppHeader 组件 - 蓝色顶部导航栏
 * 包含系统名称、通知图标、调解员信息
 */
 
import React, { useState, useCallback } from 'react';
import { Badge, Popover, List, Avatar } from 'antd';
import { BellOutlined, UserOutlined } from '@ant-design/icons';
import { getMergedParams } from '../../utils/urlParams';
import './AppHeader.css';
 
// 默认头像
const DEFAULT_AVATAR = '/app_logo.png';
 
/**
 * 从URL参数获取调解员信息
 */
const getMediatorInfo = () => {
  const params = getMergedParams();
  const userInfo = {
    userId: params.userId || '',
    roleId: params.roleId || '',
    auth_token: params.auth_token || '',
    unitType: params.unitType || '',
    trueName: params.trueName ? decodeURIComponent(params.trueName) : '调解员',
    unit: params.unit ? decodeURIComponent(params.unit) : '',
    unitRegion: params.unitRegion ? decodeURIComponent(params.unitRegion) : '',
    roleName: params.roleName ? decodeURIComponent(params.roleName) : '管理员',
    avatar: params.avatar || ''
  };
 
  // 存储到 localStorage
  try {
    localStorage.setItem('userInfo', JSON.stringify(userInfo));
  } catch (error) {
    console.error('Failed to save userInfo to localStorage:', error);
  }
 
  return userInfo;
};
 
/**
 * 通知列表组件
 */
const NotificationList = ({ notifications, onClose }) => {
  if (!notifications?.length) {
    return (
      <div className="notification-empty">
        <span>暂无新通知</span>
      </div>
    );
  }
 
  return (
    <List
      className="notification-list"
      dataSource={notifications}
      renderItem={(item) => (
        <List.Item className="notification-item">
          <div className="notification-content">
            <span className="notification-text">{item.content || item.title}</span>
            <span className="notification-time">{item.create_time || item.time}</span>
          </div>
        </List.Item>
      )}
    />
  );
};
 
/**
 * AppHeader 主组件
 */
const AppHeader = ({ notifications = [] }) => {
  const [popoverVisible, setPopoverVisible] = useState(false);
  const mediatorInfo = getMediatorInfo();
 
  // 处理Popover显示状态
  const handlePopoverChange = useCallback((visible) => {
    setPopoverVisible(visible);
  }, []);
 
  // 渲染通知图标和气泡
  const renderNotificationIcon = () => (
    <Badge count={notifications.length} offset={[-2, 2]} size="small">
      <BellOutlined className="header-bell-icon" />
    </Badge>
  );
 
  // 渲染调解员信息
  const renderMediatorInfo = () => (
    <div className="header-mediator">
      <Avatar 
        src={mediatorInfo.avatar || DEFAULT_AVATAR} 
        icon={!mediatorInfo.avatar && <UserOutlined />}
        className="mediator-avatar"
      />
      <div className="mediator-details">
        <span className="mediator-name">{mediatorInfo.trueName}</span>
        <span className="mediator-role">
          {mediatorInfo.unit && `${mediatorInfo.unit} | `}{mediatorInfo.roleName}
        </span>
      </div>
      <span className="mediator-status-dot" />
    </div>
  );
 
  return (
    <header className="app-header">
      {/* 左侧:系统名称 */}
      <div className="header-left">
        <span className="header-title">矛盾纠纷应用</span>
      </div>
 
      {/* 右侧:通知+调解员信息 */}
      <div className="header-right">
        {/* 通知图标 */}
        <Popover
          content={<NotificationList notifications={notifications} />}
          title="系统通知"
          trigger="click"
          open={popoverVisible}
          onOpenChange={handlePopoverChange}
          placement="bottomRight"
          overlayClassName="notification-popover"
        >
          <div className="header-notification">
            {renderNotificationIcon()}
          </div>
        </Popover>
 
        {/* 调解员信息 */}
        {renderMediatorInfo()}
      </div>
    </header>
  );
};
 
export default AppHeader;