king
2021-09-01 31ec63f0419895876cbaba99637a884a32d33d0d
src/views/login/loginform.jsx
@@ -1,25 +1,28 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Form, Icon, Input, Button, Checkbox, Select, Modal, Tabs, message } from 'antd'
import { Form, Icon, Input, Button, Checkbox, Select, Modal, message } from 'antd'
import md5 from 'md5'
import moment from 'moment'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import options from '@/store/options.js'
import asyncLoadComponent from '@/utils/asyncLoadComponent'
import './index.scss'
const { warning } = Modal
const { TabPane } = Tabs
let LoginVerCodeTimer = null
const QrCode = asyncLoadComponent(() => import('@/components/qrcode'))
class LoginTabForm extends Component {
  static propTpyes = {
    isDisabled: PropTypes.bool,
    changelang: PropTypes.func,
    handleSubmit: PropTypes.func,
    authLogin: PropTypes.func,
    dict: PropTypes.object,
    auth: PropTypes.bool,
    authError: PropTypes.string,
    touristLogin: PropTypes.bool,
    lang: PropTypes.string,
    langList: PropTypes.array,
@@ -29,14 +32,19 @@
  state = {
    activeKey: 'uname_pwd',
    scanId: '',
    username: '',
    password: '',
    remember: true,
    delay: null,
    loginWays: [],
    smsId: '',
    verdisabled: false
    verdisabled: false,
    timeout: false
  }
  timer = null
  splitTime = 0
  UNSAFE_componentWillMount () {
    const { loginWays } = this.props
@@ -55,36 +63,64 @@
        _loginWays.push(item)
      } else if (item.type === 'uname_pwd') {
        _loginWays.push(item)
      } else if (item.type === 'app_scan') {
        _loginWays.push(item)
      }
    })
    let activeKey = _loginWays[0].type
    this.setState({
      smsId: smsId,
      loginWays: _loginWays,
      activeKey: _loginWays[0].type,
      activeKey,
      scanId: activeKey === 'app_scan' ? Utils.getuuid() : '',
      timeout: false,
      remember
    })
    if (activeKey === 'app_scan') {
      this.splitTime = 0
      this.timer = setTimeout(() => {
        this.checkResult()
      }, 10000)
    }
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (!is(fromJS(this.props.loginWays), fromJS(nextProps.loginWays))) {
      let smsId = ''
      let _loginWays = []
      nextProps.loginWays.forEach(item => {
        if (item.type === 'sms_vcode') {
          smsId = item.smsId
          _loginWays.push(item)
        } else if (item.type === 'uname_pwd') {
          _loginWays.push(item)
        }
      })
  checkResult = () => {
    const { scanId } = this.state
      this.setState({
        smsId: smsId,
        loginWays: _loginWays,
        activeKey: _loginWays[0].type
      })
    this.splitTime += 10000
    let _param = {
      func: 'webapi_get_binding_key',
      scan_type: 'pc',
      id: scanId,
      UserName: ''
    }
    _param.userid = sessionStorage.getItem('visitorUserID')
    _param.LoginUID = sessionStorage.getItem('visitorLoginUID')
    if (this.splitTime >= 180000) {
      this.setState({
        timeout: true
      })
      return
    }
    Api.getSystemConfig(_param).then(res => {
      if (!res.status) {
        message.warning(res.message)
        return
      } else if (res.thd_party_appid && res.thd_party_member_id && res.thd_party_openid) {
        this.props.authLogin(res.thd_party_appid, res.thd_party_openid, res.thd_party_member_id, scanId)
      } else {
        this.timer = setTimeout(() => {
          this.checkResult()
        }, 10000)
      }
    })
  }
  handleConfirm = () => {
@@ -111,9 +147,9 @@
    e.preventDefault()
    if (!this.props.auth) {
      warning({
        title: this.props.dict['login.auth.tip'],
        okText: this.props.dict['login.auth.ok'],
        cancelText: this.props.dict['login.auth.cancel'],
        title: this.props.authError || this.props.dict['login.auth.tip'],
        okText: this.props.dict['login.ok'],
        cancelText: this.props.dict['login.cancel'],
        onOk() {},
        onCancel() {}
      })
@@ -158,7 +194,7 @@
    if (_user) {
      try {
        _user = JSON.parse(window.decodeURIComponent(window.atob(_user)))
      } catch {
      } catch (e) {
        console.warn('Parse Failure')
        _user = ''
      }
@@ -183,7 +219,29 @@
  }
  onChangeTab = (activeKey) => {
    this.setState({activeKey})
    this.setState({activeKey, scanId: activeKey === 'app_scan' ? Utils.getuuid() : ''})
    if (this.state.activeKey === 'app_scan') {
      this.timer && clearTimeout(this.timer)
    }
    if (activeKey === 'app_scan') {
      this.splitTime = 0
      this.setState({timeout: false})
      this.timer = setTimeout(() => {
        this.checkResult()
      }, 10000)
    }
  }
  reCode = () => {
    this.splitTime = 0
    this.setState({timeout: false, scanId: Utils.getuuid()})
    this.timer = setTimeout(() => {
      this.checkResult()
    }, 10000)
  }
  getvercode = () => {
@@ -200,30 +258,61 @@
      return
    }
    let param = {
      func: 'MSN_sms_send_code',
    let _param = {
      func: 'mes_sms_send_code_sso',
      send_type: 'login',
      mob: _phone,
      timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
      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') || ''
    param.LText = md5(`${_phone}mingke${window.GLOB.appkey}${param.timestamp}`)
    param.secretkey = md5(`${param.LText}mingke${param.timestamp}`)
    Api.getSystemConfig(_param).then(res => {
      if (!res.status || !res.n_id) {
        message.warning(res.message || '验证码获取失败!')
        return
      }
    param.userid = sessionStorage.getItem('visitorUserID') || ''
    param.LoginUID = sessionStorage.getItem('visitorLoginUID') || ''
      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}`)
    this.setState({
      verdisabled: true,
      delay: 60
    })
    LoginVerCodeTimer = setTimeout(this.resetVerCodeDelay, 1000)
    Api.getSystemConfig(param).then(res => {
      if (res.status) {
      } else {
      param.rduri = 'http://sso.mk9h.cn/webapi/dostars'
      param.userid = 'bh0bapabtd45epsgra79segbch6c1ibk'
      param.LoginUID = 'bh0bapabtd45epsgra79segbch6c1ibk'
      this.setState({
        verdisabled: true,
        delay: 60
      })
      LoginVerCodeTimer = setTimeout(this.resetVerCodeDelay, 1000)
      Api.getLocalConfig(param).then(res => {
        if (res.status) {
        } else {
          if (LoginVerCodeTimer) {
            clearTimeout(LoginVerCodeTimer)
          }
          this.setState({
            verdisabled: false,
            delay: null
          })
          message.warning(res.message)
        }
      }, () => {
        if (LoginVerCodeTimer) {
          clearTimeout(LoginVerCodeTimer)
        }
@@ -231,15 +320,6 @@
          verdisabled: false,
          delay: null
        })
        message.warning(res.message)
      }
    }, () => {
      if (LoginVerCodeTimer) {
        clearTimeout(LoginVerCodeTimer)
      }
      this.setState({
        verdisabled: false,
        delay: null
      })
    })
  }
@@ -275,13 +355,15 @@
  render() {
    const { getFieldDecorator } = this.props.form
    const { activeKey, verdisabled, delay, loginWays, remember } = this.state
    const { activeKey, verdisabled, delay, loginWays, remember, scanId, timeout } = this.state
    return (
      <Form className={`login-form login-form-${loginWays.length}`} id="login-form" onSubmit={this.handleSubmit}>
        <Tabs type="card" activeKey={activeKey} onChange={this.onChangeTab}>
          {loginWays.map(item => (<TabPane tab={item.label} key={item.type}></TabPane>))}
        </Tabs>
      <Form className="login-form" id="login-form" onSubmit={this.handleSubmit}>
        <div className={'login-way-wrap ' + (loginWays.length === 1 ? 'simple' : '')}>
          {loginWays.map(item => (
            <div className={'login-way' + (activeKey === item.type ? ' active' : '')} onClick={() => this.onChangeTab(item.type)} key={item.type}>{item.label}</div>
          ))}
        </div>
        <div className="form-item-wrap">
          {activeKey === 'uname_pwd' ? <Form.Item>
            {getFieldDecorator('username', {
@@ -317,7 +399,7 @@
              />
            )}
          </Form.Item> : null}
          {activeKey === 'sms_vcode' ? <Form.Item>
          {activeKey === 'sms_vcode' ? <Form.Item className="vercode">
            {getFieldDecorator('vercode', {
              initialValue: '',
              rules: [
@@ -344,7 +426,7 @@
              initialValue: remember,
            })(<Checkbox onChange={this.rememberChange}>{this.props.dict['login.remember']}</Checkbox>)}
          </Form.Item> : null}
          {this.props.langList && this.props.langList.length > 0 ? <Form.Item className="minline right">
          {activeKey !== 'app_scan' && this.props.langList && this.props.langList.length > 0 ? <Form.Item className="minline right">
            {getFieldDecorator('lang', {
              initialValue: this.props.lang,
            })(
@@ -363,7 +445,17 @@
              {this.props.dict['login.submit']}
            </Button>
          </Form.Item> : null}
          {options.sysType === 'cloud' ? <Form.Item className="register-line">
          {activeKey === 'app_scan' ? <div className="form-scan-wrap">
            <div className="qr-wrap">
              {scanId ? <QrCode card={{qrWidth: 500, color: '#000000'}} value={`mkpcscan,${window.GLOB.appkey},${scanId}`}/> : null}
              {timeout ? <div className="qrcode-out">
                <Icon onClick={this.reCode} type="redo" />
                二维码已失效。
              </div> : null}
            </div>
            请使用客户端扫一扫登录
          </div> : null}
          {options.sysType === 'cloud' && options.cdomain.indexOf('mk9h') > -1 ? <Form.Item className="register-line">
            <a href="http://minkesoft.com/#/signup" target="_blank" rel="noopener noreferrer" className="register">注册</a>
            <a href="http://minkesoft.com/#/forgotPwd" target="_blank" rel="noopener noreferrer" className="forgot">忘记密码?</a>
          </Form.Item> : null}