完成注册功能
This commit is contained in:
parent
38b4688b09
commit
934252e2d1
|
@ -2,20 +2,34 @@ export default {
|
||||||
index: {
|
index: {
|
||||||
banner: {
|
banner: {
|
||||||
url: "/index/banner",
|
url: "/index/banner",
|
||||||
|
method: "post",
|
||||||
auth: false,
|
auth: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
|
sendCode: {
|
||||||
|
url: "/public/send",
|
||||||
|
method: "post",
|
||||||
|
auth: false,
|
||||||
|
},
|
||||||
|
openId: {
|
||||||
|
url: "/public/getopenid",
|
||||||
|
method: "post",
|
||||||
|
auth: false,
|
||||||
|
},
|
||||||
register: {
|
register: {
|
||||||
url: "/public/register",
|
url: "/public/register",
|
||||||
|
method: "post",
|
||||||
auth: false,
|
auth: false,
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
url: "/public/login",
|
url: "/public/login",
|
||||||
|
method: "post",
|
||||||
auth: false,
|
auth: false,
|
||||||
},
|
},
|
||||||
info: {
|
info: {
|
||||||
url: "/user/getuserinfo",
|
url: "/user/getuserinfo",
|
||||||
|
method: "post",
|
||||||
auth: true,
|
auth: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,59 +1,79 @@
|
||||||
|
import Vue from "vue"
|
||||||
|
let prototype = Vue.prototype;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
/**
|
/**
|
||||||
* 获取平台用户信息
|
* 登录平台
|
||||||
*/
|
*/
|
||||||
platformInfo() {
|
platformLogin() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 获取用户信息
|
// #ifndef H5
|
||||||
uni.getUserProfile({
|
|
||||||
provider: 'weixin',
|
|
||||||
desc: "获取用户信息",
|
|
||||||
success: function (info) {
|
|
||||||
console.log(info);
|
|
||||||
uni.login({
|
uni.login({
|
||||||
provider: "weixin",
|
provider: "weixin",
|
||||||
success: (result) => {
|
success(result) {
|
||||||
resolve({
|
prototype.$request({
|
||||||
code: result.code,
|
api: 'user.openId',
|
||||||
userInfo: {
|
data: {
|
||||||
avatarUrl: info.userInfo.avatarUrl,
|
code: result.code
|
||||||
city: info.userInfo.city,
|
|
||||||
country: info.userInfo.country,
|
|
||||||
gender: info.userInfo.gender,
|
|
||||||
language: info.userInfo.language,
|
|
||||||
nickName: info.userInfo.nickName,
|
|
||||||
province: info.userInfo.province
|
|
||||||
}
|
}
|
||||||
// encryptedData: info.encryptedData,
|
}).then((response) => {
|
||||||
// iv: info.iv,
|
resolve(response.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
fail: e => {
|
/**
|
||||||
reject(e);
|
* 发送验证码
|
||||||
},
|
*/
|
||||||
});
|
sendVerificationCode(mobile) {
|
||||||
},
|
|
||||||
fail: e => {
|
|
||||||
reject(e);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
register() {
|
|
||||||
this.platformInfo().then(platfromUser => {
|
|
||||||
console.log(platfromUser);
|
|
||||||
}).catch(e => { });
|
|
||||||
},
|
|
||||||
login() {
|
|
||||||
uni.navigateTo({
|
|
||||||
url: '/pages/auth/login'
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getInfo() {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
resolve({
|
if (!prototype.$test.mobile(mobile)) {
|
||||||
id: 123,
|
return reject('请输入正确的手机号码');
|
||||||
name: '李四'
|
}
|
||||||
|
prototype.$request({
|
||||||
|
api: 'user.sendCode',
|
||||||
|
data: {
|
||||||
|
username: mobile,
|
||||||
|
},
|
||||||
|
}).then((res) => {
|
||||||
|
if (res.code == 1) {
|
||||||
|
return resolve();
|
||||||
|
} else {
|
||||||
|
return reject(response.msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 用户注册
|
||||||
|
*/
|
||||||
|
register(userData, verificationCode) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!prototype.$test.mobile(userData.mobile)) {
|
||||||
|
return reject('请输入正确的手机号码');
|
||||||
|
}
|
||||||
|
if (userData.password.length < 6 || userData.password.length > 16) {
|
||||||
|
return reject('密码在6至16位字符之间');
|
||||||
|
}
|
||||||
|
this.platformLogin().then(res => {
|
||||||
|
prototype.$request({
|
||||||
|
api: 'user.register',
|
||||||
|
data: {
|
||||||
|
username: userData.mobile,
|
||||||
|
password: userData.password,
|
||||||
|
verification_code: verificationCode,
|
||||||
|
openid: res.openid,
|
||||||
|
types: 1,
|
||||||
|
}
|
||||||
|
}).then((response) => {
|
||||||
|
if (response.code == 1) {
|
||||||
|
return resolve(response);
|
||||||
|
} else {
|
||||||
|
return reject(response.msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
|
{
|
||||||
|
"path": "pages/auth/auth",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "登录"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/index/index",
|
"path": "pages/index/index",
|
||||||
"style": {
|
"style": {
|
||||||
|
@ -7,12 +13,6 @@
|
||||||
"enablePullDownRefresh": true
|
"enablePullDownRefresh": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"path": "pages/auth/auth",
|
|
||||||
"style": {
|
|
||||||
"navigationBarTitleText": "登录"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path": "pages/service/cate",
|
"path": "pages/service/cate",
|
||||||
"style": {
|
"style": {
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
<input
|
<input
|
||||||
class="input"
|
class="input"
|
||||||
type="number"
|
type="number"
|
||||||
v-model="mobile"
|
v-model="verificationCode"
|
||||||
placeholder="请输入验证码"
|
placeholder="请输入验证码"
|
||||||
placeholder-class="placeholder-style-3"
|
placeholder-class="placeholder-style-3"
|
||||||
/>
|
/>
|
||||||
|
@ -115,6 +115,7 @@ export default {
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
mobile: "",
|
mobile: "",
|
||||||
password: "",
|
password: "",
|
||||||
|
verificationCode: "",
|
||||||
isAgree: false,
|
isAgree: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -133,9 +134,14 @@ export default {
|
||||||
},
|
},
|
||||||
getVerifyCode() {
|
getVerifyCode() {
|
||||||
if (this.canUse) {
|
if (this.canUse) {
|
||||||
if (true) {
|
this.$models.user
|
||||||
this.parseTime(10);
|
.sendVerificationCode(this.mobile)
|
||||||
}
|
.then((response) => {
|
||||||
|
this.parseTime(60);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
this.$utils.toast(e);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.$utils.toast("请稍后再试");
|
this.$utils.toast("请稍后再试");
|
||||||
}
|
}
|
||||||
|
@ -155,10 +161,32 @@ export default {
|
||||||
},
|
},
|
||||||
login() {},
|
login() {},
|
||||||
register() {
|
register() {
|
||||||
|
const that = this;
|
||||||
if (!this.isAgree) {
|
if (!this.isAgree) {
|
||||||
this.$utils.toast("请先阅读并同意《服务协议》《隐私政策》");
|
this.$utils.toast("请先阅读并同意《服务协议》《隐私政策》");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.$models.user
|
||||||
|
.register(
|
||||||
|
{
|
||||||
|
mobile: this.mobile,
|
||||||
|
password: this.password,
|
||||||
|
},
|
||||||
|
this.verificationCode
|
||||||
|
)
|
||||||
|
.then((response) => {
|
||||||
|
this.$utils.toast(response.msg, {
|
||||||
|
duration: 1500,
|
||||||
|
complete() {
|
||||||
|
setTimeout(() => {
|
||||||
|
that.$utils.toPage("/pages/auth/auth");
|
||||||
|
}, 1500);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
this.$utils.toast(e);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -206,6 +234,7 @@ export default {
|
||||||
margin-top: 45rpx;
|
margin-top: 45rpx;
|
||||||
border-bottom: 2rpx solid #d2d1d1;
|
border-bottom: 2rpx solid #d2d1d1;
|
||||||
.input {
|
.input {
|
||||||
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 32rpx;
|
font-size: 32rpx;
|
||||||
color: #666666;
|
color: #666666;
|
||||||
|
@ -235,6 +264,7 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.get-code {
|
.get-code {
|
||||||
|
z-index: 10;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
import user from '@/core/models/user'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: {
|
state: {
|
||||||
showLoginModal: false,
|
showLoginModal: false,
|
||||||
isLogin: false,
|
openId: "",
|
||||||
|
token: "",
|
||||||
userInfo: null,
|
userInfo: null,
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
showLoginModal(state) {
|
showLoginModal(state) {
|
||||||
return state.showLoginModal;
|
return state.showLoginModal;
|
||||||
},
|
},
|
||||||
isLogin(state) {
|
|
||||||
return state.isLogin;
|
|
||||||
},
|
|
||||||
userInfo(state) {
|
userInfo(state) {
|
||||||
return state.userInfo;
|
return state.userInfo;
|
||||||
},
|
},
|
||||||
|
@ -22,8 +18,11 @@ export default {
|
||||||
showLoginModal(state, data) {
|
showLoginModal(state, data) {
|
||||||
state.showLoginModal = data;
|
state.showLoginModal = data;
|
||||||
},
|
},
|
||||||
isLogin(state, data) {
|
openId(state, data) {
|
||||||
state.isLogin = data;
|
state.openId = data;
|
||||||
|
},
|
||||||
|
token(state, data) {
|
||||||
|
state.token = data;
|
||||||
},
|
},
|
||||||
userInfo(state, data) {
|
userInfo(state, data) {
|
||||||
state.userInfo = data;
|
state.userInfo = data;
|
||||||
|
@ -33,10 +32,5 @@ export default {
|
||||||
logout(context) {
|
logout(context) {
|
||||||
context.commit('userInfo', null);
|
context.commit('userInfo', null);
|
||||||
},
|
},
|
||||||
userInfo(context) {
|
|
||||||
user.getInfo().then(info => {
|
|
||||||
context.commit('userInfo', info);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue