完成登录功能
This commit is contained in:
parent
7d32cb091a
commit
1644642e54
|
|
@ -2,6 +2,7 @@
|
||||||
export default {
|
export default {
|
||||||
onLaunch: function () {
|
onLaunch: function () {
|
||||||
this.$store.dispatch("system/initConfig");
|
this.$store.dispatch("system/initConfig");
|
||||||
|
this.$store.dispatch("user/token");
|
||||||
},
|
},
|
||||||
onShow: function () {},
|
onShow: function () {},
|
||||||
onHide: function () {},
|
onHide: function () {},
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import $store from "@/store/index"
|
||||||
import Vue from "vue"
|
import Vue from "vue"
|
||||||
let prototype = Vue.prototype;
|
let prototype = Vue.prototype;
|
||||||
|
|
||||||
|
|
@ -49,20 +50,20 @@ export default {
|
||||||
/**
|
/**
|
||||||
* 用户注册
|
* 用户注册
|
||||||
*/
|
*/
|
||||||
register(userData, verificationCode) {
|
register(user, verificationCode) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!prototype.$test.mobile(userData.mobile)) {
|
if (!prototype.$test.mobile(user.mobile)) {
|
||||||
return reject('请输入正确的手机号码');
|
return reject('请输入正确的手机号码');
|
||||||
}
|
}
|
||||||
if (userData.password.length < 6 || userData.password.length > 16) {
|
if (user.password.length < 6 || user.password.length > 16) {
|
||||||
return reject('密码在6至16位字符之间');
|
return reject('密码在6至16位字符之间');
|
||||||
}
|
}
|
||||||
this.platformLogin().then(res => {
|
this.platformLogin().then(res => {
|
||||||
prototype.$request({
|
prototype.$request({
|
||||||
api: 'user.register',
|
api: 'user.register',
|
||||||
data: {
|
data: {
|
||||||
username: userData.mobile,
|
username: user.mobile,
|
||||||
password: userData.password,
|
password: user.password,
|
||||||
verification_code: verificationCode,
|
verification_code: verificationCode,
|
||||||
openid: res.openid,
|
openid: res.openid,
|
||||||
types: 1,
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,5 @@
|
||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
{
|
|
||||||
"path": "pages/auth/auth",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "登录"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path": "pages/index/index",
|
"path": "pages/index/index",
|
||||||
"style": {
|
"style": {
|
||||||
|
|
@ -13,6 +7,12 @@
|
||||||
"enablePullDownRefresh": true
|
"enablePullDownRefresh": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/auth/auth",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "登录"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/service/cate",
|
"path": "pages/service/cate",
|
||||||
"style": {
|
"style": {
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,19 @@ export default {
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 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() {
|
register() {
|
||||||
const that = this;
|
const that = this;
|
||||||
if (!this.isAgree) {
|
if (!this.isAgree) {
|
||||||
|
|
|
||||||
|
|
@ -32,5 +32,14 @@ export default {
|
||||||
logout(context) {
|
logout(context) {
|
||||||
context.commit('userInfo', null);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue