this.setState({
image:`data:image/jpeg;base64,${res.data.result.image}`,
ticket:res.data.result.ticket,
websocketUrl:`wss://api.xxxxxx.com/socket/login/${res.data.result.ticket}`
},()=>{
this.getSocket()
})
getSocket(){
socket=new WebSocket(this.state.websocketUrl);
socket.onopen=this.getOpen.bind(this)
socket.onmessage=this.getMessage.bind(this)
}
getOpen(){
console.log('已连接...')
}
getMessage(data){
let result = JSON.parse(data.data);
if(result.category=="Scan"){
this.setState({
mask:true
})
}
if(result.category=="Login" && result.message.access_token!=''){
message.success('验证成功 准备跳转中...');
sessionStorage.setItem('time',6000)
sessionStorage.setItem('access_token',result.message.access_token)
sessionStorage.setItem('refresh_token',result.message.refresh_token)
this.logintimer = setTimeout(() => {
this.props.history.push('/HomePage');
},3000);
}
}
|