register.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <script lang="ts" setup>
  2. import type { VbenFormSchema } from '@vben/common-ui';
  3. import type { Recordable } from '@vben/types';
  4. import { computed, h, ref } from 'vue';
  5. import { AuthenticationRegister, z } from '@vben/common-ui';
  6. import { $t } from '@vben/locales';
  7. defineOptions({ name: 'Register' });
  8. const loading = ref(false);
  9. const formSchema = computed((): VbenFormSchema[] => {
  10. return [
  11. {
  12. component: 'VbenInput',
  13. componentProps: {
  14. placeholder: $t('authentication.usernameTip'),
  15. },
  16. fieldName: 'username',
  17. label: $t('authentication.username'),
  18. rules: z.string().min(1, { message: $t('authentication.usernameTip') }),
  19. },
  20. {
  21. component: 'VbenInputPassword',
  22. componentProps: {
  23. passwordStrength: true,
  24. placeholder: $t('authentication.password'),
  25. },
  26. fieldName: 'password',
  27. label: $t('authentication.password'),
  28. renderComponentContent() {
  29. return {
  30. strengthText: () => $t('authentication.passwordStrength'),
  31. };
  32. },
  33. rules: z.string().min(1, { message: $t('authentication.passwordTip') }),
  34. },
  35. {
  36. component: 'VbenInputPassword',
  37. componentProps: {
  38. placeholder: $t('authentication.confirmPassword'),
  39. },
  40. dependencies: {
  41. rules(values) {
  42. const { password } = values;
  43. return z
  44. .string({ required_error: $t('authentication.passwordTip') })
  45. .min(1, { message: $t('authentication.passwordTip') })
  46. .refine((value) => value === password, {
  47. message: $t('authentication.confirmPasswordTip'),
  48. });
  49. },
  50. triggerFields: ['password'],
  51. },
  52. fieldName: 'confirmPassword',
  53. label: $t('authentication.confirmPassword'),
  54. },
  55. {
  56. component: 'VbenCheckbox',
  57. fieldName: 'agreePolicy',
  58. renderComponentContent: () => ({
  59. default: () =>
  60. h('span', [
  61. $t('authentication.agree'),
  62. h(
  63. 'a',
  64. {
  65. class: 'vben-link ml-1 ',
  66. href: '',
  67. },
  68. `${$t('authentication.privacyPolicy')} & ${$t('authentication.terms')}`,
  69. ),
  70. ]),
  71. }),
  72. rules: z.boolean().refine((value) => !!value, {
  73. message: $t('authentication.agreeTip'),
  74. }),
  75. },
  76. ];
  77. });
  78. function handleSubmit(value: Recordable<any>) {
  79. // eslint-disable-next-line no-console
  80. console.log('register submit:', value);
  81. }
  82. </script>
  83. <template>
  84. <AuthenticationRegister
  85. :form-schema="formSchema"
  86. :loading="loading"
  87. @submit="handleSubmit"
  88. />
  89. </template>