提交 6c6d8ca3 编写于 作者: DCloud_iOS_WZT's avatar DCloud_iOS_WZT

update get-univerify-manager.uvue

上级 55e752f6
......@@ -20,7 +20,7 @@
data() {
return {
title: '一键登录',
univerifyManager: null as UniverifyManager | null,
uniVerifyManager: null as UniVerifyManager | null,
phone: '',
slogan: '',
privacyName: '',
......@@ -28,7 +28,7 @@
}
},
onLoad() {
this.univerifyManager = uni.getUniverifyManager();
this.uniVerifyManager = uni.getUniVerifyManager();
// 预登录
this.preLogin(() => { });
},
......@@ -42,7 +42,7 @@
})
return
}
const isPreLoginValid = this.univerifyManager?.isPreLoginValid() ?? false;
const isPreLoginValid = this.uniVerifyManager?.isPreLoginValid() ?? false;
if (isPreLoginValid) {
this.pushCustomPage();
} else {
......@@ -74,7 +74,7 @@
return
}
// 校验预登录是否有效
const isPreLoginValid = this.univerifyManager?.isPreLoginValid() ?? false;
const isPreLoginValid = this.uniVerifyManager?.isPreLoginValid() ?? false;
if (isPreLoginValid) {
// 预登录有效,执行登录
this.login(fullScreen);
......@@ -86,7 +86,7 @@
}
},
preLogin(callback: (() => void)) {
this.univerifyManager?.preLogin({
this.uniVerifyManager?.preLogin({
success: (res) => {
this.phone = res.number;
this.slogan = res.slogan;
......@@ -106,7 +106,7 @@
});
},
login(fullScreen : boolean) {
this.univerifyManager?.login({
this.uniVerifyManager?.login({
univerifyStyle:{
fullScreen: fullScreen,
backgroundColor: "#FFFFFF",
......@@ -137,7 +137,7 @@
}
}).then(res => {
// 关闭登录页
this.univerifyManager?.close();
this.uniVerifyManager?.close();
setTimeout(() => {
uni.showModal({
title: '取号成功',
......@@ -148,7 +148,7 @@
}).catch(err => {
console.error(JSON.stringify(err));
// 关闭登录页
this.univerifyManager?.close();
this.uniVerifyManager?.close();
setTimeout(() => {
uni.showModal({
title: '取号失败',
......
......@@ -22,16 +22,17 @@
export default {
data() {
return {
univerifyManager: null as UniverifyManager | null,
uniVerifyManager: null as UniVerifyManager | null,
phone: '',
slogan: '',
privacyName: '',
privacyUrl: '',
closeIcon: '\uE650'
closeIcon: '\uE650',
isLoading: false //是否正在登录中
}
},
onLoad(options : OnLoadOptions) {
this.univerifyManager = uni.getUniverifyManager();
onLoad(options : OnLoadOptions) {
this.uniVerifyManager = uni.getUniVerifyManager();
this.phone = options['phone'] as string;
this.slogan = options['slogan'] as string;
this.privacyName = options['name'] as string;
......@@ -39,15 +40,15 @@
},
methods: {
closePage() {
uni.closeDialogPage({
dialogPage: this.$page,
animationType:'slide-out-bottom',
success(res) {
console.log('closeThisDialog success', res)
},
fail(err) {
console.log('closeThisDialog fail', err)
}
uni.closeDialogPage({
dialogPage: this.$page,
animationType: 'slide-out-bottom',
success(res) {
console.log('closeThisDialog success', res)
},
fail(err) {
console.log('closeThisDialog fail', err)
}
})
},
openLink() {
......@@ -64,53 +65,66 @@
})
},
loginIn() {
loginIn() {
if (this.isLoading) {
uni.showToast({
title: "正在登录中,请稍后",
position: "bottom",
duration: 2000
})
return;
}else{
this.isLoading = true;
}
const numberTextElement = this.$page.getElementById('number-text');
const sloganTextElement = this.$page.getElementById('slogan-text');
const loginButtonElement = this.$page.getElementById('login-button');
const privacyCheckBoxElement = this.$page.getElementById('privacy-checkbox');
const privacyTextElement = this.$page.getElementById('privacy-text');
if(numberTextElement != null && sloganTextElement != null && loginButtonElement != null && privacyCheckBoxElement != null && privacyTextElement != null){
this.univerifyManager?.customLogin({
numberTextElement: numberTextElement,
sloganTextElement: sloganTextElement,
loginButtonElement: loginButtonElement,
privacyCheckBoxElement: privacyCheckBoxElement,
privacyTextElement: privacyTextElement,
success: (res) => {
console.log(res);
this.takePhoneNumber(res.accessToken, res.openId);
const privacyTextElement = this.$page.getElementById('privacy-text');
if (numberTextElement != null && sloganTextElement != null && loginButtonElement != null && privacyCheckBoxElement != null && privacyTextElement != null) {
this.uniVerifyManager?.customLogin({
numberTextElement: numberTextElement,
sloganTextElement: sloganTextElement,
loginButtonElement: loginButtonElement,
privacyCheckBoxElement: privacyCheckBoxElement,
privacyTextElement: privacyTextElement,
success: (res) => {
console.log(res);
this.takePhoneNumber(res.accessToken, res.openId);
},
fail: (error) => {
if (error.errCode == 40001) {
uni.showToast({
title: "请同意服务条款",
position: "bottom",
duration: 2000
})
} else if (error.errCode == 40002) {
uni.showToast({
title: "授权页不符合规范",
position: "bottom",
duration: 2000
})
} else {
const errorMsg = JSON.parseObject(error.cause?.cause?.message ?? "")?.getString("errorDesc") ?? error.errMsg;
uni.showToast({
title: errorMsg,
position: "bottom",
duration: 2000
})
}
},
fail: (error) => {
if (error.errCode == 40001){
uni.showToast({
title:"请同意服务条款",
position: "bottom",
duration:2000
})
}else if(error.errCode == 40002){
uni.showToast({
title:"授权页不符合规范",
position: "bottom",
duration:2000
})
}else{
const errorMsg = JSON.parseObject(error.cause?.cause?.message ?? "")?.getString("errorDesc") ?? error.errMsg;
uni.showToast({
title:errorMsg,
position: "bottom",
duration:2000
})
}
}
})
}else{
uni.showToast({
title:"元素不能为空",
position: "bottom",
duration:2000
complete: () =>{
this.isLoading = false;
}
})
} else {
uni.showToast({
title: "未获取到页面元素",
position: "bottom",
duration: 2000
})
this.isLoading = false;
}
},
......@@ -148,7 +162,7 @@
otherLogin() {
//此处可实现其他登录方式
uni.showToast({
title: "使用其他方式登录",
title: "使用其他方式登录",
position: "bottom"
})
}
......@@ -224,7 +238,7 @@
flex-wrap: wrap;
top: 45%;
width: 100%;
justify-content: center;
justify-content: center;
align-self: center;
position: absolute;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册