From 24c3709c9521035263b1e4e7194e0304e598b760 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 19 Oct 2023 21:49:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=9A=84=E4=B8=80=E9=94=AE=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/users/login/index.vue | 34 ------- pages/users/wechat_login/index.vue | 145 ++++++++++------------------- 2 files changed, 47 insertions(+), 132 deletions(-) diff --git a/pages/users/login/index.vue b/pages/users/login/index.vue index 5d04a686..bd2586eb 100644 --- a/pages/users/login/index.vue +++ b/pages/users/login/index.vue @@ -50,9 +50,6 @@
快速登录
账号登录
- - -
@@ -353,37 +350,6 @@ }); }); }, - /** - * 微信一键登录 - */ - async getPhoneNumber(e) { - // 情况一:拒绝授权手机号码 - const phoneCode = e.detail.code - if (!e.detail.code) { - uni.showModal({ - title: '授权失败', - content: '您已拒绝获取绑定手机号登录授权,可以使用其他手机号验证登录', - confirmText: '知道了', - confirmColor: '#3C9CFFFF' - }) - return; - } - // 情况二:允许授权手机号码 - const loginCode = await Routine.getCode() - AuthApi.weixinMiniAppLogin(phoneCode, loginCode).then(res => { - const data = res.data; - // TODO 芋艿:refreshToken 机制 - this.$store.commit("LOGIN", { - 'token': data.accessToken - }); - this.getUserInfo(data); - this.bindBrokerUser(); - }).catch(e => { - this.$util.Tips({ - title: e - }); - }); - }, getUserInfo(data) { this.$store.commit("SETUID", data.userId); this.$store.commit("OPENID", data.openid); diff --git a/pages/users/wechat_login/index.vue b/pages/users/wechat_login/index.vue index 564a4f5a..01686699 100644 --- a/pages/users/wechat_login/index.vue +++ b/pages/users/wechat_login/index.vue @@ -23,6 +23,9 @@ + + + @@ -40,12 +43,11 @@ const app = getApp(); let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px'; import * as UserApi from "@/api/member/user"; + import * as AuthApi from "@/api/member/auth"; import mobileLogin from '@/components/login_mobile/index.vue' import routinePhone from '@/components/login_mobile/routine_phone.vue' - import { - getLogo, - getUserPhone - } from '@/api/public'; + import * as BrokerageAPI from '@/api/trade/brokerage.js' + import { getUserPhone } from '@/api/public'; import Routine from '@/libs/routine'; import wechat from "@/libs/wechat"; export default { @@ -56,7 +58,7 @@ statusBarHeight: statusBarHeight, isHome: false, isPhoneBox: false, - logoUrl: '', + // logoUrl: '', code: '', authKey: '', options: '', @@ -72,9 +74,9 @@ routinePhone }, onLoad(options) { - getLogo().then(res => { - this.logoUrl = res.data.logoUrl - }) + // getLogo().then(res => { + // this.logoUrl = res.data.logoUrl + // }) // #ifdef H5 document.body.addEventListener("focusout", () => { @@ -141,52 +143,14 @@ tab: 3 }) }); + }, + bindBrokerUser() { + const spread = this.$Cache.get("spread"); + if (spread > 0) { + BrokerageAPI.bindBrokerageUser(spread) + } }, // #ifdef MP - // 小程序获取手机号码 - getphonenumber(e) { - uni.showLoading({ - title: '正在登录中' - }); - Routine.getCode() - .then(code => { - this.getUserPhoneNumber(e.detail.encryptedData, e.detail.iv, code); - }) - .catch(error => { - uni.$emit('closePage', false) - uni.hideLoading(); - }); - }, - // 小程序获取手机号码回调 - getUserPhoneNumber(encryptedData, iv, code) { - getUserPhone({ - encryptedData: encryptedData, - iv: iv, - code: code, - type: 'routine', - key: this.authKey - }) - .then(res => { - this.$store.commit('LOGIN', { - token: res.data.token - }); - this.$store.commit("SETUID", res.data.uid); - this.getUserInfo(); - this.$util.Tips({ - title: '登录成功', - icon: 'success' - }, { - tab: 3 - }) - - }) - .catch(res => { - uni.hideLoading(); - that.$util.Tips({ - title: res - }); - }); - }, getUserProfile() { let self = this; uni.showLoading({ @@ -206,52 +170,37 @@ uni.hideLoading(); }); }, - - getWxUser(code, res) { - let self = this - let userInfo = res.userInfo; - userInfo.code = code; - userInfo.spread_spid = app.globalData.spid; //获取推广人ID - userInfo.spread_code = app.globalData.code; //获取推广人分享二维码ID - userInfo.avatar = userInfo.userInfo.avatarUrl; - userInfo.city = userInfo.userInfo.city; - userInfo.country = userInfo.userInfo.country; - userInfo.nickName = userInfo.userInfo.nickName; - userInfo.province = userInfo.userInfo.province; - userInfo.sex = userInfo.userInfo.gender; - userInfo.type = 'routine' - Routine.authUserInfo(userInfo.code, userInfo) - .then(res => { - self.authKey = res.data.key; - if (res.data.type === 'register') { - uni.hideLoading(); - self.isPhoneBox = true - } - if (res.data.type === 'login') { - uni.hideLoading(); - self.$store.commit('LOGIN', { - token: res.data.token - }); - self.$store.commit("SETUID", res.data.uid); - self.getUserInfo(); - self.$util.Tips({ - title: res, - icon: 'success' - }, { - tab: 3 - }) - } - }) - .catch(res => { - uni.hideLoading(); - uni.showToast({ - title: res, - icon: 'none', - duration: 2000 - }); - }); - - }, + /** + * 微信一键登录 + */ + async getPhoneNumber(e) { + // 情况一:拒绝授权手机号码 + const phoneCode = e.detail.code + if (!e.detail.code) { + uni.showModal({ + title: '授权失败', + content: '您已拒绝获取绑定手机号登录授权,可以使用其他手机号验证登录', + confirmText: '知道了', + confirmColor: '#3C9CFFFF' + }) + return; + } + // 情况二:允许授权手机号码 + const loginCode = await Routine.getCode() + AuthApi.weixinMiniAppLogin(phoneCode, loginCode).then(res => { + const data = res.data; + // TODO 芋艿:refreshToken 机制 + this.$store.commit("LOGIN", { + 'token': data.accessToken + }); + this.getUserInfo(); + this.bindBrokerUser(); + }).catch(e => { + this.$util.Tips({ + title: e + }); + }); + }, // #endif // #ifdef H5