已解决!
话不多说,直接上代码!
<template>
<div class="LoginSanfang" v-show="!iswx">
<h3> 第三方账号登录</h3>
<div style="margin-top: .4rem;">
<span style="margin-right: 1rem;"><img :src="require('@/assets/img/account/qqbg.png')" alt="" @click="qqlogin"></span>
<span><img :src="require('@/assets/img/account/wechatbg.png')" alt="" @click="weixinlogin"></span>
</div>
<span id="qqLoginBtn"></span>
</div>
</template>
export default {
name: 'LoginSanfang',
data() {
return {
timeOut: '',
iswx: false,
qq: null,
auths: null,
aweixin: null,
}
},
beforeCreate() {
function plusready() {
this.updateServices();
}
if (window.plus) {
plusready();
} else {
document.addEventListener("plusready", plusready, false);
}
},
methods: {
//判断是否为微信浏览器
isweixin() {
const ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
this.iswx = true;
return true;
} else {
this.iswx = false;
return false;
}
},
//更新oauth服务
updateServices() {
let _self = this;
plus.oauth.getServices(function(services) {
_self.auths = services;
for (var i in services) {
if ('weixin' == services[i].id) {
_self.aweixin = services[i];
}
}
for (var i in services) {
if ('qq' == services[i].id) {
_self.aqq = services[i];
}
}
}, function(e) {
plus.nativeUI.alert("获取登录授权服务列表失败:" + JSON.stringify(e));
});
},
//拉起QQ客户端
qqlogin() {
this.aqq.login(function(e){
console.log(e)
plus.nativeUI.alert("授权成功:"+JSON.stringify(e));
}, function(e) {
console.log(e)
plus.nativeUI.alert("授权失败:"+JSON.stringify(e));
});
},
//微信授权登录
weixinlogin() {
this.aweixin.login(function(e){
console.log(e)
plus.nativeUI.alert("授权成功:"+JSON.stringify(e));
}, function(e) {
console.log(e)
plus.nativeUI.alert("授权失败:"+JSON.stringify(e));
});
}
},
mounted() {
this.isweixin();
if(window.plus) this.updateServices();
}
}