新增用户注册

This commit is contained in:
zjl 2024-12-20 10:08:46 +08:00
parent c0612fc4fd
commit fbac9da5a0
2 changed files with 44 additions and 16 deletions

View File

@ -22,6 +22,22 @@ export function getUserInfo() {
}); });
} }
/**
* @description:
*/
export function register(params) {
return http.request(
{
url: '/register',
method: 'POST',
params,
},
{
isTransformResponse: false,
},
);
}
/** /**
* @description: * @description:
*/ */
@ -246,6 +262,6 @@ export function sendMsg(data) {
return http.request({ return http.request({
url: '/websocket/sendMsg', url: '/websocket/sendMsg',
method: 'post', method: 'post',
data data,
}); });
} }

View File

@ -4,26 +4,26 @@
:show-label="false" :show-label="false"
:show-require-mark="false" :show-require-mark="false"
size="large" size="large"
:model="formInline" :model="formData"
:rules="rules" :rules="rules"
class="register-form" class="register-form"
> >
<a-form-item name="username"> <a-form-item name="username">
<a-input v-model:value="formInline.username" placeholder="请输入用户名"> <a-input v-model:value="formData.username" placeholder="请输入用户名">
<template #prefix> <template #prefix>
<UserOutlined style="color: #808695; font-size: 18px" /> <UserOutlined style="color: #808695; font-size: 18px" />
</template> </template>
</a-input> </a-input>
</a-form-item> </a-form-item>
<a-form-item name="mobile"> <a-form-item name="mobile">
<a-input v-model:value="formInline.mobile" placeholder="请输入手机号码"> <a-input v-model:value="formData.mobile" placeholder="请输入手机号码">
<template #prefix> <template #prefix>
<MobileOutlined style="color: #808695; font-size: 18px" /> <MobileOutlined style="color: #808695; font-size: 18px" />
</template> </template>
</a-input> </a-input>
</a-form-item> </a-form-item>
<a-form-item name="code"> <a-form-item name="code">
<a-input v-model:value.trim="formInline.code" placeholder="验证码"> <a-input v-model:value.trim="formData.code" placeholder="验证码">
<template #prefix> <template #prefix>
<SafetyCertificateOutlined style="color: #808695; font-size: 18px" /> <SafetyCertificateOutlined style="color: #808695; font-size: 18px" />
</template> </template>
@ -36,7 +36,7 @@
</a-form-item> </a-form-item>
<a-form-item name="password"> <a-form-item name="password">
<a-input <a-input
v-model:value="formInline.password" v-model:value="formData.password"
type="password" type="password"
show-password show-password
placeholder="请输入密码" placeholder="请输入密码"
@ -48,7 +48,7 @@
</a-form-item> </a-form-item>
<a-form-item name="retPassword"> <a-form-item name="retPassword">
<a-input <a-input
v-model:value="formInline.retPassword" v-model:value="formData.retPassword"
type="password" type="password"
show-password show-password
placeholder="请再次输入密码" placeholder="请再次输入密码"
@ -66,7 +66,7 @@
<a-form-item class="default-color" name="agreement"> <a-form-item class="default-color" name="agreement">
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<div class="flex-initial"> <div class="flex-initial">
<a-checkbox v-model:checked="formInline.agreement">我同意隐私协议</a-checkbox> <a-checkbox v-model:checked="formData.agreement">我同意隐私协议</a-checkbox>
</div> </div>
</div> </div>
</a-form-item> </a-form-item>
@ -77,7 +77,8 @@
import { reactive, ref } from 'vue'; import { reactive, ref } from 'vue';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import type { Rule } from 'ant-design-vue/es/form'; import type { Rule } from 'ant-design-vue/es/form';
import type { FormInstance } from 'ant-design-vue'; import { ResultEnum } from '@/enums/httpEnum';
import { register } from '@/api/system/user';
import { import {
UserOutlined, UserOutlined,
MobileOutlined, MobileOutlined,
@ -88,7 +89,7 @@
/** /**
* 定义参数 * 定义参数
*/ */
const formRef = ref<FormInstance>(); const formRef = ref();
const loading = ref(false); const loading = ref(false);
const codeMsg: any = ref('获取验证码'); const codeMsg: any = ref('获取验证码');
const isGetCode = ref(false); const isGetCode = ref(false);
@ -97,7 +98,7 @@
/** /**
* 定义表单参数 * 定义表单参数
*/ */
const formInline = reactive({ const formData = reactive({
username: '', username: '',
password: '', password: '',
retPassword: '', retPassword: '',
@ -125,7 +126,7 @@
/** /**
* 验证规则定义 * 验证规则定义
*/ */
const rules: Record<string, Rule[]> = { const rules = {
username: { required: true, message: '请输入用户名', trigger: 'blur' }, username: { required: true, message: '请输入用户名', trigger: 'blur' },
mobile: [{ required: true, validator: validatePhone, trigger: 'blur' }], mobile: [{ required: true, validator: validatePhone, trigger: 'blur' }],
code: { required: true, message: '请输入短信验证码', trigger: 'blur' }, code: { required: true, message: '请输入短信验证码', trigger: 'blur' },
@ -153,10 +154,21 @@
.validate() .validate()
.then(async () => { .then(async () => {
loading.value = true; loading.value = true;
backLogin();
loading.value = false; try {
const { code, msg } = await register(formData);
if (code == ResultEnum.SUCCESS) {
message.success('注册成功,请登录');
backLogin();
} else {
message.error(msg || '登录失败');
}
} finally {
loading.value = false;
}
}) })
.catch((error) => { .catch((error) => {
console.log(error);
message.error('请填写完整信息'); message.error('请填写完整信息');
}); });
}; };
@ -172,7 +184,7 @@
* 获取验证码 * 获取验证码
*/ */
function getCode() { function getCode() {
if (!formInline.mobile) { if (!formData.mobile) {
formRef.value.validateFields('mobile'); formRef.value.validateFields('mobile');
return; return;
} }