详细问题描述
[内容]
重现步骤
[步骤]
[结果]
[期望]
[mui版本]
附件
[代码片段]
[安装包]
联系方式
[QQ]
[电话] 13428938048
<html>
<head>
<meta charset="utf-8">
<title>Hello MUI</title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!--标准mui.css-->
<link rel="stylesheet" href="../css/mui.min.css">
<link rel="stylesheet" href="../css/mui.css" />
<!--App自定义的css-->
<style type="text/css">
.head {
margin-top: 10px;
}
.head img{
width: 120px;
height: 120px;
margin-left: calc(50% - 60px);
}
.top {
margin-top: 40px;
}
.sinaweibo {
position: relative;
width: 60px;
height: 60px;
margin-left: calc(50% - 30px);
background: url(../images/icon-sina.png);
}
.weixin {
width: 60px;
height: 60px;
margin-left: calc(50% - 30px);
background: url(../images/icon-weixin.png);
}
.qq {
width: 60px;
height: 60px;
margin-left: calc(50% - 30px);
background: url(../images/icon-qq.png);
}
</style>
</head>
<body>
<header class="mui-bar mui-bar-nav">
<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
<h1 class="mui-title">第三方登录</h1>
</header>
<div class="mui-content">
<div class="head">
<img src="../images/Icon@2x.png" id="headImage"/>
</div>
<div class="top" id="testLogin">
<span class="mui-icon weixin" id="weixin"></span>
<a><span class="mui-icon qq" id="qq"></span>
<span class="mui-icon sinaweibo" id="sinaweibo"></span>
</div>
</div>
</body>
<script src="../js/mui.min.js"></script>
<script src="../js/mui.zoom.js"> </script>
<script src="../js/mui.previewimage.js"></script>
<script src="../js/tools.js" ></script>
<script>
// 获取用户头像标签
var headImage = document.getElementById('headImage');
mui.init({
swipeBack:true //启用右滑关闭功能
});
mui.plusReady(function() {
plus.oauth.getServices(function(services) {
auths = services;
}, function(e) {
alert("获取登录服务列表失败:" + e.message + " - " + e.code);
});
})
document.getElementById('weixin').addEventListener('tap',function() {
console.log("微信");
authLogin('weixin');
})
document.getElementById('qq').addEventListener('tap',function() {
console.log("QQ");
authLogin('qq');
})
document.getElementById('sinaweibo').addEventListener('tap',function() {
console.log("微博");
authLogin('sinaweibo');
})
// 登录操作
function authLogin(type) {
var s;
for (var i = 0; i < auths.length; i++) {
if (auths[i].id == type) {
s = auths[i];
break;
}
}
if (!s.authResult) {
s.login(function(e) {
mui.toast("登录认证成功!");
authUserInfo(type);
}, function(e) {
mui.toast("登录认证失败!");
});
} else {
mui.toast("已经登录认证!");
}
}
//注销
function authLogout() {
for (var i in auths) {
var s = auths[i];
if (s.authResult) {
s.logout(function(e) {
console.log("注销登录认证成功!");
}, function(e) {
console.log("注销登录认证失败!");
});
}
}
}
// 微信登录认证信息
function authUserInfo(type) {
var s;
for (var i = 0; i < auths.length; i++) {
if (auths[i].id == type) {
s = auths[i];
break;
}
}
if (!s.authResult) {
mui.toast("未授权登录!");
} else {
s.getUserInfo(function(e) {
var josnStr = JSON.stringify(s.userInfo);
var jsonObj = s.userInfo;
console.log("获取用户信息成功:" + josnStr);
showData(type,jsonObj);
authLogout();
}, function(e) {
alert("获取用户信息失败:" + e.message + " - " + e.code);
});
}
}
// 显示用户头像信息
function showData(type,data) {
switch (type){
case 'weixin':
headImage.src = data.headimgurl;
break;
case 'qq':
headImage.src = data.figureurl_qq_2;
break;
case 'sinaweibo':
headImage.src = data.avatar_large;
break;
default:
break;
}
}
</script>
</html>
0 个回复