weaver_trunk_cli/pc4mobx/hrm/components/secondaryVerification4em/index.js

133 lines
4.7 KiB
JavaScript

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 (
<div style={{width: '100%', height: '100%', display: 'table'}}>
<div style={{display: 'table-cell', verticalAlign: 'middle', textAlign: 'center'}}>
<div style={{paddingBottom: '10px'}}>{getLabel('534749','已启用真实身份认证')}</div>
<div style={{paddingBottom: '10px'}}>{getLabel('534571','请扫描下方二维码进行验证')}</div>
<WeaQrcode text={`${authUrl}`} size={200}/>
</div>
</div>
)
}
}