用户注册 代码调整

This commit is contained in:
joylink_cuiweidong 2022-12-13 15:32:32 +08:00
parent 8e498c45f6
commit 81152cb252

View File

@ -2,36 +2,70 @@
<el-dialog
:title="title"
:visible.sync="dialogShow"
class="rigisterDialog"
width="500px"
:before-close="doClose"
:z-index="9000"
:show-close="false"
:close-on-click-modal="false"
top="25vh"
top="18vh"
>
<el-form ref="ruleForm" :model="form" :rules="rules" label-width="110px" class="demo-ruleForm" style="margin-left: 60px;width:330px">
<el-form ref="ruleForm" :model="form" :rules="rules" label-width="110px" class="rigister-ruleForm" style="margin-left:30px;width:380px">
<el-form-item prop="type">
<template slot="label">
<span>注册途径</span>
</template>
<el-radio-group v-model="form.type" size="small" @change="changeType">
<el-radio label="phone" border>手机号注册</el-radio>
<el-radio label="email" border>邮箱注册</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="form.type === 'email'" prop="email">
<template slot="label">
<span>邮箱(账号)</span>
</template>
<el-input v-model="form.email" size="small" style="width:260px" />
</el-form-item>
<el-form-item v-if="form.type === 'phone'" prop="phone">
<template slot="label">
<span>手机号</span>
</template>
<el-input v-model="form.phone" size="small" style="width: 260px;" />
</el-form-item>
<el-form-item prop="nickname">
<template slot="label">
<span>&emsp;&emsp;</span>
</template>
<el-input v-model="form.nickname" autocomplete="new-password" size="small" style="width:200px" />
</el-form-item>
<el-form-item prop="email">
<template slot="label">
<span>邮箱(账号)</span>
</template>
<el-input v-model="form.email" size="small" style="width:200px" />
<el-input v-model="form.nickname" autocomplete="new-password" size="small" style="width:260px" />
</el-form-item>
<el-form-item label="密码:" prop="password">
<template slot="label">
<span>&emsp;&emsp;</span>
</template>
<el-input v-model="form.password" autocomplete="new-password" show-password size="small" style="width:200px" />
<el-input v-model="form.password" autocomplete="new-password" show-password size="small" style="width:260px" />
</el-form-item>
<el-form-item label="密码确认:" prop="repeatPassword">
<el-input v-model="form.repeatPassword" autocomplete="new-password" show-password size="small" style="width:200px" />
<el-input v-model="form.repeatPassword" autocomplete="new-password" show-password size="small" style="width:260px" />
</el-form-item>
<div style="display: flex;justify-content: space-around;">
<el-form-item prop="vfCode">
<template slot="label">
<span>验证码</span>
</template>
<el-input v-model="form.vfCode" size="small" style="display: inline-block;width:140px" />
<el-button
size="small"
type="primary"
style="margin-top: 10px; margin-right: 10px;"
:disabled="passWordCodeTime != 0"
@click="sendVfcode"
>
{{ $t('global.sendCode') }}
<span
v-if="passWordCodeTime"
>{{ passWordCodeTime }}</span>
</el-button>
</el-form-item>
<div style="display: flex;justify-content: space-around;margin-top:40px;">
<el-button type="primary" size="small" @click="submitForm()">立即创建</el-button>
<el-button size="small" @click="doClose()">返回登录</el-button>
</div>
@ -54,6 +88,15 @@ export default {
callback();
}
};
var validatePhone = (rule, value, callback) => {
const regu = /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$/;
const re = new RegExp(regu);
if (!re.test(value)) {
callback(new Error('手机号格式不正确'));
} else {
callback();
}
};
var validatePassword = (rule, value, callback) => {
if (this.form.repeatPassword) {
this.$refs.ruleForm.validateField('repeatPassword');
@ -67,18 +110,34 @@ export default {
callback();
}
};
var validateVfCode = (rule, value, callback) => {
if (this.form.vfCode.length !== 4) {
callback(new Error('验证码长度错误'));
} else {
callback();
}
};
return {
dialogShow: false,
passWordCodeTime: 0,
passWordTime: null,
message: '',
operation: '',
title: '账号注册',
form: {
type: 'phone',
phone: '',
email: '',
nickname: '',
password: '',
repeatPassword: ''
repeatPassword: '',
vfCode:''
},
rules: {
phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' },
{ validator: validatePhone, trigger: 'blur' }
],
email: [
{ required: true, message: '请输入邮箱', trigger: 'blur' },
{ validator: validateEmail, trigger: 'blur' }
@ -96,6 +155,10 @@ export default {
{ required: true, message: '请重复输入密码', trigger: 'blur' },
{ validator: validateRepeatPassword, trigger: 'blur' },
{ min: 5, max: 20, message: '长度在 5 到 20 个字符', trigger: 'blur' }
],
vfCode: [
{ required: true, message: '请输入验证码', trigger: 'blur' },
{ validator: validateVfCode, trigger: 'blur' }
]
}
};
@ -108,23 +171,83 @@ export default {
methods: {
doShow() {
this.form = {
type: 'phone',
phone: '',
email: '',
nickname: '',
password: '',
repeatPassword: ''
repeatPassword: '',
vfCode: ''
};
this.dialogShow = true;
},
doClose() {
this.dialogShow = false;
this.form = {
type: 'phone',
phone: '',
email: '',
nickname: '',
password: '',
repeatPassword: ''
repeatPassword: '',
vfCode: ''
};
this.$refs.ruleForm.clearValidate();
},
changeType() {
this.$refs.ruleForm.clearValidate();
},
async sendVfcode() {
const reguEmail = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
const reguPhone = /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$/;
const rePhone = new RegExp(reguPhone);
const reEmail = new RegExp(reguEmail);
if (this.form.type === 'phone' && this.form.phone && rePhone.test(this.form.phone)) {
const random = Math.floor(Math.random() * 10000 + 1);
const timeCount = Date.parse(new Date()) / 1000;
const pass = `${timeCount}86${this.form.phone}${random}`;
const param = {
mobile: this.form.phone,
nationCode: '86',
rd: random + '',
time: timeCount + '',
token: md5(pass)
};
try {
this.passWordCodeTime = 60;
this.passWordTime = setInterval(() => {
this.passWordCodeTime--;
if (this.passWordCodeTime <= 0) {
this.passWordCodeTime = 0;
clearInterval(this.mobileTime);
this.passWordTime = null;
}
}, 1000);
// await sendPhoneVfcode(param);
} catch (error) {
this.$message.info(this.$t('global.codeFaile'));
}
} else if (this.form.type === 'email' && this.form.email && reEmail.test(this.form.email)) {
const param = { email: this.form.email };
try {
this.passWordCodeTime = 60;
this.passWordTime = setInterval(() => {
this.passWordCodeTime--;
if (this.passWordCodeTime <= 0) {
this.passWordCodeTime = 0;
clearInterval(this.mobileTime);
this.passWordTime = null;
}
}, 1000);
// await sendEmailVfcode(param);
} catch (error) {
this.$message.info(this.$t('global.codeFaile'));
}
} else {
this.$refs.ruleForm.validateField('email');
this.$refs.ruleForm.validateField('phone');
}
},
submitForm() {
this.$refs.ruleForm.validate((valid) => {
if (valid) {
@ -143,3 +266,8 @@ export default {
}
};
</script>
<style lang="scss">
.rigisterDialog .el-dialog__body{
padding-top:15px;
}
</style>