/**
* 域账户一键登录
*/
initWebSocket () { // 初始化weosocket
if (window['WebSocket']) {
if (this.websock !== null && this.websock.readyState === 1) {
this.websock.send('ad')
return
}
// websocket主要分为四步
// 1.打开数据
// 2.接收数据
// 3.断开连接
// 4.连接失败
// this.wsUri:这里是websocket接口地址
this.websock = new WebSocket(this.wsUri) //这里面的this都指向vue
this.websock.onmessage = this.websocketonmessage //客户端接收服务端数据时触发
this.websock.onerror = this.websocketonerror //通信发生错误时触发
this.websock.onopen = this.websocketonopen //连接建立时触发
} else {
this.$showNotification('error', '信息', '当前浏览器不支持websocket协议,建议使用Chrome浏览器')
}
},
/**
* 打开链接
*/
websocketonopen () {
console.log('链接成功!')
this.websock.send('ad')
},
send () {
this.websock.send('ad')
},
/**
* 连接失败
*/
websocketonerror () {
this.notInstallPlugin = true
console.log('链接异常!')
// this.$showNotification('error', '信息', '请检查一键登录插件安装情况')
this.isLoginError = true
this.errMsg = '请检查一键登录插件安装情况'
},
/**
* 数据接收
*/
websocketonmessage (e) {
const data = e.data
if (data === '获取失败') {
// this.$showNotification('error', '信息', '数据获取异常,请检查插件状态或使用账号密码登录')
this.isLoginError = true
this.errMsg = '数据获取异常,请检查插件状态或使用账号密码登录'
} else {
// 数据链接的方法
const {
ADLogin
} = this
ADLogin({ 'account': data })
.then((res) => this.loginSuccess(res))
.catch(err => this.requestFailed(err))
.finally(() => {
})
}
},