登录界面:账号密码登录

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,8 +43,10 @@
</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>
<div v-if="current === 1" @click="current = 0"></div> <div v-if="current === 1" @click="current = 0"></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,47 +281,64 @@
* 手机 + 密码登录 * 手机 + 密码登录
*/ */
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({ }
title: '请输入正确的账号' if (!/^[\w\d]{5,16}$/i.test(this.account)) {
}); return this.$util.Tips({
if (!that.password) return that.$util.Tips({ title: '请输入正确的账号'
title: '请填写密码' });
}); }
loginH5({ if (!this.password) {
account: that.account, return this.$util.Tips({
password: that.password, title: '请填写密码'
spread: that.$Cache.get("spread") });
}) }
.then(({ AuthApi.login({
data mobile: this.account,
}) => { password: this.password,
this.$store.commit("LOGIN", { spread: this.$Cache.get("spread") // TODO
'token': data.token }).then(({ data }) => {
}); debugger
that.getUserInfo(data); this.$store.commit("LOGIN", {
}) 'token': data.accessToken
.catch(e => { });
that.$util.Tips({ this.getUserInfo(data);
title: e }).catch(e => {
}); this.$util.Tips({
}); title: e
});
});
}, },
getUserInfo(data){ getUserInfo(data) {
this.$store.commit("SETUID", data.uid); this.$store.commit("SETUID", data.userId);
getUserInfo().then(res => { // TODO
this.$store.commit("UPDATE_USERINFO", res.data); if (true) {
let backUrl = this.$Cache.get(BACK_URL) || "/pages/index/index"; UserApi.getUserInfo().then(res => {
if (backUrl.indexOf('/pages/users/login/index') !== -1) { this.$store.commit("UPDATE_USERINFO", res.data);
backUrl = '/pages/index/index'; //
} let backUrl = this.$Cache.get(BACK_URL) || "/pages/index/index";
uni.reLaunch({ if (backUrl.indexOf('/pages/users/login/index') !== -1) {
url: backUrl backUrl = '/pages/index/index';
}); }
}) uni.reLaunch({
url: backUrl
});
})
} else {
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
});
})
}
} }
} }
}; };

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'