|
@@ -0,0 +1,243 @@
|
|
|
+<template>
|
|
|
+ <div class="content">
|
|
|
+ <h1>注册账号</h1>
|
|
|
+
|
|
|
+ <el-form ref="formRef" :model="form" class="form">
|
|
|
+ <el-form-item prop="username">
|
|
|
+ <el-input v-model="form.username" placeholder="输入用户名" :prefix-icon="User" />
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item prop="email">
|
|
|
+ <el-input v-model="form.email" placeholder="输入邮箱" :prefix-icon="Postcard" />
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item prop="text">
|
|
|
+ <div class="captcha">
|
|
|
+ <el-input v-model="form.text" placeholder="输入验证码" class="captcha-input" :prefix-icon="Finished" />
|
|
|
+ <img alt="验证码" :src="ImageCaptcha" @click="getCaptcha">
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item prop="code">
|
|
|
+ <el-input v-model="form.code" placeholder="邮箱验证码" :prefix-icon="Finished">
|
|
|
+ <template #append>
|
|
|
+ <div @click="sendEmail" v-if="time === 0">获取验证码</div>
|
|
|
+ <div disabled v-else>{{ time }} s</div>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item prop="password1">
|
|
|
+ <el-input v-model="form.password1" placeholder="设置密码" type="password" :prefix-icon="Lock" />
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item prop="password2">
|
|
|
+ <el-input v-model="form.password2" placeholder="再次输入密码" type="password" :prefix-icon="Lock" />
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <button @click="Register()">注册</button>
|
|
|
+ <div class="littleButton">
|
|
|
+ <span @click="update('Index')">已有账号,立即登录</span> |
|
|
|
+ <span @click="update('forget')">忘记密码</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { ServerAPI } from '../../../app/lib/ServerAPI';
|
|
|
+import { User, Lock, Postcard, Finished } from '@element-plus/icons-vue';
|
|
|
+
|
|
|
+let ImageCaptcha = ref('');
|
|
|
+let form = reactive({
|
|
|
+ username: '',
|
|
|
+ email: '',
|
|
|
+ password1: '',
|
|
|
+ password2: '',
|
|
|
+ text: '',
|
|
|
+ id: '',
|
|
|
+ code: ''
|
|
|
+});
|
|
|
+
|
|
|
+let time = ref(0);
|
|
|
+let disabled = ref(false);
|
|
|
+
|
|
|
+const emit = defineEmits(['update']);
|
|
|
+
|
|
|
+let update = (mode) => {
|
|
|
+ emit('update', mode);
|
|
|
+}
|
|
|
+
|
|
|
+let getCaptcha = () => {
|
|
|
+ ServerAPI.ImageCaptcha((r) => {
|
|
|
+ if (!r || r.code != 0)
|
|
|
+ ElMessage.error(`获取图片验证码失败!${r.msg}`);
|
|
|
+
|
|
|
+ ImageCaptcha.value = r.data.img;
|
|
|
+ form.id = r.data.id;
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ getCaptcha()
|
|
|
+})
|
|
|
+
|
|
|
+let settime = () => {
|
|
|
+ time.value = 60;
|
|
|
+ const timer = setInterval(() => {
|
|
|
+ if (time.value > 0) {
|
|
|
+ time.value--;
|
|
|
+ } else {
|
|
|
+ clearInterval(timer)
|
|
|
+ }
|
|
|
+ }, 1000)
|
|
|
+}
|
|
|
+
|
|
|
+let sendEmail = () => {
|
|
|
+ if (disabled.value)
|
|
|
+ return ElMessage.warning('您的操作太快了,休息一下吧!');
|
|
|
+ if (form.email == '')
|
|
|
+ return ElMessage.error('请填写邮箱');
|
|
|
+ if (form.text == '')
|
|
|
+ return ElMessage.error('请填写图片验证码');
|
|
|
+
|
|
|
+ disabled.value = true;
|
|
|
+ ServerAPI.SendEmail(form.email, form.text, form.id, 'register', (r) => {
|
|
|
+ if (r && r.code === 0) {
|
|
|
+ ElMessage.success('发送邮箱验证码成功!');
|
|
|
+ settime();
|
|
|
+ disabled.value = false;
|
|
|
+ } else {
|
|
|
+ ElMessage.error(`获取邮箱验证码失败!${r.msg || ''}`);
|
|
|
+ disabled.value = false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function checkUsername(username) {
|
|
|
+ const regex = /^[\u4e00-\u9fa5A-Za-z0-9]{2,8}$/;
|
|
|
+ return regex.test(username);
|
|
|
+}
|
|
|
+
|
|
|
+function CheckPassword(password) {
|
|
|
+ if (password.length < 8 || password.length > 16) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用正则表达式检查密码是否包含至少一个字母和一个数字
|
|
|
+ const hasLetter = /[a-zA-Z]/.test(password); // 检查是否包含字母
|
|
|
+ const hasNumber = /\d/.test(password); // 检查是否包含数字
|
|
|
+
|
|
|
+ return hasLetter && hasNumber;
|
|
|
+}
|
|
|
+
|
|
|
+let Register = () => {
|
|
|
+ if (form.username === '' || form.password1 === '' || form.password2 === '' || form.email === '' || form.code === '' || form.text === '')
|
|
|
+ return ElMessage.error('请确保每项不能为空');
|
|
|
+ if (!checkUsername(form.username))
|
|
|
+ return ElMessage.error('用户名需在2到8位之间,且只能含有英文字母和汉字');
|
|
|
+ if (!CheckPassword(form.password1))
|
|
|
+ return ElMessage.error('密码需在8到16位之间,且包含字母和数字');
|
|
|
+ if (form.password1 !== form.password2)
|
|
|
+ return ElMessage.error('请确保两次输入的密码一致');
|
|
|
+
|
|
|
+ let password = btoa(form.password1);
|
|
|
+ ServerAPI.Register(form.username, form.email, form.code, password, (res) => {
|
|
|
+ if (!res || res.code !== 0)
|
|
|
+ return ElMessage.error(`注册失败!${res.msg || ''}`);
|
|
|
+
|
|
|
+ ElMessage.success('注册成功!');
|
|
|
+ update('PasswordLogin');
|
|
|
+ });
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.content {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ flex-direction: column;
|
|
|
+ background-color: rgba(255, 255, 255, 0.7);
|
|
|
+ position: absolute;
|
|
|
+ top: 50%;
|
|
|
+ left: 50%;
|
|
|
+ transform: translate(-50%, -50%);
|
|
|
+ height: 650px;
|
|
|
+ width: 650px;
|
|
|
+ box-sizing: border-box;
|
|
|
+ border-radius: 10px;
|
|
|
+}
|
|
|
+
|
|
|
+.content .input {
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ gap: 15px;
|
|
|
+}
|
|
|
+
|
|
|
+.content h1 {
|
|
|
+ color: #337ecc;
|
|
|
+ font-size: 2em;
|
|
|
+ margin: 0;
|
|
|
+ margin-bottom: 20px;
|
|
|
+}
|
|
|
+
|
|
|
+.el-input {
|
|
|
+ border-radius: 15px;
|
|
|
+ height: 50px;
|
|
|
+}
|
|
|
+
|
|
|
+.content .captcha {
|
|
|
+ display: flex;
|
|
|
+ height: 50px;
|
|
|
+}
|
|
|
+
|
|
|
+.content button {
|
|
|
+ width: 180px;
|
|
|
+ height: 40px;
|
|
|
+ margin-top: 20px;
|
|
|
+ font-size: 1em;
|
|
|
+ border: none;
|
|
|
+ border-radius: 10px;
|
|
|
+ background-color: #337ecc;
|
|
|
+ color: #fff;
|
|
|
+}
|
|
|
+
|
|
|
+.content .littleButton {
|
|
|
+ color: #444;
|
|
|
+ margin-top: 20px;
|
|
|
+ font-size: 0.9em;
|
|
|
+}
|
|
|
+
|
|
|
+@media only screen and (max-width: 768px) {
|
|
|
+ .content {
|
|
|
+ width: 80%;
|
|
|
+ height: 60%;
|
|
|
+ padding: 25px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-input {
|
|
|
+ height: 40px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content .captcha {
|
|
|
+ height: 40px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content h1 {
|
|
|
+ font-size: 1.5em;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content button {
|
|
|
+ height: 35px;
|
|
|
+ width: 150px;
|
|
|
+ font-size: 0.9em;
|
|
|
+ }
|
|
|
+
|
|
|
+ .content .littleButton {
|
|
|
+ font-size: 0.8em;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|