index.js 1.2 KB
Newer Older
zhanghaozhe committed
1 2 3 4 5 6 7 8 9
import React, { Component } from 'react';
import './index.scss'
import { initCaptchaNC } from "@/utils"

const appkey = 'FFFF0N000000000090FC'
const scene = 'nc_login_h5'

class CaptchaAli extends Component {
  nc = null
10
  el = null
zhanghaozhe committed
11 12 13 14 15 16
  state = {
    isLoaded: false
  }

  componentDidMount() {
    const _this = this
17
    this.el && initCaptchaNC(() => {
zhanghaozhe committed
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
      const nc_token = [appkey, (new Date()).getTime(), Math.random()].join(':');
      this.nc = NoCaptcha.init({
        renderTo: '#nc',
        appkey,
        scene,
        token: nc_token,
        elementID: ['tel'],
        bannerHidden: false,
        callback(data) {
          _this.props.onVerify({
            app_key: appkey,
            scene,
            token: nc_token,
            session_id: data.csessionid,
            sig: data.sig
          })
        },
        error(s) {
          console.log(s)
        }
      })
      NoCaptcha.setEnabled(true);
      this.nc.reset()
      this.props.getInstance(this.nc)
    })
  }

  render() {
    const {mb = 30} = this.props
    return (
      <div id={'captcha'} style={{marginBottom: `${mb}px`}}>
49
        <div id="nc" ref={el => this.el = el}></div>
zhanghaozhe committed
50 51 52 53 54 55
      </div>
    );
  }
}

export default CaptchaAli;