新增用户注册功能
This commit is contained in:
parent
54881ca611
commit
ea9859b523
@ -22,6 +22,22 @@ export function getUserInfo() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 用户注册
|
||||
*/
|
||||
export function register(params) {
|
||||
return http.request(
|
||||
{
|
||||
url: '/register',
|
||||
method: 'POST',
|
||||
params,
|
||||
},
|
||||
{
|
||||
isTransformResponse: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 用户登录
|
||||
*/
|
||||
|
@ -4,12 +4,12 @@
|
||||
:show-label="false"
|
||||
:show-require-mark="false"
|
||||
size="large"
|
||||
:model="formInline"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
class="register-form"
|
||||
>
|
||||
<n-form-item path="username">
|
||||
<n-input v-model:value="formInline.username" placeholder="请输入用户名">
|
||||
<n-input v-model:value="formData.username" placeholder="请输入用户名">
|
||||
<template #prefix>
|
||||
<n-icon size="18" color="#808695">
|
||||
<UserOutlined />
|
||||
@ -18,7 +18,7 @@
|
||||
</n-input>
|
||||
</n-form-item>
|
||||
<n-form-item path="mobile">
|
||||
<n-input v-model:value="formInline.mobile" placeholder="请输入手机号码">
|
||||
<n-input v-model:value="formData.mobile" placeholder="请输入手机号码">
|
||||
<template #prefix>
|
||||
<n-icon size="18" color="#808695">
|
||||
<MobileOutlined />
|
||||
@ -27,7 +27,7 @@
|
||||
</n-input>
|
||||
</n-form-item>
|
||||
<n-form-item path="code">
|
||||
<n-input v-model:value.trim="formInline.code" placeholder="验证码">
|
||||
<n-input v-model:value.trim="formData.code" placeholder="验证码">
|
||||
<template #prefix>
|
||||
<n-icon size="18" color="#808695">
|
||||
<SafetyCertificateOutlined />
|
||||
@ -42,7 +42,7 @@
|
||||
</n-form-item>
|
||||
<n-form-item path="password">
|
||||
<n-input
|
||||
v-model:value="formInline.password"
|
||||
v-model:value="formData.password"
|
||||
type="password"
|
||||
show-password-on="mousedown"
|
||||
placeholder="请输入密码"
|
||||
@ -56,7 +56,7 @@
|
||||
</n-form-item>
|
||||
<n-form-item path="retPassword">
|
||||
<n-input
|
||||
v-model:value="formInline.retPassword"
|
||||
v-model:value="formData.retPassword"
|
||||
type="password"
|
||||
show-password-on="mousedown"
|
||||
placeholder="请再次输入密码"
|
||||
@ -74,7 +74,7 @@
|
||||
<n-form-item class="default-color" path="agreement">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex-initial">
|
||||
<n-checkbox v-model:checked="formInline.agreement">我同意隐私协议</n-checkbox>
|
||||
<n-checkbox v-model:checked="formData.agreement">我同意隐私协议</n-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</n-form-item>
|
||||
@ -85,6 +85,8 @@
|
||||
import { reactive, ref } from 'vue';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { rule } from '@/utils/validate';
|
||||
import { ResultEnum } from '@/enums/httpEnum';
|
||||
import { register } from '@/api/system/user';
|
||||
import {
|
||||
UserOutlined,
|
||||
MobileOutlined,
|
||||
@ -100,13 +102,12 @@
|
||||
const loading = ref(false);
|
||||
const codeMsg: any = ref('获取验证码');
|
||||
const isGetCode = ref(false);
|
||||
|
||||
const emit = defineEmits(['backLogin']);
|
||||
|
||||
/**
|
||||
* 定义表单参数
|
||||
*/
|
||||
const formInline = reactive({
|
||||
const formData = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
retPassword: '',
|
||||
@ -162,10 +163,21 @@
|
||||
.validate()
|
||||
.then(async () => {
|
||||
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) => {
|
||||
console.log(error);
|
||||
message.error('请填写完整信息');
|
||||
});
|
||||
};
|
||||
@ -181,7 +193,7 @@
|
||||
* 获取验证码
|
||||
*/
|
||||
function getCode() {
|
||||
if (!formInline.mobile) {
|
||||
if (!formData.mobile) {
|
||||
formRef.value?.validate(
|
||||
(errors) => {},
|
||||
(rule) => {
|
||||
|
Loading…
Reference in New Issue
Block a user