Files
certd/packages/ui/certd-client/src/views/framework/register/index.vue
T

322 lines
9.5 KiB
Vue
Raw Normal View History

2023-01-29 13:44:19 +08:00
<template>
<div class="main">
2025-06-29 14:09:09 +08:00
<a-form ref="formRef" class="user-layout-register" name="custom-validation" :model="formState" :rules="rules" v-bind="layout" :label-col="{ span: 6 }" @finish="handleFinish" @finish-failed="handleFinishFailed">
<a-tabs v-model:active-key="registerType" @change="handleTabChange">
2024-12-01 03:02:59 +08:00
<a-tab-pane key="username" tab="用户名注册" :disabled="!settingsStore.sysPublic.usernameRegisterEnabled">
2024-11-28 17:36:45 +08:00
<template v-if="registerType === 'username'">
<a-form-item required has-feedback name="username" label="用户名" :rules="rules.username">
2024-11-28 17:36:45 +08:00
<a-input v-model:value="formState.username" placeholder="用户名" size="large" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:person-outline"></fs-icon>
2024-11-28 17:36:45 +08:00
</template>
</a-input>
</a-form-item>
<a-form-item has-feedback name="password" label="密码" :rules="rules.password">
<a-input-password v-model:value="formState.password" placeholder="密码" size="large" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input-password>
</a-form-item>
<a-form-item has-feedback name="confirmPassword" label="确认密码">
<a-input-password v-model:value="formState.confirmPassword" placeholder="确认密码" size="large" autocomplete="off" :rules="rules.confirmPassword">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input-password>
</a-form-item>
<a-form-item has-feedback name="captcha" label="验证码" :rules="rules.captcha">
<CaptchaInput v-model:model-value="formState.captcha"></CaptchaInput>
</a-form-item>
2023-01-29 13:44:19 +08:00
</template>
2024-11-28 17:36:45 +08:00
</a-tab-pane>
2026-01-04 11:58:32 +08:00
<a-tab-pane v-if="settingsStore.sysPublic.emailRegisterEnabled !== false" key="email" tab="邮箱注册">
2024-11-28 17:36:45 +08:00
<template v-if="registerType === 'email'">
2025-08-07 18:52:20 +08:00
<a-form-item required has-feedback name="username" label="用户名" :rules="rules.username">
2025-08-07 10:36:34 +08:00
<a-input v-model:value="formState.username" placeholder="用户名" size="large" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:person-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
2024-11-28 17:36:45 +08:00
<a-form-item required has-feedback name="email" label="邮箱">
<a-input v-model:value="formState.email" placeholder="邮箱" size="large" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:mail-outline"></fs-icon>
2024-11-28 17:36:45 +08:00
</template>
</a-input>
</a-form-item>
<a-form-item has-feedback name="password" label="密码">
<a-input-password v-model:value="formState.password" placeholder="密码" size="large" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input-password>
</a-form-item>
<a-form-item has-feedback name="confirmPassword" label="确认密码">
<a-input-password v-model:value="formState.confirmPassword" placeholder="确认密码" size="large" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input-password>
</a-form-item>
2024-11-28 17:36:45 +08:00
2025-10-28 15:30:31 +08:00
<a-form-item has-feedback name="captchaForEmail" label="验证码" :rules="rules.captchaForEmail">
<CaptchaInput v-model:model-value="formState.captchaForEmail"></CaptchaInput>
2024-11-28 17:36:45 +08:00
</a-form-item>
<a-form-item has-feedback name="validateCode" :rules="rules.validateCode" label="邮件验证码">
2025-09-24 00:06:00 +08:00
<email-code v-model:value="formState.validateCode" :captcha="formState.captchaForEmail" :email="formState.email" @error="formState.captchaForEmail = null" />
2024-11-28 17:36:45 +08:00
</a-form-item>
</template>
</a-tab-pane>
<a-tab-pane v-if="settingsStore.sysPublic.smsLoginEnabled" key="mobile" tab="手机号注册"> </a-tab-pane>
2024-11-28 17:36:45 +08:00
</a-tabs>
2023-01-29 13:44:19 +08:00
<a-form-item>
<a-button type="primary" size="large" html-type="submit" class="login-button">注册</a-button>
</a-form-item>
<a-form-item class="user-login-other">
<router-link class="register" :to="{ name: 'login' }"> 登录 </router-link>
</a-form-item>
</a-form>
</div>
</template>
<script lang="ts">
2023-01-29 13:44:19 +08:00
import { defineComponent, reactive, ref, toRaw } from "vue";
2025-04-12 23:59:03 +08:00
import { useUserStore } from "/src/store/user";
import { utils } from "@fast-crud/fast-crud";
import EmailCode from "./email-code.vue";
2025-04-12 23:59:03 +08:00
import { useSettingStore } from "/@/store/settings";
2024-12-01 03:02:59 +08:00
import { notification } from "ant-design-vue";
import CaptchaInput from "/@/components/captcha/captcha-input.vue";
import { useRouter } from "vue-router";
2023-01-29 13:44:19 +08:00
export default defineComponent({
2023-06-27 09:29:43 +08:00
name: "RegisterPage",
components: { CaptchaInput, EmailCode },
2023-01-29 13:44:19 +08:00
setup() {
2024-12-01 03:02:59 +08:00
const settingsStore = useSettingStore();
const registerType = ref("email");
if (!settingsStore.sysPublic.emailRegisterEnabled) {
registerType.value = "username";
if (!settingsStore.sysPublic.usernameRegisterEnabled) {
registerType.value = "";
notification.error({
2025-06-29 14:09:09 +08:00
message: "没有启用任何一种注册方式",
2024-12-01 03:02:59 +08:00
});
}
}
2023-01-29 13:44:19 +08:00
const userStore = useUserStore();
const formRef = ref();
const formState: any = reactive({
2024-11-28 17:36:45 +08:00
mobile: "",
phoneCode: "",
email: "",
2023-01-29 13:44:19 +08:00
username: "",
2023-06-27 09:29:43 +08:00
password: "",
confirmPassword: "",
captcha: null,
2025-10-28 15:30:31 +08:00
captchaForEmail: null,
2023-01-29 13:44:19 +08:00
});
const rules = {
username: [
{
required: true,
trigger: "change",
2025-06-29 14:09:09 +08:00
message: "请输入用户名",
},
2023-01-29 13:44:19 +08:00
],
2024-11-28 17:36:45 +08:00
email: [
{
required: true,
trigger: "change",
2025-06-29 14:09:09 +08:00
message: "请输入邮箱",
},
{
type: "email",
2025-06-29 14:09:09 +08:00
message: "请输入正确的邮箱",
},
2024-11-28 17:36:45 +08:00
],
2023-01-29 13:44:19 +08:00
password: [
{
required: true,
trigger: "change",
2025-06-29 14:09:09 +08:00
message: "请输入密码",
},
2023-01-29 13:44:19 +08:00
],
confirmPassword: [
{
required: true,
trigger: "change",
2025-06-29 14:09:09 +08:00
message: "请确认密码",
},
{
validator: async (rule: any, value: any) => {
2024-11-30 01:57:09 +08:00
if (value && value !== formState.password) {
throw new Error("两次输入密码不一致");
}
return true;
2025-06-29 14:09:09 +08:00
},
},
],
smsCode: [
{
required: true,
2025-06-29 14:09:09 +08:00
message: "请输入短信验证码",
},
],
validateCode: [
{
required: true,
2025-06-29 14:09:09 +08:00
message: "请输入邮件验证码",
},
],
captcha: [
{
required: true,
message: "请通过验证码",
},
],
2025-10-28 15:30:31 +08:00
captchaForEmail: [
{
required: true,
2025-10-28 15:30:31 +08:00
message: "请通过验证码",
},
],
2023-01-29 13:44:19 +08:00
};
const layout = {
labelCol: {
2025-06-29 14:09:09 +08:00
span: 0,
2023-01-29 13:44:19 +08:00
},
wrapperCol: {
2025-06-29 14:09:09 +08:00
span: 24,
},
2023-01-29 13:44:19 +08:00
};
const handleFinish = async (values: any) => {
2025-09-24 00:06:00 +08:00
try {
await userStore.register(
toRaw({
type: registerType.value,
password: formState.password,
username: formState.username,
email: formState.email,
2025-10-28 15:30:31 +08:00
captcha: registerType.value === "email" ? formState.captchaForEmail : formState.captcha,
2025-09-24 00:06:00 +08:00
validateCode: formState.validateCode,
}) as any
);
} finally {
formState.captcha = null;
}
2023-01-29 13:44:19 +08:00
};
const handleFinishFailed = (errors: any) => {
utils.logger.log(errors);
2023-01-29 13:44:19 +08:00
};
const resetForm = () => {
formRef.value.resetFields();
};
const router = useRouter();
const handleTabChange = (key: string) => {
if (key === "mobile") {
router.push({ path: "/login", query: { loginType: "sms" } });
}
};
2023-01-29 13:44:19 +08:00
return {
formState,
formRef,
rules,
layout,
handleFinishFailed,
handleFinish,
2024-11-28 17:36:45 +08:00
resetForm,
2024-12-01 03:02:59 +08:00
registerType,
2025-06-29 14:09:09 +08:00
settingsStore,
handleTabChange,
2023-01-29 13:44:19 +08:00
};
2025-06-29 14:09:09 +08:00
},
2023-01-29 13:44:19 +08:00
});
</script>
<style lang="less">
2023-06-27 09:29:43 +08:00
.user-layout-register {
2023-01-29 13:44:19 +08:00
label {
font-size: 14px;
}
.ant-input-affix-wrapper {
line-height: 1.8 !important;
font-size: 14px !important;
> * {
line-height: 1.8 !important;
font-size: 14px !important;
}
}
.getCaptcha {
display: block;
width: 100%;
}
.image-code {
height: 34px;
}
.input-right {
width: 160px;
margin-left: 10px;
}
2023-01-29 13:44:19 +08:00
.login-title {
2023-06-27 09:29:43 +08:00
// color: @primary-color;
2023-01-29 13:44:19 +08:00
font-size: 18px;
text-align: center;
2023-06-27 09:29:43 +08:00
margin: 30px;
margin-top: 50px;
2023-01-29 13:44:19 +08:00
}
.forge-password {
font-size: 14px;
}
button.login-button {
padding: 0 15px;
font-size: 16px;
height: 40px;
width: 100%;
}
.user-login-other {
text-align: left;
margin-top: 30px;
margin-bottom: 30px;
line-height: 22px;
.item-icon {
font-size: 24px;
color: rgba(0, 0, 0, 0.2);
margin-left: 16px;
vertical-align: middle;
cursor: pointer;
transition: color 0.3s;
&:hover {
}
}
.register {
float: right;
}
}
.iconify {
color: rgba(0, 0, 0, 0.45);
}
}
</style>