登录:微信一键登录
parent
0bd831fe35
commit
e8573f42bb
|
|
@ -48,3 +48,13 @@ export function socialLogin(type, code, state) {
|
||||||
noAuth: true // TODO 芋艿:后续要做调整
|
noAuth: true // TODO 芋艿:后续要做调整
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 微信小程序的一键登录登录
|
||||||
|
export function weixinMiniAppLogin(phoneCode, loginCode) {
|
||||||
|
return request.post('app-api/member/auth/weixin-mini-app-login', {
|
||||||
|
phoneCode,
|
||||||
|
loginCode
|
||||||
|
}, {
|
||||||
|
noAuth: true // TODO 芋艿:后续要做调整
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ class Routine
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 小程序登录
|
* 微信小程序静默登录
|
||||||
*
|
*
|
||||||
* @param code 授权码
|
* @param code 授权码
|
||||||
* @param spread 推广员编号
|
* @param spread 推广员编号
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,10 @@
|
||||||
<div class="tips">
|
<div class="tips">
|
||||||
<div v-if="current === 0" @click="current = 1">快速登录</div>
|
<div v-if="current === 0" @click="current = 1">快速登录</div>
|
||||||
<div v-if="current === 1" @click="current = 0">账号登录</div>
|
<div v-if="current === 1" @click="current = 0">账号登录</div>
|
||||||
</div>
|
<!-- #ifdef MP-WEIXIN -->
|
||||||
|
<button open-type="getPhoneNumber" type="primary" @getphonenumber="getPhoneNumber">一键登录</button>
|
||||||
|
<!-- #endif -->
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bottom"></div>
|
<div class="bottom"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -63,6 +66,7 @@
|
||||||
const BACK_URL = "login_back_url";
|
const BACK_URL = "login_back_url";
|
||||||
import * as BrokerageAPI from '@/api/trade/brokerage.js'
|
import * as BrokerageAPI from '@/api/trade/brokerage.js'
|
||||||
import Routine from '@/libs/routine.js';
|
import Routine from '@/libs/routine.js';
|
||||||
|
import {weixinMiniAppLogin} from "../../../api/member/auth";
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: "Login",
|
||||||
mixins: [sendVerifyCode],
|
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("SETUID", data.userId);
|
||||||
this.$store.commit("OPENID", data.openid);
|
this.$store.commit("OPENID", data.openid);
|
||||||
UserApi.getUserInfo().then(res => {
|
UserApi.getUserInfo().then(res => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue