广州市综治平台前端
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
/*
 * @Company: hugeInfo
 * @Author: xzx
 * @Date: 2022-03-25 11:00:36
 * @LastEditors: lwh
 * @LastEditTime: 2025-01-23 11:14:34
 * @Version: 1.0.0
 * @Description: 登录注册页 TODO:注释掉的内容代码是暂时没有开发的功能,后续看需求是否添加
 */
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Form, Input, Button, Divider, message, Tabs, Space, Typography, Radio } from 'antd';
import { QrcodeOutlined, ScanOutlined } from '@ant-design/icons';
import * as $$ from '../../utils/utility';
import logAvatar from '../../assets/images/logAvatar.png';
import logo1 from '../../assets/images/logo1.png';
import publicDataStatus from '../../status/publicData';
import SlideTest from '../../components/SlideTest';
 
const { TabPane } = Tabs;
 
const { Link } = Typography;
 
// 登录接口
function logInApi(data) {
  return $$.ax.request({ url: 'ctAccount/login', type: 'post', data, service: 'cust' });
}
 
// 角色选择
function switchRoleApi(data) {
  return $$.ax.request({ url: 'ctAccount/switchRole', type: 'get', data, service: 'cust' });
}
 
const LogAndSign = () => {
  // 已登录和未登录 true为已登录
  const [isLog, setIsLog] = useState(false);
 
  useEffect(() => {
    let token = $$.getSessionStorage('customerSystemToken');
    // 无token时
    setIsLog(!!token);
  }, []);
 
  // 变更登录状态
  function transformLogStatus(status) {
    setIsLog(status);
  }
 
  return (
    <div className="logAndSign">
      <main className="logAndSign-main">
        <div className="logAndSign-main-first">
          {!isLog && <BeforeLog returnLogStatus={transformLogStatus} />}
          {isLog && <AfterLog returnLogStatus={transformLogStatus} />}
        </div>
      </main>
      <div onClick={()=>{window.open('https://beian.miit.gov.cn')}} className='public-a' style={{ color: '#bbb', fontSize: '12px', display: 'flex', justifyContent: 'center', position: 'absolute', bottom: '8px', right: '0', width: '550px' }}>粤ICP备2022017384号</div>
    </div>
  );
};
 
//等待登录 组件
const BeforeLog = ({ returnLogStatus }) => {
  const navigate = useNavigate();
 
  // 滑动验证
  const [isSuccessCode, setIsSuccessCode] = useState(false);
 
  // 手写或扫码 默认手写true
  const [isWrite, setIsWrite] = useState(true);
 
  // tab
  const [tabKey, setTabKey] = useState('2');
 
  // 表单
  const [form] = Form.useForm();
 
  // 登录提交
  async function submitLogInfo(value) {
    if (!isSuccessCode && !$$.isDebug) {
      $$.info({ type: 'warning', content: '请滑动验证' });
      return;
    }
    global.setSpinning(true);
    const res = await logInApi(value);
    if (res.type) {
      message.success('您已登入成功,欢迎回来!');
      $$.clearSessionStorage();
      $$.setSessionStorage('customerSystemToken', res.data?.token);
      $$.setSessionStorage('customerSystemUser', res.data || {});
      // $$.setLocal('customerSystemToken', res.data?.token);
      // $$.setLocal('customerSystemUser', res.data || {});
      // 清除公共数据
      publicDataStatus.clearData();
      let ctUseroleList = res.data?.ctUseroleList || [];
      if (ctUseroleList.length === 1) {
        const res = await switchRoleApi({ roleCode: ctUseroleList[0]?.roleCode });
        if (res.type) {
          $$.setSessionStorage('customerSystemToken', res.data);
          // $$.setLocal('customerSystemToken', res.data);
          navigate('/mediate/visit/visitWorkBench');
        }
      } else {
        returnLogStatus(true);
      }
    }
    global.setSpinning(false);
  }
 
  return (
    <div className="logAndSign-main-first-beforeLog animated faster flipInY">
      {isWrite && (
        <div className="logAndSign-main-first-beforeLog-form">
          <div style={{ display: 'flex', justifyContent: 'center' }}>
            <img src={logo1} alt='' style={{ width: '198px', height: '120px' }} />
          </div>
          <div className="logAndSign-main-first-beforeLog-form-title">广州市社会治安综合治理应用平台<br></br>{$$.title}</div>
          <Form name="logForm" onFinish={submitLogInfo} form={form} size="middle">
            <Form.Item name="acc" rules={[{ required: true, message: '请输入帐号' }]}>
              <Input placeholder="请输入登录帐号" allowClear />
            </Form.Item>
            <Form.Item name="cipher" rules={[{ required: true, message: '请输入密码' }]}  >
              <Input.Password type="password" placeholder="请输入登录密码" allowClear autoComplete="on" />
            </Form.Item>
            <SlideTest onSuccessCallback={() => setIsSuccessCode(true)} />
            <Form.Item>
              <Button type="primary" htmlType="submit" block style={{ marginTop: '16px', fontSize: '16px', height: '48px' }} size='large'>
                登录
              </Button>
            </Form.Item>
          </Form>
        </div>
      )}
      {!isWrite && (
        <div className="logAndSign-main-first-beforeLog-wxQrcode">
          <div className="beforeLog-wxQrcode-img">
            <QrcodeOutlined style={{ fontSize: '120px' }} />
          </div>
          <div>
          </div>
        </div>
      )}
    </div>
  );
};
 
//已登录 组件
const AfterLog = ({ returnLogStatus }) => {
  const navigate = useNavigate();
 
  const user = $$.getSessionStorage('customerSystemUser') || {};
 
  const roleList = user.ctUseroleList || [];
 
  const [tabKey, setTabKey] = useState(0);
 
  // 进入系统
  async function enterPersonCenter() {
    global.setSpinning(true);
    const res = await switchRoleApi({ roleCode: roleList[tabKey]?.roleCode });
    global.setSpinning(false);
    if (res.type) {
      $$.setSessionStorage('customerSystemToken', res.data);
      // $$.setLocal('customerSystemToken', res.data);
      navigate('/mediate/visit/visitWorkBench');
    }
  }
 
  //登出
  function handleLogOut() {
    $$.clearLocal('customerSystemUser');
    $$.clearSessionStorage();
    returnLogStatus(false);
  }
 
  function subStrName() {
    let arr = user?.trueName?.split('') || [];
    return arr[0] + (arr.length > 1 ? '*' : '') + (arr.length > 2 ? arr[arr.length - 1] : '');
  }
 
  return (
    <div className="logAndSign-main-first-afterLog animated faster flipInY" >
      <div className="logAndSign-main-first-afterLog-userInfo">
        <div className="afterLog-userInfo-img">
          <img src={logAvatar} alt="登录头像" />
        </div>
        <div className="afterLog-userInfo-label">{subStrName()}</div>
        <div>
          <Radio.Group
            value={tabKey}
            onChange={(e) => {
              let index = e.target.value;
              $$.setSessionStorage('role', { roleId: roleList[index]?.roleId, roleName: roleList[index]?.roleName });
              setTabKey(index);
            }}
          >
            {roleList.map((x, t) => (
              <Radio value={t} key={x.roleId}>
                {x.roleName}
              </Radio>
            ))}
          </Radio.Group>
        </div>
        <div className="afterLog-userInfo-subtitle">以{roleList[tabKey]?.roleName}身份使用平台功能</div>
        <div className="afterLog-userInfo-time">最近一次登录时间:{$$.timeFormat(user?.lastLoginTime)}</div>
        <Button type="primary" block onClick={enterPersonCenter} size="large">
          进入平台
        </Button>
      </div>
    </div>
  );
};
 
export default LogAndSign;