admin-vben5/packages/effects/common-ui/src/ui/authentication/register.vue

122 lines
2.4 KiB
Vue
Raw Normal View History

2024-05-19 21:20:42 +08:00
<script setup lang="ts">
import type { Recordable } from '@vben/types';
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';
import { $t } from '@vben/locales';
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 {
formSchema?: VbenFormSchema[];
2024-05-19 21:20:42 +08:00
/**
* @zh_CN 是否处于加载处理状态
*/
loading?: boolean;
/**
* @zh_CN 登录路径
*/
loginPath?: string;
/**
* @zh_CN 标题
*/
title?: string;
/**
* @zh_CN 描述
*/
subTitle?: string;
/**
* @zh_CN 按钮文本
*/
submitButtonText?: string;
2024-05-19 21:20:42 +08:00
}
defineOptions({
name: 'RegisterForm',
});
const props = withDefaults(defineProps<Props>(), {
formSchema: () => [],
2024-05-19 21:20:42 +08:00
loading: false,
loginPath: '/auth/login',
submitButtonText: '',
subTitle: '',
title: '',
2024-05-19 21:20:42 +08:00
});
const emit = defineEmits<{
submit: [Recordable<any>];
2024-05-19 21:20:42 +08:00
}>();
const [Form, formApi] = useVbenForm(
reactive({
commonConfig: {
hideLabel: true,
hideRequiredMark: true,
},
schema: computed(() => props.formSchema),
showDefaultActions: false,
}),
);
2024-05-19 21:20:42 +08:00
const router = useRouter();
2024-05-19 21:20:42 +08:00
async function handleSubmit() {
const { valid } = await formApi.validate();
const values = await formApi.getValues();
if (valid) {
emit('submit', values as { password: string; username: string });
2024-05-19 21:20:42 +08:00
}
}
function goToLogin() {
router.push(props.loginPath);
2024-05-19 21:20:42 +08:00
}
defineExpose({
getFormApi: () => formApi,
});
2024-05-19 21:20:42 +08:00
</script>
<template>
<div>
<Title>
<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>
<Form />
2024-05-19 21:20:42 +08:00
2024-09-12 22:03:58 +08:00
<VbenButton
:class="{
'cursor-wait': loading,
}"
:loading="loading"
aria-label="register"
2024-09-12 22:03:58 +08:00
class="mt-2 w-full"
@click="handleSubmit"
>
<slot name="submitButtonText">
{{ submitButtonText || $t('authentication.signUp') }}
</slot>
</VbenButton>
2024-05-19 21:20:42 +08:00
<div class="mt-4 text-center text-sm">
{{ $t('authentication.alreadyHaveAccount') }}
<span class="vben-link text-sm font-normal" @click="goToLogin()">
{{ $t('authentication.goToLogin') }}
2024-05-19 21:20:42 +08:00
</span>
</div>
</div>
</template>