RegisterForm.vue 3.0 KB

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