Files
ipms-sjy/yudao-ui-admin-vue3/src/views/Login/components/RegisterForm.vue

141 lines
3.0 KiB
Vue
Raw Normal View History

2022-11-17 17:49:19 +08:00
<template>
<Form
:schema="schema"
:rules="rules"
label-position="top"
hide-required-asterisk
size="large"
v-show="getShow"
class="dark:(border-1 border-[var(--el-border-color)] border-solid)"
@register="register"
>
<template #title>
<LoginFormTitle style="width: 100%" />
</template>
<template #code="form">
<div class="w-[100%] flex">
<el-input v-model="form['code']" :placeholder="t('login.codePlaceholder')" />
</div>
</template>
<template #register>
<div class="w-[100%]">
2022-12-06 21:36:46 +08:00
<XButton
:loading="loading"
type="primary"
class="w-[100%]"
:title="t('login.register')"
@click="loginRegister()"
/>
2022-11-17 17:49:19 +08:00
</div>
<div class="w-[100%] mt-15px">
2022-12-06 21:36:46 +08:00
<XButton class="w-[100%]" :title="t('login.hasUser')" @click="handleBackLogin()" />
2022-11-17 17:49:19 +08:00
</div>
</template>
</Form>
</template>
2022-07-20 09:12:20 +08:00
<script setup lang="ts">
2023-01-18 12:14:58 +08:00
import type { FormRules } from 'element-plus'
2022-07-20 09:12:20 +08:00
import { useI18n } from '@/hooks/web/useI18n'
import { useForm } from '@/hooks/web/useForm'
import { useValidator } from '@/hooks/web/useValidator'
import LoginFormTitle from './LoginFormTitle.vue'
2022-12-06 21:36:46 +08:00
import { useLoginState, LoginStateEnum } from './useLogin'
2022-10-11 16:02:28 +08:00
import { FormSchema } from '@/types/form'
2022-07-20 09:12:20 +08:00
2022-11-22 21:41:59 +08:00
const { t } = useI18n()
const { required } = useValidator()
2022-07-20 09:12:20 +08:00
const { register, elFormRef } = useForm()
const { handleBackLogin, getLoginState } = useLoginState()
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER)
const schema = reactive<FormSchema[]>([
{
field: 'title',
colProps: {
span: 24
}
},
{
field: 'username',
label: t('login.username'),
value: '',
component: 'Input',
colProps: {
span: 24
},
componentProps: {
placeholder: t('login.usernamePlaceholder')
}
},
{
field: 'password',
label: t('login.password'),
value: '',
component: 'InputPassword',
colProps: {
span: 24
},
componentProps: {
style: {
width: '100%'
},
strength: true,
placeholder: t('login.passwordPlaceholder')
}
},
{
field: 'check_password',
label: t('login.checkPassword'),
value: '',
component: 'InputPassword',
colProps: {
span: 24
},
componentProps: {
style: {
width: '100%'
},
strength: true,
placeholder: t('login.passwordPlaceholder')
}
},
{
field: 'code',
label: t('login.code'),
colProps: {
span: 24
}
},
{
field: 'register',
colProps: {
span: 24
}
}
])
const rules: FormRules = {
username: [required()],
password: [required()],
check_password: [required()],
code: [required()]
}
const loading = ref(false)
const loginRegister = async () => {
const formRef = unref(elFormRef)
formRef?.validate(async (valid) => {
if (valid) {
try {
loading.value = true
} finally {
loading.value = false
}
}
})
}
</script>