import React, {Component} from 'react' import {message} from 'antd'; import { WeaTools, WeaLocaleProvider, WeaQrcode } from 'ecCom'; const {callApi} = WeaTools; const {getLabel} = WeaLocaleProvider; //获取二次验证表单 const getForm = (params = {}) => callApi('/api/encrypt/secondauthsetting/getSecondAuthForm', 'POST', params); //轮训qys状态 const checkQYSStatus = (params = {}) => callApi('/api/encrypt/secondauthsetting/checkqysLogin', 'POST', params); //二次验证 const doSecondAuth = (params = {}) => callApi('/api/encrypt/secondauthsetting/doSecondAuth', 'POST', params); const defualtParams = {mouldCode: 'EM', itemCode: 'MESSAGE'}; const getDialogInfo = () => { return top.window.getParentDialog(); } export default class SecondaryVerification4em extends Component { constructor(props){ super(props); this.state = { authId: '', authUrl: '', qysAuthType: '' } } componentDidMount(){ this.init(); } init = () => { getForm(defualtParams).then(data => { if(data.status == '1'){ const {authId, authUrl, qysAuthType, authType} = data; if(authType == 50){ this.setState({authId, authUrl, qysAuthType}); this.monitor(); } }else{ message.error(data.message); } }) } monitor = () => { this.timer && clearInterval(this.timer); this.timer = setInterval(() => { checkQYSStatus({authId: this.state.authId}).then(data => { if(data.status == '1'){ if(data.code == '1'){ clearInterval(this.timer); doSecondAuth({...defualtParams, authId: this.state.authId}).then(data => { if(data.checkStatus == '1'){ this.onCloseHandle(data.token); } }) } }else{ message.error(data.message); clearInterval(this.timer); } }) }, 2000); } // init = () => { // window.doCheckSecondaryVerify4ec && window.doCheckSecondaryVerify4ec({mouldCode: 'EM', itemCode: 'MESSAGE'}, data => { // if(isEmpty(data)) // return; // const {status, token} = data; // if(status == '1'){ // window.em && window.em.ready(() => { // window.em.invoke && window.em.invoke('setauthtag', { // authtag: token, //string 类型。必填,校验令牌 // success: res => { // const {errCode, errMsg} = res; // if(errCode == 0){ // this.onCloseHandle(); // }else // message.error(JSON.stringify(errMsg)); // } // }) // }) // }else{ // } // }) // } onCloseHandle = (token) => { if(window.em){ window.em.ready(() => { window.em.invoke && window.em.invoke('setauthtag', { authtype: 1, authtag: token, //string 类型。必填,校验令牌 success: res => { const {errCode, errMsg} = res; if(errCode == 0){ window.em.closeWindow && window.em.closeWindow(); }else message.error(JSON.stringify(errMsg)); } }) }) }else{ // message.error('em not found'); const dia = getDialogInfo(); if(dia){ dia.callback && dia.callback({status: '1', token}); dia.close(); } } } render() { const {authUrl} = this.state; if(authUrl == null || authUrl == '') return null; return (