king
2025-05-13 1a176e4bdba485301385caac1a29102e598d25cc
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Input, Button, Checkbox, Modal, message, AutoComplete, Select } from 'antd'
import { UserOutlined, LockOutlined, CloseCircleOutlined } from '@ant-design/icons'
import md5 from 'md5'
import moment from 'moment'
 
import Api from '@/api'
import './index.scss'
 
const { warning } = Modal
let LoginVerCodeTimer = null
 
class LoginTabForm extends Component {
  static propTpyes = {
    isDisabled: PropTypes.bool,
    handleSubmit: PropTypes.func,
    authLogin: PropTypes.func,
    auth: PropTypes.bool,
    authError: PropTypes.string,
    langList: PropTypes.array,
    loginWays: PropTypes.array
  }
 
  state = {
    username: '',
    password: '',
    remember: true,
    protocol: null,
    delay: null,
    loginWays: [],
    smsId: '',
    verdisabled: false,
    hasScan: false,
    timeout: false,
    vispwd: window.GLOB.vispwd,
    wayLabels: {},
    dict: window.GLOB.dict,
    users: [],
    lang: sessionStorage.getItem('lang')
  }
 
  UNSAFE_componentWillMount () {
    let remember = true
    
    if (localStorage.getItem(window.GLOB.sysSign + 'remember') === 'false') {
      remember = false
    }
    if (!window.GLOB.keepKey) {
      remember = false
    }
 
    let smsId = ''
    // let wayLabels = {app_scan: 'APP扫码', weixin_scan: '微信扫码', uname_pwd: '账号登录', sms_vcode: '短信登录'}
 
    // loginWays.forEach(item => {
    //   item.label = window.GLOB.dict[item.type] || wayLabels[item.type]
    //   wayLabels[item.type] = item.label
    //   if (item.type === 'sms_vcode') {
    //     smsId = item.smsId
    //     _loginWays.push(item)
    //   } else if (item.type === 'uname_pwd') {
    //     _loginWays.push(item)
    //   } else if (item.type === 'app_scan') {
    //     _loginWays.push(item)
    //     hasScan = true
    //   } else if (item.type === 'weixin_scan') {
    //     _loginWays.push(item)
    //     hasScan = true
    //   }
    // })
 
    let users = localStorage.getItem(window.GLOB.sysSign + 'users')
    let _user = null
    
    if (users) {
      try {
        users = JSON.parse(window.decodeURIComponent(window.atob(users)))
      } catch (e) {
        users = []
      }
    } else {
      users = []
    }
 
    this.setState({
      users: users,
      username: _user ? _user.username : '',
      password: _user ? _user.password : '',
      smsId: smsId,
      remember
    })
  }
 
  handleConfirm = () => {
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          values.username = values.username.replace(/\t+|\v+|\s+/g, '')
          values.password = values.password.replace(/\t+|\v+|\s+/g, '')
 
          resolve({type: 'uname_pwd', ...values})
        } else {
          reject(err)
        }
      })
    })
  }
 
  changelang = (val) => {
    localStorage.setItem(window.location.href.split('#')[0] + 'lang', val)
    sessionStorage.setItem('lang', val)
 
    window.location.reload()
  }
 
  handleSubmit = e => {
    const { dict } = this.state
    // 登录参数检验
    e && e.preventDefault()
    if (!this.props.auth) {
      warning({
        title: this.props.authError || dict['auth_tip'] || '系统未授权,请联系管理员。',
        okText: dict['got_it'] || '知道了',
        onOk() {},
        onCancel() {}
      })
      return
    }
 
    if (!this.props.form.getFieldValue('username')) {
      const wrap = document.getElementById('username')
      const input = wrap ? wrap.getElementsByTagName('input')[0] : null
      if (input) {
        input.focus()
      }
    } else if (!this.props.form.getFieldValue('password')) {
      const input = document.getElementById('password')
      if (input) {
        input.focus()
      }
    } else {
      this.props.handleSubmit()
    }
  }
 
  componentDidMount () {
    const wrap = document.getElementById('username')
    const input = wrap ? wrap.getElementsByTagName('input')[0] : null
    if (input) {
      input.focus()
    }
  }
 
  getvercode = () => {
    const { smsId, dict } = this.state
    let _phone = this.props.form.getFieldValue('phone')
    if (!_phone) {
      message.warning(dict['phone_no_required'] || '请输入手机号!')
      return
    } else if (!/^1[3456789]\d{9}$/.test(_phone)) {
      message.warning(dict['phone_error'] || '手机号格式错误,请重填!')
      return
    } else if (!sessionStorage.getItem('visitorUserID') || !sessionStorage.getItem('visitorLoginUID')) {
      message.warning(dict['vercode_error'] || '未获取验证码设置,请稍后或刷新重试!')
      return
    }
 
    let _param = {
      func: 'mes_sms_send_code_sso',
      send_type: 'login',
      mob: _phone,
      ID: smsId
    }
    _param.LText = 'minke'
    _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    _param.secretkey = md5(`${_param.LText}mingke${_param.timestamp}`)
    
    _param.userid = sessionStorage.getItem('visitorUserID') || ''
    _param.LoginUID = sessionStorage.getItem('visitorLoginUID') || ''
 
    Api.getSystemConfig(_param).then(res => {
      if (!res.status || !res.n_id) {
        message.warning(res.message || '验证码获取失败!')
        return
      }
 
      let param = {
        func: 'MSN_sms_send_code',
        send_type: 'login',
        mob: _phone,
        timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
        ID: smsId,
        n_id: res.n_id
      }
  
      param.LText = md5(`${_phone}mingke${window.GLOB.appkey}${param.timestamp}`)
      param.secretkey = md5(`${param.LText}mingke${param.timestamp}`)
 
      param.rduri = 'https://sso.mk9h.cn/webapi/dostars'
      param.userid = 'bh0bapabtd45epsgra79segbch6c1ibk'
      param.LoginUID = 'bh0bapabtd45epsgra79segbch6c1ibk'
  
      this.setState({
        verdisabled: true,
        delay: 60
      })
      LoginVerCodeTimer = setTimeout(this.resetVerCodeDelay, 1000)
  
      Api.genericInterface(param).then(res => {
        if (res.status) {
  
        } else {
          if (LoginVerCodeTimer) {
            clearTimeout(LoginVerCodeTimer)
          }
          this.setState({
            verdisabled: false,
            delay: null
          })
          message.warning(res.message)
        }
      }, (error) => {
        if (error && error.ErrCode === 'LoginError') {
          let param = {
            func: 's_visitor_login',
            timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), 
            SessionUid: 'bh0bapabtd45epsgra79segbch6c1ibk',
            TypeCharOne: 'pc',
            appkey: '202004041613277377A6A2456D34A4948AE84'
          }
          
          param.LText = md5(window.btoa('bh0bapabtd45epsgra79segbch6c1ibk' + param.timestamp))
          param.secretkey = md5(param.LText + 'mingke' + param.timestamp)
  
          let params = {
            url: 'https://sso.mk9h.cn/webapi/dologon',
            method: 'post',
            data: JSON.stringify(param)
          }
 
          Api.directRequest(params)
 
          return
        }
 
        if (LoginVerCodeTimer) {
          clearTimeout(LoginVerCodeTimer)
        }
        this.setState({
          verdisabled: false,
          delay: null
        })
      })
    })
  }
 
  resetVerCodeDelay = () => {
    const { delay } = this.state
    if (delay && delay > 1) {
      this.setState({delay: delay - 1})
      LoginVerCodeTimer = setTimeout(this.resetVerCodeDelay, 1000)
    } else {
      this.setState({
        verdisabled: false,
        delay: null
      })
    }
  }
 
  rememberChange = (e) => {
    let val = e.target.checked
 
    localStorage.setItem(window.GLOB.sysSign + 'remember', val)
  }
 
  complete = (val) => {
    const { users } = this.state
 
    let user = users.filter(m => m.username === val)[0]
    let password = user && user.password ? user.password : ''
 
    this.props.form.setFieldsValue({password: password})
 
    if (!password) {
      const input = document.getElementById('password')
      if (input) {
        input.focus()
      }
    }
  }
 
  deleteUser = (e, val) => {
    const { users } = this.state
 
    e.stopPropagation()
 
    let _users = users.filter(m => m.username !== val)
    
    this.setState({users: _users})
 
    localStorage.setItem(window.GLOB.sysSign + 'users', window.btoa(window.encodeURIComponent(JSON.stringify(_users))))
  }
 
  changeAgree = (val) => {
    this.setState({protocol: val})
 
    if (this.scanParam && val) {
      this.props.authLogin(this.scanParam.thd_party_appid, this.scanParam.thd_party_openid, this.scanParam.thd_party_member_id, this.scanParam.scanId)
    }
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  render() {
    const { langList, isDisabled } = this.props
    const { getFieldDecorator } = this.props.form
    const { remember, users, dict, lang, vispwd } = this.state
 
    return (
      <Form className={`login-form login-form-1`} id="login-form" onSubmit={this.handleSubmit}>
        <p className="title">{this.props.platName}</p>
        <div className="form-item-wrap">
          <Form.Item>
            {getFieldDecorator('username', {
              rules: [{ required: true, message: dict['username_required'] || '请输入用户名' }],
              initialValue: this.state.username || '',
            })(
              <AutoComplete
                className
                dataSource={users.map((cell, i) => <AutoComplete.Option className="mk-user-option" value={cell.username} key={i}>
                  {cell.username}
                  <CloseCircleOutlined onClick={(e) => this.deleteUser(e, cell.username)}/>
                </AutoComplete.Option>)}
                filterOption={false}
                onSelect={this.complete}
                defaultActiveFirstOption={false}
                defaultOpen={false}
                optionLabelProp="value"
              >
                <Input
                  prefix={<UserOutlined style={{ color: 'rgba(0,0,0,.25)' }} />}
                  placeholder={dict['username'] || '用户名'}
                  autoComplete="off"
                />
              </AutoComplete>
            )}
          </Form.Item>
          <Form.Item>
            {getFieldDecorator('password', {
              initialValue: this.state.password || '',
              rules: [
                {
                  required: true,
                  message: dict['password_required'] || '请输入密码',
                }
              ]
            })(<Input.Password placeholder={dict['password'] || '密码'} visibilityToggle={vispwd} prefix={<LockOutlined style={{ color: 'rgba(0,0,0,.25)' }} />} />)}
          </Form.Item>
          {window.GLOB.keepKey ? <Form.Item className="minline">
            {getFieldDecorator('remember', {
              valuePropName: 'checked',
              initialValue: remember,
            })(<Checkbox onChange={this.rememberChange}>{dict['remember_me'] || '记住密码'}</Checkbox>)}
          </Form.Item> : <div style={{height: '30px', float: 'left'}}></div>}
          {langList && langList.length > 0 ? <Form.Item className="minline right">
            {getFieldDecorator('lang', {
              initialValue: lang,
            })(
              <Select
                onChange={(value) => {this.changelang(value)}}
                getPopupContainer={() => document.getElementById('login-form')}
              >
                {langList.map((item, index) => {
                  return <Select.Option key={index} value={item.Lang}>{item.LangName}</Select.Option>
                })}
              </Select>
            )}
          </Form.Item> : null}
          <Form.Item className="btn-login">
            <Button type="primary" htmlType="submit" className="login-form-button" disabled={isDisabled} loading={isDisabled}>
            {dict['log_in'] || '登录'}
            </Button>
          </Form.Item>
        </div>
      </Form>
    )
  }
}
 
export default Form.create()(LoginTabForm)