登录:接入验证码登录

pull/1/MERGE
YunaiV 2023-09-09 22:45:58 +08:00
parent b71fed3782
commit 3c7db828db
2 changed files with 55 additions and 42 deletions

View File

@ -30,3 +30,10 @@ export function login(data) {
noAuth: true // TODO 芋艿:后续要做调整 noAuth: true // TODO 芋艿:后续要做调整
}); });
} }
// 使用手机 + 验证码登录
export function smsLogin(data) {
return request.post('app-api/member/auth/sms-login', data, {
noAuth: true // TODO 芋艿:后续要做调整
});
}

View File

@ -57,12 +57,13 @@
</template> </template>
<script> <script>
import sendVerifyCode from "@/mixins/SendVerifyCode"; import sendVerifyCode from "@/mixins/SendVerifyCode";
import { loginMobile, registerVerify } from "@/api/user"; import { loginMobile } from "@/api/user";
import * as AuthApi from "@/api/member/auth"; import * as AuthApi from "@/api/member/auth";
import * as UserApi from "@/api/member/user"; import * as UserApi from "@/api/member/user";
import { appAuth, appleLogin } from "@/api/public"; import { appAuth, appleLogin } from "@/api/public";
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 {smsLogin} from "../../../api/member/auth";
export default { export default {
name: "Login", name: "Login",
mixins: [sendVerifyCode], mixins: [sendVerifyCode],
@ -224,56 +225,61 @@
* 手机 + 验证码登录 * 手机 + 验证码登录
*/ */
async loginMobile() { async loginMobile() {
let that = this;
if (!this.account) { if (!this.account) {
return that.$util.Tips({ return this.$util.Tips({
title: '请填写手机号码' title: '请填写手机号码'
}); });
} }
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({ if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.account)) {
return this.$util.Tips({
title: '请输入正确的手机号码' title: '请输入正确的手机号码'
}); });
if (!that.captcha) return that.$util.Tips({ }
if (!this.captcha) {
return this.$util.Tips({
title: '请填写验证码' title: '请填写验证码'
}); });
if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({ }
if (!/^[\w\d]+$/i.test(this.captcha)) {
return this.$util.Tips({
title: '请输入正确的验证码' title: '请输入正确的验证码'
}); });
loginMobile({ }
phone: that.account, AuthApi.smsLogin({
captcha: that.captcha, mobile: this.account,
spread_spid: that.$Cache.get("spread") code: this.captcha,
}) }).then(res => {
.then(res => { // TODO refreshToken
let data = res.data; let data = res.data;
let newTime = Math.round(new Date() / 1000);
this.$store.commit("LOGIN", { this.$store.commit("LOGIN", {
'token': res.data.token 'token': res.data.accessToken
}); });
that.getUserInfo(data); this.getUserInfo(data);
}) this.bindBrokerUser();
.catch(res => { }).catch(res => {
that.$util.Tips({ this.$util.Tips({
title: res title: res
}); });
}); });
}, },
async code() { async code() {
let that = this; if (!this.account) {
if (!that.account) return that.$util.Tips({ return this.$util.Tips({
title: '请填写手机号码' title: '请填写手机号码'
}); });
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({ }
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.account)) {
return this.$util.Tips({
title: '请输入正确的手机号码' title: '请输入正确的手机号码'
}); });
if (that.formItem == 2) that.type = "register"; }
await registerVerify(that.account) await AuthApi.sendSmsCode(this.account, 1)
.then(res => { .then(res => {
that.$util.Tips({title:res.message}); this.$util.Tips({title:res.message});
that.sendCode(); this.sendCode();
}) })
.catch(err => { .catch(err => {
return that.$util.Tips({ return this.$util.Tips({
title: err title: err
}); });
}); });