登录界面:账号密码登录

pull/1/MERGE
YunaiV 2023-08-28 19:58:22 +08:00
parent 84e9e44b22
commit 02ce643f57
3 changed files with 72 additions and 44 deletions

View File

@ -23,3 +23,10 @@ export function validateSmsCode(mobile, scene, code) {
export function logout() { export function logout() {
return request.post('app-api/member/auth/logout'); return request.post('app-api/member/auth/logout');
} }
// 使用手机 + 密码登录
export function login(data) {
return request.post('app-api/member/auth/login', data, {
noAuth: true // TODO 芋艿:后续要做调整
});
}

View File

@ -43,7 +43,9 @@
</div> </div>
</div> </div>
</div> </div>
<!-- 登录方式一验证码登录 -->
<div class="logon" @click="loginMobile" v-if="current !== 0"></div> <div class="logon" @click="loginMobile" v-if="current !== 0"></div>
<!-- 登录方式二密码登录 -->
<div class="logon" @click="submit" v-if="current === 0"></div> <div class="logon" @click="submit" v-if="current === 0"></div>
<div class="tips"> <div class="tips">
<div v-if="current === 0" @click="current = 1"></div> <div v-if="current === 0" @click="current = 1"></div>
@ -55,7 +57,9 @@
</template> </template>
<script> <script>
import sendVerifyCode from "@/mixins/SendVerifyCode"; import sendVerifyCode from "@/mixins/SendVerifyCode";
import { loginH5, loginMobile, registerVerify, getUserInfo } from "@/api/user"; import { loginMobile, registerVerify, getUserInfo } from "@/api/user";
import * as AuthApi from "@/api/member/auth";
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";
export default { export default {
@ -277,37 +281,53 @@
* 手机 + 密码登录 * 手机 + 密码登录
*/ */
async submit() { async submit() {
let that = this; if (!this.account) {
if (!that.account) return that.$util.Tips({ return this.$util.Tips({
title: '请填写账号' title: '请填写账号'
}); });
if (!/^[\w\d]{5,16}$/i.test(that.account)) return that.$util.Tips({ }
if (!/^[\w\d]{5,16}$/i.test(this.account)) {
return this.$util.Tips({
title: '请输入正确的账号' title: '请输入正确的账号'
}); });
if (!that.password) return that.$util.Tips({ }
if (!this.password) {
return this.$util.Tips({
title: '请填写密码' title: '请填写密码'
}); });
loginH5({ }
account: that.account, AuthApi.login({
password: that.password, mobile: this.account,
spread: that.$Cache.get("spread") password: this.password,
}) spread: this.$Cache.get("spread") // TODO
.then(({ }).then(({ data }) => {
data debugger
}) => {
this.$store.commit("LOGIN", { this.$store.commit("LOGIN", {
'token': data.token 'token': data.accessToken
}); });
that.getUserInfo(data); this.getUserInfo(data);
}) }).catch(e => {
.catch(e => { this.$util.Tips({
that.$util.Tips({
title: e title: e
}); });
}); });
}, },
getUserInfo(data) { getUserInfo(data) {
this.$store.commit("SETUID", data.uid); this.$store.commit("SETUID", data.userId);
// TODO
if (true) {
UserApi.getUserInfo().then(res => {
this.$store.commit("UPDATE_USERINFO", res.data);
//
let backUrl = this.$Cache.get(BACK_URL) || "/pages/index/index";
if (backUrl.indexOf('/pages/users/login/index') !== -1) {
backUrl = '/pages/index/index';
}
uni.reLaunch({
url: backUrl
});
})
} else {
getUserInfo().then(res => { getUserInfo().then(res => {
this.$store.commit("UPDATE_USERINFO", res.data); this.$store.commit("UPDATE_USERINFO", res.data);
let backUrl = this.$Cache.get(BACK_URL) || "/pages/index/index"; let backUrl = this.$Cache.get(BACK_URL) || "/pages/index/index";
@ -320,6 +340,7 @@
}) })
} }
} }
}
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -58,7 +58,7 @@
import { toLogin } from '@/libs/login.js'; import { toLogin } from '@/libs/login.js';
import { mapGetters } from "vuex"; import { mapGetters } from "vuex";
import * as UserApi from '@/api/member/user.js'; import * as UserApi from '@/api/member/user.js';
import * as AuthUtil from '@/api/member/auth.js'; import * as AuthApi from '@/api/member/auth.js';
export default { export default {
components: {}, components: {},
data() { data() {
@ -98,7 +98,7 @@
console.log('用户点击取消'); console.log('用户点击取消');
return return
} }
AuthUtil.logout().then(res => { AuthApi.logout().then(res => {
this.$store.commit("LOGOUT"); this.$store.commit("LOGOUT");
uni.reLaunch({ uni.reLaunch({
url: '/pages/index/index' url: '/pages/index/index'