


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)
}
}
};
源碼視圖做配置
