广州市综治平台前端
xusd
2025-06-07 ee685c9f350ec9241107d4e8a05799768a0bce9a
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-03-11 11:33:21
 * @LastEditTime: 2024-12-06 10:17:06
 * @LastEditors: lwh
 * @Version: 1.0.0
 * @Description: 头部组件
 */
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { useNavigate } from 'react-router-dom';
import { Menu, Badge, Avatar, Dropdown, Space, Form, Input, Button, Radio } from 'antd';
import { BellOutlined, LogoutOutlined, UserOutlined, FormOutlined, UserSwitchOutlined, DownCircleFilled } from '@ant-design/icons';
import { mediationCenter, book, operateCenter, operateCenter_active } from '../../assets/images/icon';
import { yewu } from '../../assets/images';
import * as $$ from '../../utils/utility';
import MyMessage from '../../views/myMessage';
import MyModal from '../MyModal';
import { logo1 } from '../../assets/images';
import manual from '../../assets/file/广州市社会治安综合治理应用平台(矛盾纠纷应用)培训手册(广州市版本).pdf'
 
//修改密码api
function submitModifyInfoApi(data) {
  return $$.ax.request({ url: 'ctAccount/changeCipher', type: 'post', data, service: 'cust' });
}
 
// 角色选择
function changeRoleApi(data) {
  return $$.ax.request({ url: 'ctAccount/switchRole', type: 'get', data, service: 'cust' });
}
 
/**
 * roleActive: obj 当前选中的角色
 * headerMenu: array 头部导航菜单
 * headerMenuActive: string 头部导航选择项
 * headerUserChange: bool 判断用户修改自身信息时更新头部的用户名称
 * handleClickMenu: function 头部导航点击
 * handleChangeRole: function 切换角色
 */
const Header = ({ roleActive, headerMenu, headerMenuActive, headerUserChange, handleClickMenu, handleChangeRole, userData }) => {
 
  let navigate = useNavigate();
 
  // 修改密码窗口显示隐藏
  const [visible, setVisible] = useState(false);
 
  // 切换角色的modal
  const [roleModal, setRoleModal] = useState({ visible: false, value: '' });
 
  // 我的消息窗口显示隐藏
  const [myMessageVisible, setMyMessageVisible] = useState(false);
 
  const headerMenuIcon = {
    'mediate': { icon: yewu, iconActive: yewu },
    'operation': { icon: operateCenter, iconActive: operateCenter_active },
  };
 
  // 消息提醒数量
  const [newsNum, setNewsNum] = useState();
 
  // 退出登录
  function handleLoginOut() {
    $$.modalInfo({
      content: '是否退出登录?',
      onOk: () => {
        $$.clearLocal('customerSystemUser');
        $$.clearLocal('customerSystemToken');
        $$.clearSessionStorage();
        navigate('/customerSystem/login');
      },
    });
  }
 
  const userMenu = (
    <Menu>
      {userData?.ctUseroleList?.length > 1 && (
        <>
          <Menu.Item key="changeRole" onClick={() => setRoleModal({ visible: true, value: roleActive.id })}>
            <UserSwitchOutlined style={{ marginRight: '8px' }} />
            切换角色
          </Menu.Item>
          <Menu.Divider />
        </>
      )}
      <Menu.Item key="modifyPassword" onClick={() => setVisible(true)}>
        <FormOutlined style={{ marginRight: '8px' }} />
        修改密码
      </Menu.Item>
      <Menu.Divider />
      <Menu.Item key="loginOut" onClick={handleLoginOut}>
        <LogoutOutlined style={{ marginRight: '8px' }} />
        退出登录
      </Menu.Item>
    </Menu>
  );
 
  // 切换角色
  async function changeRole() {
    if (roleActive.id === roleModal.value) {
      $$.info({ type: 'warning', content: '已是当前角色' });
      return;
    }
    global.setSpinning(true);
    const res = await changeRoleApi({ roleCode: roleModal.roleCode });
    global.setSpinning(false);
    if (res.type) {
      $$.setSessionStorage('customerSystemToken', res.data);
      handleChangeRole(roleModal.name, roleModal.value);
      setRoleModal({ visible: false });
    }
  }
 
 
  return (
    <header className="header">
      <div className="header-logo">
        {/* <img src={logo1} alt="" /> */}
        <div className="header-logo-text" style={{ color: '#fff' }}>
          <div className="header-logo-title">广州市社会治安综合治理应用平台{$$.title}</div>
          {/* <div>Guangzhou Baiyun Diversified Dispute Resolution Platform</div> */}
        </div>
      </div>
      {/* <div className="header-menu">
        {headerMenu.map((x) => {
          return (
            headerMenuActive.powerTag && (
              <div
                onClick={() => handleClickMenu(x)}
                className={`header-menu-item ${x.powerTag === headerMenuActive.powerTag ? 'header-menu-active' : ''}`}
                key={x.powerTag || x.value}
              >
                <div>
                  <img
                    src={x.powerTag === headerMenuActive.powerTag ? headerMenuIcon[x.powerTag]?.iconActive : headerMenuIcon[x.powerTag]?.icon}
                    alt=""
                  />
                </div>
                <div>{x.label}</div>
              </div>
            )
          );
        })}
      </div> */}
      <div className="header-user">
        <Space size="small">
          <div style={{ paddingRight: '24px' }} className="header-user-item" >
            <img style={{ width: '16px', height: '16px' }} src={book} alt="" srcset="" /><div className="header-user-name"><a href={manual} target="_blank" style={{ color: '#fff' }}>用户手册</a></div>
          </div>
          <Dropdown overlay={userMenu} overlayStyle={{ zIndex: 1007 }}>
            <div className="header-user-avatar">
              <Avatar icon={<UserOutlined />} />
              <div>
                <div className="header-user-name">{userData?.trueName || '-'}</div>
                <div className="header-user-unit">
                  <span>{userData?.unit || '-'}</span>
                  <span className="public-rightBorder">{roleActive.roleName || '-'}</span>
                  <DownCircleFilled style={{ fontSize: '10px', marginLeft: '8px', color: '#ffffff' }} />
                </div>
              </div>
            </div>
          </Dropdown>
        </Space>
      </div>
      {/* 切换角色 */}
      <MyModal title="切换角色" visible={roleModal.visible} width={500} onCancel={() => setRoleModal({ visible: false })} footer={false}>
        <div style={{ paddingTop: '16px', textAlign: 'center' }}>
          <Radio.Group
            value={roleModal.value}
            onChange={(e) => setRoleModal({ visible: true, value: e.target.value, name: e.target.label, roleCode: e.target.roleCode })}
          >
            {userData?.ctUseroleList?.map((x) => (
              <Radio key={x.roleId} value={x.roleId} label={x.roleName} roleCode={x.roleCode}>
                {x.roleName}
              </Radio>
            ))}
          </Radio.Group>
        </div>
        <div onClick={changeRole} style={{ marginTop: '16px', textAlign: 'center' }}>
          <Button type="primary">提交</Button>
        </div>
      </MyModal>
      {/* 修改密码 */}
      {visible && <ModifyPassword handleCancel={() => setVisible(false)} />}
      {/* 消息 */}
      {myMessageVisible && <MyMessage visible={myMessageVisible} onClose={() => setMyMessageVisible(false)} />}
    </header>
  );
};
 
// 修改密码
const ModifyPassword = ({ handleCancel }) => {
  // 表单
  const [form] = Form.useForm();
 
  const navigate = useNavigate();
 
  // 提交修改密码
  function submitModifyInfo(values) {
    $$.modalInfo({
      content: '更改密码需重新登录,是否确认修改?',
      onOk: async () => {
        global.setSpinning(true);
        const res = await submitModifyInfoApi(values);
        global.setSpinning(false);
        if (res.type) {
          $$.infoSuccess({ content: '密码修改成功' });
          handleCancel();
          await $$.sleep();
          $$.clearLocal('customerSystemUser');
          $$.clearSessionStorage();
          navigate('/customerSystem/login');
        }
      },
    });
  }
 
  return (
    <MyModal title="修改密码" visible={true} width={500} onCancel={handleCancel} footer={false}>
      <div style={{ paddingTop: '16px' }}>
        <Form
          form={form}
          layout="vertical"
          requiredMark={false}
          onFinish={submitModifyInfo}
          onFinishFailed={({ values, errorFields, outOfDate }) => $$.info({ type: 'error', content: errorFields[0].errors })}
        >
          <Form.Item
            name="oldCipher"
            label={
              <span>
                旧密码<span className="leftRequired">*</span>
              </span>
            }
            rules={[{ required: true, message: '请输入旧密码!' }]}
          >
            <Input.Password placeholder="请输入" />
          </Form.Item>
          <Form.Item
            name="newCipher"
            label={
              <span>
                新密码<span className="leftRequired">*</span>
              </span>
            }
            rules={[{ required: true, pattern: new RegExp('^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{6,12}$', 'g'), message: '密码至少含有小写字母、大写字母、数字….,且密码长度为6-12位' }]}
          >
            <Input.Password placeholder="密码至少含有小写字母、大写字母、数字….,且密码长度为6-12位" />
          </Form.Item>
          <Form.Item
            name="confirmNewCipher"
            label={
              <span>
                确认新密码<span className="leftRequired">*</span>
              </span>
            }
            dependencies={['newCipher']}
            rules={[
              { required: true, message: '请输入确认新密码!' },
              ({ getFieldValue }) => ({
                validator(_, value) {
                  if (!value || getFieldValue('newCipher') === value) {
                    return Promise.resolve();
                  }
                  return Promise.reject(new Error('确认新密码与新密码不一致!'));
                },
              }),
            ]}
          >
            <Input.Password placeholder="请输入" />
          </Form.Item>
          <Form.Item style={{ textAlign: 'center', marginBottom: 0 }}>
            <Button type="primary" htmlType="submit">
              提交
            </Button>
          </Form.Item>
        </Form>
      </div>
    </MyModal>
  );
};
 
Header.propTypes = {
  roleActive: PropTypes.object,
  headerMenu: PropTypes.any,
  headerMenuActive: PropTypes.any,
  headerUserChange: PropTypes.bool,
  handleClickMenu: PropTypes.func,
  handleChangeRole: PropTypes.func,
};
 
export default Header;