2024-05-19 21:20:42 +08:00
|
|
|
<script setup lang="ts">
|
2024-10-20 21:44:25 +08:00
|
|
|
import type { Recordable } from '@vben/types';
|
2025-01-01 11:39:49 +08:00
|
|
|
|
2024-09-10 21:48:51 +08:00
|
|
|
import type { VbenFormSchema } from '@vben-core/form-ui';
|
|
|
|
|
2024-06-08 19:49:06 +08:00
|
|
|
import { computed, reactive } from 'vue';
|
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
2024-07-23 00:03:59 +08:00
|
|
|
import { $t } from '@vben/locales';
|
2025-01-01 11:39:49 +08:00
|
|
|
|
2024-09-10 21:48:51 +08:00
|
|
|
import { useVbenForm } from '@vben-core/form-ui';
|
|
|
|
import { VbenButton } from '@vben-core/shadcn-ui';
|
2024-05-19 21:20:42 +08:00
|
|
|
|
|
|
|
import Title from './auth-title.vue';
|
|
|
|
|
|
|
|
interface Props {
|
2025-04-27 22:06:49 +08:00
|
|
|
formSchema?: VbenFormSchema[];
|
2024-05-19 21:20:42 +08:00
|
|
|
/**
|
|
|
|
* @zh_CN 是否处于加载处理状态
|
|
|
|
*/
|
|
|
|
loading?: boolean;
|
2024-06-02 21:21:34 +08:00
|
|
|
/**
|
2024-10-20 21:44:25 +08:00
|
|
|
* @zh_CN 登录路径
|
2024-06-02 21:21:34 +08:00
|
|
|
*/
|
|
|
|
loginPath?: string;
|
2024-09-11 23:10:35 +08:00
|
|
|
/**
|
|
|
|
* @zh_CN 标题
|
|
|
|
*/
|
|
|
|
title?: string;
|
|
|
|
/**
|
|
|
|
* @zh_CN 描述
|
|
|
|
*/
|
|
|
|
subTitle?: string;
|
|
|
|
/**
|
|
|
|
* @zh_CN 按钮文本
|
|
|
|
*/
|
|
|
|
submitButtonText?: string;
|
2024-05-19 21:20:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
defineOptions({
|
|
|
|
name: 'RegisterForm',
|
|
|
|
});
|
|
|
|
|
2024-06-02 21:21:34 +08:00
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
2024-09-10 21:48:51 +08:00
|
|
|
formSchema: () => [],
|
2024-05-19 21:20:42 +08:00
|
|
|
loading: false,
|
2024-07-23 00:03:59 +08:00
|
|
|
loginPath: '/auth/login',
|
2024-09-11 23:10:35 +08:00
|
|
|
submitButtonText: '',
|
|
|
|
subTitle: '',
|
|
|
|
title: '',
|
2024-05-19 21:20:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
2024-10-20 21:44:25 +08:00
|
|
|
submit: [Recordable<any>];
|
2024-05-19 21:20:42 +08:00
|
|
|
}>();
|
|
|
|
|
2024-11-04 22:46:16 +08:00
|
|
|
const [Form, formApi] = useVbenForm(
|
2024-09-10 21:48:51 +08:00
|
|
|
reactive({
|
|
|
|
commonConfig: {
|
|
|
|
hideLabel: true,
|
|
|
|
hideRequiredMark: true,
|
|
|
|
},
|
|
|
|
schema: computed(() => props.formSchema),
|
|
|
|
showDefaultActions: false,
|
|
|
|
}),
|
|
|
|
);
|
2024-05-19 21:20:42 +08:00
|
|
|
|
2024-09-10 21:48:51 +08:00
|
|
|
const router = useRouter();
|
2024-05-19 21:20:42 +08:00
|
|
|
|
2024-09-10 21:48:51 +08:00
|
|
|
async function handleSubmit() {
|
2024-11-04 22:46:16 +08:00
|
|
|
const { valid } = await formApi.validate();
|
|
|
|
const values = await formApi.getValues();
|
2024-09-10 21:48:51 +08:00
|
|
|
if (valid) {
|
|
|
|
emit('submit', values as { password: string; username: string });
|
2024-05-19 21:20:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-12 12:14:09 +08:00
|
|
|
function goToLogin() {
|
2024-06-02 21:21:34 +08:00
|
|
|
router.push(props.loginPath);
|
2024-05-19 21:20:42 +08:00
|
|
|
}
|
2024-11-04 22:46:16 +08:00
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
getFormApi: () => formApi,
|
|
|
|
});
|
2024-05-19 21:20:42 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<Title>
|
2024-09-11 23:10:35 +08:00
|
|
|
<slot name="title">
|
|
|
|
{{ title || $t('authentication.createAnAccount') }} 🚀
|
|
|
|
</slot>
|
|
|
|
<template #desc>
|
|
|
|
<slot name="subTitle">
|
|
|
|
{{ subTitle || $t('authentication.signUpSubtitle') }}
|
|
|
|
</slot>
|
|
|
|
</template>
|
2024-05-19 21:20:42 +08:00
|
|
|
</Title>
|
2024-09-10 21:48:51 +08:00
|
|
|
<Form />
|
2024-05-19 21:20:42 +08:00
|
|
|
|
2024-09-12 22:03:58 +08:00
|
|
|
<VbenButton
|
|
|
|
:class="{
|
|
|
|
'cursor-wait': loading,
|
|
|
|
}"
|
|
|
|
:loading="loading"
|
2024-09-22 21:35:40 +08:00
|
|
|
aria-label="register"
|
2024-09-12 22:03:58 +08:00
|
|
|
class="mt-2 w-full"
|
|
|
|
@click="handleSubmit"
|
|
|
|
>
|
2024-09-11 23:10:35 +08:00
|
|
|
<slot name="submitButtonText">
|
|
|
|
{{ submitButtonText || $t('authentication.signUp') }}
|
|
|
|
</slot>
|
2024-09-10 21:48:51 +08:00
|
|
|
</VbenButton>
|
2024-05-19 21:20:42 +08:00
|
|
|
<div class="mt-4 text-center text-sm">
|
2024-07-10 21:55:16 +08:00
|
|
|
{{ $t('authentication.alreadyHaveAccount') }}
|
2024-10-20 22:34:11 +08:00
|
|
|
<span class="vben-link text-sm font-normal" @click="goToLogin()">
|
2024-07-10 21:55:16 +08:00
|
|
|
{{ $t('authentication.goToLogin') }}
|
2024-05-19 21:20:42 +08:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|