forget-password.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <script setup lang="ts">
  2. import type { VbenFormSchema } from '@vben-core/form-ui';
  3. import { computed, reactive } from 'vue';
  4. import { useRouter } from 'vue-router';
  5. import { $t } from '@vben/locales';
  6. import { useVbenForm } from '@vben-core/form-ui';
  7. import { VbenButton } from '@vben-core/shadcn-ui';
  8. import Title from './auth-title.vue';
  9. interface Props {
  10. formSchema: VbenFormSchema[];
  11. /**
  12. * @zh_CN 是否处于加载处理状态
  13. */
  14. loading?: boolean;
  15. /**
  16. * @zh_CN 登陆路径
  17. */
  18. loginPath?: string;
  19. /**
  20. * @zh_CN 标题
  21. */
  22. title?: string;
  23. /**
  24. * @zh_CN 描述
  25. */
  26. subTitle?: string;
  27. /**
  28. * @zh_CN 按钮文本
  29. */
  30. submitButtonText?: string;
  31. }
  32. defineOptions({
  33. name: 'ForgetPassword',
  34. });
  35. const props = withDefaults(defineProps<Props>(), {
  36. loading: false,
  37. loginPath: '/auth/login',
  38. submitButtonText: '',
  39. subTitle: '',
  40. title: '',
  41. });
  42. const emit = defineEmits<{
  43. submit: [string];
  44. }>();
  45. const [Form, { validate }] = useVbenForm(
  46. reactive({
  47. commonConfig: {
  48. hideLabel: true,
  49. hideRequiredMark: true,
  50. },
  51. schema: computed(() => props.formSchema),
  52. showDefaultActions: false,
  53. }),
  54. );
  55. const router = useRouter();
  56. async function handleSubmit() {
  57. const { valid, values } = await validate();
  58. if (valid) {
  59. emit('submit', values?.email);
  60. }
  61. }
  62. function goToLogin() {
  63. router.push(props.loginPath);
  64. }
  65. </script>
  66. <template>
  67. <div>
  68. <Title>
  69. <slot name="title">
  70. {{ title || $t('authentication.forgetPassword') }} 🤦🏻‍♂️
  71. </slot>
  72. <template #desc>
  73. <slot name="subTitle">
  74. {{ subTitle || $t('authentication.forgetPasswordSubtitle') }}
  75. </slot>
  76. </template>
  77. </Title>
  78. <Form />
  79. <div>
  80. <VbenButton class="mt-2 w-full" @click="handleSubmit">
  81. <slot name="submitButtonText">
  82. {{ submitButtonText || $t('authentication.sendResetLink') }}
  83. </slot>
  84. </VbenButton>
  85. <VbenButton class="mt-4 w-full" variant="outline" @click="goToLogin()">
  86. {{ $t('common.back') }}
  87. </VbenButton>
  88. </div>
  89. </div>
  90. </template>