From 42af87f53f0a833e8a8560d5819521613e94717e Mon Sep 17 00:00:00 2001 From: wangzhitong Date: Fri, 29 Nov 2024 13:14:02 +0800 Subject: [PATCH] add univerify-custom-page.uvue --- pages.json | 14 ++ .../get-univerify-manager.uvue | 174 ++++++++------ .../univerify-custom-page.uvue | 223 ++++++++++++++++++ .../univerify-privacy-page.uvue | 73 ++++++ 4 files changed, 411 insertions(+), 73 deletions(-) create mode 100644 pages/API/get-univerify-manager/univerify-custom-page.uvue create mode 100644 pages/API/get-univerify-manager/univerify-privacy-page.uvue diff --git a/pages.json b/pages.json index 04f8faf1..efd02ed3 100644 --- a/pages.json +++ b/pages.json @@ -1220,6 +1220,20 @@ "enablePullDownRefresh": false } }, + { + "path": "pages/API/get-univerify-manager/univerify-custom-page", + "style": { + "navigationBarTextStyle":"black", + "navigationStyle": "custom" + } + }, + { + "path": "pages/API/get-univerify-manager/univerify-privacy-page", + "style": { + "navigationBarTextStyle":"black", + "navigationStyle": "custom" + } + }, // #endif // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN { diff --git a/pages/API/get-univerify-manager/get-univerify-manager.uvue b/pages/API/get-univerify-manager/get-univerify-manager.uvue index 0f7db071..49c76efe 100644 --- a/pages/API/get-univerify-manager/get-univerify-manager.uvue +++ b/pages/API/get-univerify-manager/get-univerify-manager.uvue @@ -8,6 +8,9 @@ + + + @@ -17,27 +20,40 @@ data() { return { title: '一键登录', - univerifyManager: null as UniverifyManager | null + univerifyManager: null as UniverifyManager | null, + phone: '', + slogan: '', + privacyName: '', + privacyUrl: '' + // phone: '176****6657', + // slogan: '认证服务由中国联通提供', + // privacyName: '中国联通认证服务条款', + // privacyUrl: 'https://opencloud.wostore.cn/authz/resource/html/disclaimer.html?fromsdk=true' } }, onLoad() { this.univerifyManager = uni.getUniverifyManager(); // 预登录 - this.univerifyManager?.preLogin({ - success: () => { - console.log("pre login success"); - }, - fail: (err : PreLoginFail) => { - console.error("pre login fail => " + JSON.stringify(err)); - uni.showModal({ - title: '预登录失败', - content: JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") ?? err.errMsg, - showCancel: false - }); - } - } as PreLoginOptions); + this.preLogin(() => { }); }, methods: { + customLoginIn() { + const isPreLoginValid = this.univerifyManager?.isPreLoginValid() ?? false; + if (isPreLoginValid) { + this.pushCustomPage(); + } else { + this.preLogin(() => { + this.pushCustomPage(); + }) + } + }, + pushCustomPage() { + const url = '/pages/API/get-univerify-manager/univerify-custom-page?phone=' + this.phone + '&slogan=' + this.slogan + '&name=' + this.privacyName + '&link=' + this.privacyUrl; + uni.navigateTo({ + url: url, + animationType: "slide-in-bottom", + }) + }, verify(fullScreen : boolean) { // 校验预登录是否有效 const isPreLoginValid = this.univerifyManager?.isPreLoginValid() ?? false; @@ -46,72 +62,84 @@ this.login(fullScreen); } else { // 预登录无效,执行预登录 - this.univerifyManager?.preLogin({ - success: () => { - console.log("pre login success"); - this.login(fullScreen); - }, - fail: (err : PreLoginFail) => { - console.error("pre login fail => " + JSON.stringify(err)); - uni.showModal({ - title: '预登录失败', - content: JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") ?? err.errMsg, - showCancel: false - }); - } - } as PreLoginOptions); + this.preLogin(() => { + this.login(fullScreen); + }) } }, - login(fullScreen : boolean) { - this.univerifyManager?.login({ - // 登录页样式 - univerifyStyle: { - fullScreen: fullScreen, - backgroundColor: "#FFFFFF", - loginBtnText: "一键登录", - logoPath: "/static/logo.png" - } as UniverifyStyle, - success: (res : LoginSuccess) => { - console.log("login success => " + JSON.stringify(res)); - // 云函数取号 - uniCloud.callFunction({ - name: 'univerify', - data: { - access_token: res.accessToken, // 客户端一键登录接口返回的access_token - openid: res.openId // 客户端一键登录接口返回的openid - } - }).then(res => { - // 关闭登录页 - this.univerifyManager?.close(); - setTimeout(() => { - uni.showModal({ - title: '取号成功', - content: res.result.getJSON("res")?.getString("phoneNumber"), - showCancel: false - }); - }, 100); - }).catch(err => { - console.error(JSON.stringify(err)); - // 关闭登录页 - this.univerifyManager?.close(); - setTimeout(() => { - uni.showModal({ - title: '取号失败', - content: (err as Error).message, - showCancel: false - }); - }, 100); - }); + preLogin(callback) { + this.univerifyManager?.preLogin({ + success: (res) => { + this.phone = res.number; + this.slogan = res.slogan; + this.privacyName = res.privacyName; + this.privacyUrl = res.privacyUrl; + console.log("pre login success"); + callback(); }, - fail: (err : LoginFail) => { - console.error("login fail => " + err); + fail: (err : PreLoginFail) => { + console.error("pre login fail => " + JSON.stringify(err)); uni.showModal({ - title: '登录失败', + title: '预登录失败', content: JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") ?? err.errMsg, showCancel: false }); } - } as LoginOptions); + } as PreLoginOptions); + }, + login(fullScreen : boolean) { + this.univerifyManager?.login({ + univerifyStyle:{ + fullScreen: fullScreen, + backgroundColor: "#FFFFFF", + loginBtnText: "一键登录", + logoPath: "/static/logo.png" + }, + success: (res : LoginSuccess) => { + console.log("login success => " + JSON.stringify(res)); + this.takePhoneNumber(res.accessToken,res.openId); + }, + fail: (err : LoginFail) => { + console.error("login fail => " + err); + uni.showModal({ + title: '登录失败', + content: JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") ?? err.errMsg, + showCancel: false + }); + } + }); + }, + takePhoneNumber(accessToken : string, openId : string) { + // 云函数取号 + uniCloud.callFunction({ + name: 'univerify', + data: { + access_token: accessToken, // 客户端一键登录接口返回的access_token + openid: openId // 客户端一键登录接口返回的openid + } + }).then(res => { + // 关闭登录页 + this.univerifyManager?.close(); + setTimeout(() => { + uni.showModal({ + title: '取号成功', + content: res.result.getJSON("res")?.getString("phoneNumber"), + showCancel: false + }); + }, 100); + }).catch(err => { + console.error(JSON.stringify(err)); + // 关闭登录页 + this.univerifyManager?.close(); + setTimeout(() => { + uni.showModal({ + title: '取号失败', + content: (err as Error).message, + showCancel: false + }); + }, 100); + }); + } } } @@ -119,4 +147,4 @@ +/style> diff --git a/pages/API/get-univerify-manager/univerify-custom-page.uvue b/pages/API/get-univerify-manager/univerify-custom-page.uvue new file mode 100644 index 00000000..b654c3e9 --- /dev/null +++ b/pages/API/get-univerify-manager/univerify-custom-page.uvue @@ -0,0 +1,223 @@ + + + + + diff --git a/pages/API/get-univerify-manager/univerify-privacy-page.uvue b/pages/API/get-univerify-manager/univerify-privacy-page.uvue new file mode 100644 index 00000000..95be8d4d --- /dev/null +++ b/pages/API/get-univerify-manager/univerify-privacy-page.uvue @@ -0,0 +1,73 @@ + + + + + -- GitLab