完成登录功能

This commit is contained in:
TOP糯米 2023-03-07 11:02:54 +08:00
parent 7d32cb091a
commit 1644642e54
5 changed files with 59 additions and 12 deletions

View File

@ -2,6 +2,7 @@
export default {
onLaunch: function () {
this.$store.dispatch("system/initConfig");
this.$store.dispatch("user/token");
},
onShow: function () {},
onHide: function () {},

View File

@ -1,3 +1,4 @@
import $store from "@/store/index"
import Vue from "vue"
let prototype = Vue.prototype;
@ -49,20 +50,20 @@ export default {
/**
* 用户注册
*/
register(userData, verificationCode) {
register(user, verificationCode) {
return new Promise((resolve, reject) => {
if (!prototype.$test.mobile(userData.mobile)) {
if (!prototype.$test.mobile(user.mobile)) {
return reject('请输入正确的手机号码');
}
if (userData.password.length < 6 || userData.password.length > 16) {
if (user.password.length < 6 || user.password.length > 16) {
return reject('密码在6至16位字符之间');
}
this.platformLogin().then(res => {
prototype.$request({
api: 'user.register',
data: {
username: userData.mobile,
password: userData.password,
username: user.mobile,
password: user.password,
verification_code: verificationCode,
openid: res.openid,
types: 1,
@ -76,5 +77,29 @@ export default {
});
});
});
},
login(user) {
return new Promise((resolve, reject) => {
if (!prototype.$test.mobile(user.mobile)) {
return reject('请输入正确的手机号码');
}
if (user.password.length < 6 || user.password.length > 16) {
return reject('密码在6至16位字符之间');
}
prototype.$request({
api: 'user.login',
data: {
username: user.mobile,
password: user.password,
}
}).then(response => {
if (response.code == 1) {
$store.dispatch('user/token', response.data.token);
return resolve(response);
} else {
return reject(response.msg);
}
});
});
}
}

View File

@ -1,11 +1,5 @@
{
"pages": [
{
"path": "pages/auth/auth",
"style": {
"navigationBarTitleText": "登录"
}
},
{
"path": "pages/index/index",
"style": {
@ -13,6 +7,12 @@
"enablePullDownRefresh": true
}
},
{
"path": "pages/auth/auth",
"style": {
"navigationBarTitleText": "登录"
}
},
{
"path": "pages/service/cate",
"style": {

View File

@ -159,7 +159,19 @@ export default {
}
}, 1000);
},
login() {},
login() {
this.$models.user
.login({
mobile: this.mobile,
password: this.password,
})
.then((response) => {
this.$utils.toPage("/pages/member/member", {}, 'switch');
})
.catch((e) => {
this.$utils.toast(e);
});
},
register() {
const that = this;
if (!this.isAgree) {

View File

@ -32,5 +32,14 @@ export default {
logout(context) {
context.commit('userInfo', null);
},
token(context, token) {
let cacheToken = uni.getStorageSync('user_access_token');
if (typeof token !== "undefined") {
uni.setStorageSync('user_access_token', token);
context.commit('token', token);
} else if (typeof token === "undefined" && cacheToken) {
context.commit('token', cacheToken);
}
}
}
}