完成注册功能

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: {
banner: {
url: "/index/banner",
method: "post",
auth: false,
},
},
user: {
sendCode: {
url: "/public/send",
method: "post",
auth: false,
},
openId: {
url: "/public/getopenid",
method: "post",
auth: false,
},
register: {
url: "/public/register",
method: "post",
auth: false,
},
login: {
url: "/public/login",
method: "post",
auth: false,
},
info: {
url: "/user/getuserinfo",
method: "post",
auth: true,
}
},

View File

@ -1,59 +1,79 @@
import Vue from "vue"
let prototype = Vue.prototype;
export default {
/**
* 获取平台用户信息
* 登录平台
*/
platformInfo() {
platformLogin() {
return new Promise((resolve, reject) => {
// 获取用户信息
uni.getUserProfile({
provider: 'weixin',
desc: "获取用户信息",
success: function (info) {
console.log(info);
uni.login({
provider: "weixin",
success: (result) => {
resolve({
code: result.code,
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);
},
// #ifndef H5
uni.login({
provider: "weixin",
success(result) {
prototype.$request({
api: 'user.openId',
data: {
code: result.code
}
}).then((response) => {
resolve(response.data);
});
}
});
// #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 => {
reject(e);
},
}).then((res) => {
if (res.code == 1) {
return resolve();
} else {
return reject(response.msg);
}
});
});
},
register() {
this.platformInfo().then(platfromUser => {
console.log(platfromUser);
}).catch(e => { });
},
login() {
uni.navigateTo({
url: '/pages/auth/login'
});
},
getInfo() {
/**
* 用户注册
*/
register(userData, verificationCode) {
return new Promise((resolve, reject) => {
resolve({
id: 123,
name: '李四'
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);
}
});
});
});
}

View File

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

View File

@ -63,7 +63,7 @@
<input
class="input"
type="number"
v-model="mobile"
v-model="verificationCode"
placeholder="请输入验证码"
placeholder-class="placeholder-style-3"
/>
@ -115,6 +115,7 @@ export default {
tabIndex: 0,
mobile: "",
password: "",
verificationCode: "",
isAgree: false,
};
},
@ -133,9 +134,14 @@ export default {
},
getVerifyCode() {
if (this.canUse) {
if (true) {
this.parseTime(10);
}
this.$models.user
.sendVerificationCode(this.mobile)
.then((response) => {
this.parseTime(60);
})
.catch((e) => {
this.$utils.toast(e);
});
} else {
this.$utils.toast("请稍后再试");
}
@ -155,10 +161,32 @@ export default {
},
login() {},
register() {
const that = this;
if (!this.isAgree) {
this.$utils.toast("请先阅读并同意《服务协议》《隐私政策》");
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;
border-bottom: 2rpx solid #d2d1d1;
.input {
position: relative;
width: 100%;
font-size: 32rpx;
color: #666666;
@ -235,6 +264,7 @@ export default {
}
}
.get-code {
z-index: 10;
position: absolute;
top: 0;
right: 0;

View File

@ -1,19 +1,15 @@
import user from '@/core/models/user'
export default {
namespaced: true,
state: {
showLoginModal: false,
isLogin: false,
openId: "",
token: "",
userInfo: null,
},
getters: {
showLoginModal(state) {
return state.showLoginModal;
},
isLogin(state) {
return state.isLogin;
},
userInfo(state) {
return state.userInfo;
},
@ -22,8 +18,11 @@ export default {
showLoginModal(state, data) {
state.showLoginModal = data;
},
isLogin(state, data) {
state.isLogin = data;
openId(state, data) {
state.openId = data;
},
token(state, data) {
state.token = data;
},
userInfo(state, data) {
state.userInfo = data;
@ -33,10 +32,5 @@ export default {
logout(context) {
context.commit('userInfo', null);
},
userInfo(context) {
user.getInfo().then(info => {
context.commit('userInfo', info);
});
}
}
}