RegisterForm.vue 3.1 KB

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