RegisterForm.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <script setup lang="ts">
  2. import { Form } from '@/components/Form'
  3. import { computed, reactive, ref, unref } from 'vue'
  4. import { useI18n } from '@/hooks/web/useI18n'
  5. import { useForm } from '@/hooks/web/useForm'
  6. import { ElInput, FormRules } from 'element-plus'
  7. import { useValidator } from '@/hooks/web/useValidator'
  8. import { useLoginState, LoginStateEnum } from './useLogin'
  9. import LoginFormTitle from './LoginFormTitle.vue'
  10. const { register, elFormRef } = useForm()
  11. const { handleBackLogin, getLoginState } = useLoginState()
  12. const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER)
  13. const { t } = useI18n()
  14. const { required } = useValidator()
  15. const schema = reactive<FormSchema[]>([
  16. {
  17. field: 'title',
  18. colProps: {
  19. span: 24
  20. }
  21. },
  22. {
  23. field: 'username',
  24. label: t('login.username'),
  25. value: '',
  26. component: 'Input',
  27. colProps: {
  28. span: 24
  29. },
  30. componentProps: {
  31. placeholder: t('login.usernamePlaceholder')
  32. }
  33. },
  34. {
  35. field: 'password',
  36. label: t('login.password'),
  37. value: '',
  38. component: 'InputPassword',
  39. colProps: {
  40. span: 24
  41. },
  42. componentProps: {
  43. style: {
  44. width: '100%'
  45. },
  46. strength: true,
  47. placeholder: t('login.passwordPlaceholder')
  48. }
  49. },
  50. {
  51. field: 'check_password',
  52. label: t('login.checkPassword'),
  53. value: '',
  54. component: 'InputPassword',
  55. colProps: {
  56. span: 24
  57. },
  58. componentProps: {
  59. style: {
  60. width: '100%'
  61. },
  62. strength: true,
  63. placeholder: t('login.passwordPlaceholder')
  64. }
  65. },
  66. {
  67. field: 'code',
  68. label: t('login.code'),
  69. colProps: {
  70. span: 24
  71. }
  72. },
  73. {
  74. field: 'register',
  75. colProps: {
  76. span: 24
  77. }
  78. }
  79. ])
  80. const rules: FormRules = {
  81. username: [required()],
  82. password: [required()],
  83. check_password: [required()],
  84. code: [required()]
  85. }
  86. const loading = ref(false)
  87. const loginRegister = async () => {
  88. const formRef = unref(elFormRef)
  89. formRef?.validate(async (valid) => {
  90. if (valid) {
  91. try {
  92. loading.value = true
  93. } finally {
  94. loading.value = false
  95. }
  96. }
  97. })
  98. }
  99. </script>
  100. <template>
  101. <Form
  102. :schema="schema"
  103. :rules="rules"
  104. label-position="top"
  105. hide-required-asterisk
  106. size="large"
  107. v-show="getShow"
  108. class="dark:(border-1 border-[var(--el-border-color)] border-solid)"
  109. @register="register"
  110. >
  111. <template #title>
  112. <LoginFormTitle style="width: 100%" />
  113. </template>
  114. <template #code="form">
  115. <div class="w-[100%] flex">
  116. <el-input v-model="form['code']" :placeholder="t('login.codePlaceholder')" />
  117. </div>
  118. </template>
  119. <template #register>
  120. <div class="w-[100%]">
  121. <el-button type="primary" class="w-[100%]" :loading="loading" @click="loginRegister">
  122. {{ t('login.register') }}
  123. </el-button>
  124. </div>
  125. <div class="w-[100%] mt-15px">
  126. <el-button class="w-[100%]" @click="handleBackLogin">
  127. {{ t('login.hasUser') }}
  128. </el-button>
  129. </div>
  130. </template>
  131. </Form>
  132. </template>