
- 发布:2022-07-28 11:25
- 更新:2022-07-28 11:25
- 阅读:661
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: -
HBuilderX类型: 正式
HBuilderX版本号: 3.4.18
手机系统: 全部
手机系统版本号: Android 12
手机厂商: 华为
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
测试过的手机:
示例代码:
oneClickLogin() {
let than = this
uni.getProvider({
service: 'oauth',
success: function (res) {
// console.log(res.provider)// ['qq', 'univerify']
if (~res.provider.indexOf('univerify')) {
uni.login({
provider: 'univerify',
univerifyStyle: {
"fullScreen": true, // 是否全屏显示,默认值: false
"backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff
"backgroundImage": "", // 全屏显示的背景图片,默认值:"" (仅支持本地图片,只有全屏显示时支持)
"icon": {
"path": "/static/shop_logo.png" // 自定义显示在授权框中的logo,仅支持本地图片 默认显示App logo
},
"phoneNum": {
"color": "#202020" // 手机号文字颜色 默认值:#202020
},
"slogan": {
"color": "#BBBBBB" // slogan 字体颜色 默认值:#BBBBBB
},
"authButton": {
"normalColor": "#FC6035", // 授权按钮正常状态背景颜色 默认值:#3479f5
"highlightColor": "#FC6035", // 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
"disabledColor": "#FC6035", // 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
"textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff
"title": "本机号码一键登录", // 授权按钮文案 默认值:“本机号码一键登录”
"borderRadius": "24px" // 授权按钮圆角 默认值:"24px" (按钮高度的一半)
},
"otherLoginButton": {
"visible": true, // 是否显示其他登录按钮,默认值:true
"normalColor": "#F4F4F4", // 其他登录按钮正常状态背景颜色 默认值:透明
"highlightColor": "#F1F1F1", // 其他登录按钮按下状态背景颜色 默认值:透明
"textColor": "#111111", // 其他登录按钮文字颜色 默认值:#656565
"title": "开店", // 其他登录方式按钮文字 默认值:“其他登录方式”
"borderColor": "#F4F4F4", //边框颜色 默认值:透明(仅iOS支持)
"borderRadius": "24px" // 其他登录按钮圆角 默认值:"24px" (按钮高度的一半)
},
"privacyTerms": {
"defaultCheckBoxState":false, // 条款勾选框初始状态 默认值: true
"uncheckedImage":"", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
"checkedImage":"", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
"textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
"termsColor": "#5496E3", // 协议文字颜色 默认值: #5496E3
"prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
"suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
"privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
{
"url": "https://uxianxin.com/treaty/index.html?10004", // 点击跳转的协议详情页面
"title": "隐私政策" // 协议名称
},
{
"url": "https://uxianxin.com/treaty/index.html?10013", // 点击跳转的协议详情页面
"title": "商家服务协议" // 协议名称
}
]
},
"buttons": { // 自定义页面下方按钮仅全屏模式生效(3.1.14+ 版本支持)
"iconWidth": "35px", // 图标宽度(高度等比例缩放) 默认值:45px
"list": than.buttonList
}
},
success(loginres){ // 登录成功
// console.log(res);
// console.log(res.authResult); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
uniCloud.callFunction({
name: 'getPhoneFunction', // 你的云函数名称
data: {
access_token: loginres.authResult.access_token, // 客户端一键登录接口返回的access_token
openid: loginres.authResult.openid // 客户端一键登录接口返回的openid
}
}).then(Phoneres => {
// console.log(Phoneres)
// console.log('/////////////////////////////')
// console.log(Phoneres.result)
// console.log('=========================')
if (Phoneres.result.code === 200) {
uni.clearStorageSync();
uni.closeAuthView()
than.loginDataGo(Phoneres.result)
} else if (Phoneres.result.code == 204){
than.$u.toast(Phoneres.result.msg);
setTimeout(function () {
uni.closeAuthView()
than.gotoRegist()
}, 1500);
} else {
than.$u.toast(res.msg);
uni.closeAuthView()
// than.$u.toast("登录失败,请重新登录");
}
}).catch(err=>{
// 处理错误
})
},
fail(failres){ // 登录失败
// console.log(failres)
if(failres.code === 30002){
// than.$u.toast("其他按钮");
uni.closeAuthView()
than.gotoRegist()
// uni.showToast({
// title: failres.msg,
// duration:2000, mask:false, icon:'none'
// });
// setTimeout(function () {
// uni.closeAuthView()
// than.gotoRegist()
// }, 2000);
} else if(failres.index === 0){
// console.log("手机")
uni.closeAuthView()
}
// if(failres.index === 0){
// console.log("手机")
// uni.closeAuthView()
// }else if(failres.index === 1){
// than.login_weixin()
// } else if(failres.index == 2){
// than.login_apple()
// }
}
})
}
}
})
},
oneClickLogin() {
let than = this
uni.getProvider({
service: 'oauth',
success: function (res) {
// console.log(res.provider)// ['qq', 'univerify']
if (~res.provider.indexOf('univerify')) {
uni.login({
provider: 'univerify',
univerifyStyle: {
"fullScreen": true, // 是否全屏显示,默认值: false
"backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff
"backgroundImage": "", // 全屏显示的背景图片,默认值:"" (仅支持本地图片,只有全屏显示时支持)
"icon": {
"path": "/static/shop_logo.png" // 自定义显示在授权框中的logo,仅支持本地图片 默认显示App logo
},
"phoneNum": {
"color": "#202020" // 手机号文字颜色 默认值:#202020
},
"slogan": {
"color": "#BBBBBB" // slogan 字体颜色 默认值:#BBBBBB
},
"authButton": {
"normalColor": "#FC6035", // 授权按钮正常状态背景颜色 默认值:#3479f5
"highlightColor": "#FC6035", // 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
"disabledColor": "#FC6035", // 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
"textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff
"title": "本机号码一键登录", // 授权按钮文案 默认值:“本机号码一键登录”
"borderRadius": "24px" // 授权按钮圆角 默认值:"24px" (按钮高度的一半)
},
"otherLoginButton": {
"visible": true, // 是否显示其他登录按钮,默认值:true
"normalColor": "#F4F4F4", // 其他登录按钮正常状态背景颜色 默认值:透明
"highlightColor": "#F1F1F1", // 其他登录按钮按下状态背景颜色 默认值:透明
"textColor": "#111111", // 其他登录按钮文字颜色 默认值:#656565
"title": "开店", // 其他登录方式按钮文字 默认值:“其他登录方式”
"borderColor": "#F4F4F4", //边框颜色 默认值:透明(仅iOS支持)
"borderRadius": "24px" // 其他登录按钮圆角 默认值:"24px" (按钮高度的一半)
},
"privacyTerms": {
"defaultCheckBoxState":false, // 条款勾选框初始状态 默认值: true
"uncheckedImage":"", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
"checkedImage":"", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
"textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
"termsColor": "#5496E3", // 协议文字颜色 默认值: #5496E3
"prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
"suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
"privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
{
"url": "https://uxianxin.com/treaty/index.html?10004", // 点击跳转的协议详情页面
"title": "隐私政策" // 协议名称
},
{
"url": "https://uxianxin.com/treaty/index.html?10013", // 点击跳转的协议详情页面
"title": "商家服务协议" // 协议名称
}
]
},
"buttons": { // 自定义页面下方按钮仅全屏模式生效(3.1.14+ 版本支持)
"iconWidth": "35px", // 图标宽度(高度等比例缩放) 默认值:45px
"list": than.buttonList
}
},
success(loginres){ // 登录成功
// console.log(res);
// console.log(res.authResult); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
uniCloud.callFunction({
name: 'getPhoneFunction', // 你的云函数名称
data: {
access_token: loginres.authResult.access_token, // 客户端一键登录接口返回的access_token
openid: loginres.authResult.openid // 客户端一键登录接口返回的openid
}
}).then(Phoneres => {
// console.log(Phoneres)
// console.log('/////////////////////////////')
// console.log(Phoneres.result)
// console.log('=========================')
if (Phoneres.result.code === 200) {
uni.clearStorageSync();
uni.closeAuthView()
than.loginDataGo(Phoneres.result)
} else if (Phoneres.result.code == 204){
than.$u.toast(Phoneres.result.msg);
setTimeout(function () {
uni.closeAuthView()
than.gotoRegist()
}, 1500);
} else {
than.$u.toast(res.msg);
uni.closeAuthView()
// than.$u.toast("登录失败,请重新登录");
}
}).catch(err=>{
// 处理错误
})
},
fail(failres){ // 登录失败
// console.log(failres)
if(failres.code === 30002){
// than.$u.toast("其他按钮");
uni.closeAuthView()
than.gotoRegist()
// uni.showToast({
// title: failres.msg,
// duration:2000, mask:false, icon:'none'
// });
// setTimeout(function () {
// uni.closeAuthView()
// than.gotoRegist()
// }, 2000);
} else if(failres.index === 0){
// console.log("手机")
uni.closeAuthView()
}
// if(failres.index === 0){
// console.log("手机")
// uni.closeAuthView()
// }else if(failres.index === 1){
// than.login_weixin()
// } else if(failres.index == 2){
// than.login_apple()
// }
}
})
}
}
})
},
操作步骤:
华为手机首次下载app
华为手机首次下载app
预期结果:
只调起一次一键登录,显示其他方式登录按钮
只调起一次一键登录,显示其他方式登录按钮
实际结果:
调起两次一键登录,不显示其他按钮和返回按钮
调起两次一键登录,不显示其他按钮和返回按钮
bug描述:
华为手机第一次下载app,回调起一键登录,但是没有返回按钮和其他按钮,手机返回键返回后,出现正确页面