vue移動(dòng)端app開發(fā)實(shí)現(xiàn)微信,QQ,新浪微博登錄

export default { name: 'Login', data() { return { username: '', password: "", auths:null,//初始化 headerimg:require("../../assets/images/logoleyi.png") } }, computed: { ...mapState({ items: state => store.state.autoLogin.item, }) }, created: function() { this.huocode() }, methods: { ...mapActions("user",["loginuser"]), ...mapActions("autoLogin",["authLogin"]), ...mapMutations("autoLogin",["getAuths"]), async login() { if (this.username == "" || this.password == "") { Toast("輸入框不能為空") return } let payload = { body: { umobile:this.username, upassword:this.password, }, callback:this.completed } this.loginuser(payload) }, completed(){ this.$router.push('/main') }, huocode(){ // this.getAuths() let that=this; document.addEventListener('plusready', function() { plus.oauth.getServices(function(services) { console.log(services) that.auths = services; }, function(e) { alert("獲取登錄服務(wù)列表失?。? + e.message + " - " + e.code); }); }) }, loginclick(name){ this.authLogin(name); }, authLogin(type){ let that=this; let s; for (var i = 0; i < that.auths.length; i++) { if (that.auths[i].id == type) { s = that.auths[i]; break; } } if (!s.authResult) { s.login(function(e) { Toast("登錄認(rèn)證成功!"); that.authUserInfo(type); }, function(e) { Toast("登錄認(rèn)證失敗!"); }); } else { Toast("已經(jīng)登錄認(rèn)證!"); } }, authUserInfo(type) { let that=this; var s; for (var i = 0; i < that.auths.length; i++) { if (that.auths[i].id == type) { s = that.auths[i]; break; } } if (!s.authResult) { Toast("未授權(quán)登錄!"); } else { s.getUserInfo(function(e) { var josnStr = JSON.stringify(s.userInfo); var jsonObj = s.userInfo; console.log("獲取用戶信息成功:" + josnStr); that.showData(type,jsonObj); that.authLogout(); }, function(e) { alert("獲取用戶信息失敗:" + e.message + " - " + e.code); }); } }, authLogout() { for (var i in that.auths) { var s = that.auths[i]; if (s.authResult) { s.logout(function(e) { console.log("注銷登錄認(rèn)證成功!"); }, function(e) { console.log("注銷登錄認(rèn)證失??!"); }); } } }, showData(type,data) { let that=this; switch (type){ case 'weixin': that.headImage= data.headimgurl; break; case 'qq': that.headImage = data.figureurl_qq_2; break; case 'sinaweibo': that.headImage = data.avatar_large; break; default: break; } } }, watch:{ items(){ console.log("獲取內(nèi)容"+this.items) } } };

源碼視圖做配置

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容