login() {
let _this = this;
// 获取 univerifyManager 实例
const univerifyManager = uni.getUniverifyManager();
// 预登录
univerifyManager.preLogin({
success: (res) => {
univerifyManager.offButtonsClick();
univerifyManager.onButtonsClick(callback);
// 预登录成功后,调用一键登录弹框
univerifyManager.login({
univerifyStyle: {
"fullScreen": true, // 是否全屏显示,true表示全屏模式,false表示非全屏模式,默认值为false。
"backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff
"phoneNum": {
"color": "#000000", // 手机号文字颜色 默认值:#000000
},
"icon": {
"path": "static/logLogin.png" ,
'width':'180px'
},
"slogan": {
"color": "#8a8b90", // slogan 字体颜色 默认值:#8a8b90
},
"authButton": {
"normalColor": "#3479f5", // 授权按钮正常状态背景颜色 默认值:#3479f5
"highlightColor": "#2861c5", // 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
"disabledColor": "#73aaf5", // 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
"textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff
"title": "本机号码一键登录" // 授权按钮文案 默认值:“本机号码一键登录”
},
"otherLoginButton": {
"visible": "true", // 是否显示其他登录按钮,默认值:true
},
"privacyTerms": {
defaultCheckBoxState: "false", // 条款勾选框初始状态 默认值: true
textColor: "#707070", // 文字颜色 默认值:#8a8b90
termsColor: "#FFBB24", // 协议文字颜色 默认值: #1d4788
prefix: "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
suffix: "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
fontSize: "12", // 字体大小 默认值:12
"privacyItems": [{
"url": 'https://uniapp.dcloud.net.cn/univerify.html#%E6%A6%82%E8%BF%B0',
"title": "APP隐私政策"
}]
},
"buttons": {
"iconWidth": "45px",
"list": [{
"provider": "weixin",
'iconPath': '/static/image/login/wx_logo.jpeg',
}]
}
},
success: (res) => {
uniCloud.callFunction({
name: 'getPhoneNumber', // 你的云函数名称
data: {
access_token: res.authResult
.access_token, // 客户端一键登录接口返回的access_token
openid: res.authResult.openid // 客户端一键登录接口返回的openid
}
}).then(dataRes => {
console.log('dataRes', dataRes)
// 在此处调用接口登录
this.registerLogin('oneLogin', dataRes.result.data
.phoneNumber);
}).catch(err => {
console.log('云函数报错', err)
uni.showToast({
title: err,
icon: none
})
})
uni.showToast({
title: res.authResult,
icon: "none"
})
},
});
},
fail(res) { // 预登录失败
// 不显示一键登录选项(或置灰)
// 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
console.log(res.errCode)
console.log(res.errMsg)
if (res.errCode == 30005) {
uni.$u.toast('获取一键登录失败,请检查当前手机是否有手机卡/开启流量/或手机卡是否欠费')
}
}
})
const callback = (res) => {
// 检查一键登录弹框协议勾选状态
univerifyManager.getCheckBoxState({
success(res) {
console.log("getCheckBoxState res: ", res);
if (res.state) {
console.log("微信登录");
// 关闭一键登录弹框
_this.wxpush();
} else {
uni.$u.toast("请同意服务条款")
}
}
});
};
},