diff --git a/api/member/auth.js b/api/member/auth.js index ac30def2..c847f652 100644 --- a/api/member/auth.js +++ b/api/member/auth.js @@ -48,3 +48,13 @@ export function socialLogin(type, code, state) { noAuth: true // TODO 芋艿:后续要做调整 }); } + +// 微信小程序的一键登录登录 +export function weixinMiniAppLogin(phoneCode, loginCode) { + return request.post('app-api/member/auth/weixin-mini-app-login', { + phoneCode, + loginCode + }, { + noAuth: true // TODO 芋艿:后续要做调整 + }); +} diff --git a/libs/routine.js b/libs/routine.js index baa8fb4e..673b818b 100644 --- a/libs/routine.js +++ b/libs/routine.js @@ -121,7 +121,7 @@ class Routine }); } /** - * 小程序登录 + * 微信小程序静默登录 * * @param code 授权码 * @param spread 推广员编号 diff --git a/pages/users/login/index.vue b/pages/users/login/index.vue index de103252..8af45a6f 100644 --- a/pages/users/login/index.vue +++ b/pages/users/login/index.vue @@ -50,7 +50,10 @@
快速登录
账号登录
-
+ + + +
@@ -63,6 +66,7 @@ const BACK_URL = "login_back_url"; import * as BrokerageAPI from '@/api/trade/brokerage.js' import Routine from '@/libs/routine.js'; + import {weixinMiniAppLogin} from "../../../api/member/auth"; export default { name: "Login", mixins: [sendVerifyCode], @@ -350,7 +354,38 @@ }); }); }, - getUserInfo(data) { + /** + * 微信一键登录 + */ + 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); UserApi.getUserInfo().then(res => {