完成注册功能

This commit is contained in:
TOP糯米 2023-03-07 00:57:43 +08:00
parent 38b4688b09
commit 934252e2d1
5 changed files with 127 additions and 69 deletions

View File

@ -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,
} }
}, },

View File

@ -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({ uni.login({
provider: 'weixin', provider: "weixin",
desc: "获取用户信息", success(result) {
success: function (info) { prototype.$request({
console.log(info); api: 'user.openId',
uni.login({ data: {
provider: "weixin", code: result.code
success: (result) => { }
resolve({ }).then((response) => {
code: result.code, resolve(response.data);
userInfo: {
avatarUrl: info.userInfo.avatarUrl,
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,
// iv: info.iv,
});
},
fail: e => {
reject(e);
},
}); });
}
});
// #endif
});
},
/**
* 发送验证码
*/
sendVerificationCode(mobile) {
return new Promise((resolve, reject) => {
if (!prototype.$test.mobile(mobile)) {
return reject('请输入正确的手机号码');
}
prototype.$request({
api: 'user.sendCode',
data: {
username: mobile,
}, },
fail: e => { }).then((res) => {
reject(e); if (res.code == 1) {
}, return resolve();
} else {
return reject(response.msg);
}
}); });
}); });
}, },
register() { /**
this.platformInfo().then(platfromUser => { * 用户注册
console.log(platfromUser); */
}).catch(e => { }); register(userData, verificationCode) {
},
login() {
uni.navigateTo({
url: '/pages/auth/login'
});
},
getInfo() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve({ if (!prototype.$test.mobile(userData.mobile)) {
id: 123, return reject('请输入正确的手机号码');
name: '李四' }
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);
}
});
}); });
}); });
} }

View File

@ -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": {

View File

@ -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;

View File

@ -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);
});
}
} }
} }