wip: coding

This commit is contained in:
kailong321200875 2022-06-22 23:03:21 +08:00
parent 17fdd87d8d
commit cf738b8701
6 changed files with 160 additions and 10 deletions

View File

@ -86,12 +86,15 @@ export default {
message: 'Backstage management system', message: 'Backstage management system',
username: 'Username', username: 'Username',
password: 'Password', password: 'Password',
register: 'Register',
checkPassword: 'Confirm password',
login: 'Sign in', login: 'Sign in',
otherLogin: 'Sign in with', otherLogin: 'Sign in with',
remember: 'Remember me', remember: 'Remember me',
hasUser: 'Existing account? Go to login',
forgetPassword: 'Forget password', forgetPassword: 'Forget password',
usernamePlaceholder: 'username is admin or test', usernamePlaceholder: 'Please input username',
passwordPlaceholder: 'password is admin or test' passwordPlaceholder: 'Please input password'
}, },
router: { router: {
login: 'Login', login: 'Login',

View File

@ -86,12 +86,15 @@ export default {
message: '开箱即用的中后台管理系统', message: '开箱即用的中后台管理系统',
username: '用户名', username: '用户名',
password: '密码', password: '密码',
register: '注册',
checkPassword: '确认密码',
login: '登录', login: '登录',
otherLogin: '其他登录方式', otherLogin: '其他登录方式',
remember: '记住我', remember: '记住我',
hasUser: '已有账号?去登录',
forgetPassword: '忘记密码', forgetPassword: '忘记密码',
usernamePlaceholder: '用户名为 admin 或者 test ', usernamePlaceholder: '请输入用户名',
passwordPlaceholder: '密码为 admin 或者 test ' passwordPlaceholder: '请输入密码'
}, },
router: { router: {
login: '登录', login: '登录',

View File

@ -1,11 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { LoginForm } from './components' import { LoginForm, RegisterForm } from './components'
import { ThemeSwitch } from '@/components/ThemeSwitch' import { ThemeSwitch } from '@/components/ThemeSwitch'
import { LocaleDropdown } from '@/components/LocaleDropdown' import { LocaleDropdown } from '@/components/LocaleDropdown'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { underlineToHump } from '@/utils' import { underlineToHump } from '@/utils'
import { useAppStore } from '@/store/modules/app' import { useAppStore } from '@/store/modules/app'
import { useDesign } from '@/hooks/web/useDesign' import { useDesign } from '@/hooks/web/useDesign'
import { ref } from 'vue'
const { getPrefixCls } = useDesign() const { getPrefixCls } = useDesign()
@ -14,6 +15,16 @@ const prefixCls = getPrefixCls('login')
const appStore = useAppStore() const appStore = useAppStore()
const { t } = useI18n() const { t } = useI18n()
const isLogin = ref(true)
const toRegister = () => {
isLogin.value = false
}
const toLogin = () => {
isLogin.value = true
}
</script> </script>
<template> <template>
@ -59,7 +70,16 @@ const { t } = useI18n()
<div <div
class="h-full flex items-center m-auto w-[100%] @2xl:max-w-500px @xl:max-w-500px @md:max-w-500px @lg:max-w-500px" class="h-full flex items-center m-auto w-[100%] @2xl:max-w-500px @xl:max-w-500px @md:max-w-500px @lg:max-w-500px"
> >
<LoginForm class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white)" /> <LoginForm
v-if="isLogin"
class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white)"
@to-register="toRegister"
/>
<RegisterForm
v-else
class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white)"
@to-login="toLogin"
/>
</div> </div>
</Transition> </Transition>
</div> </div>

View File

@ -13,6 +13,8 @@ import { usePermissionStore } from '@/store/modules/permission'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import type { RouteLocationNormalizedLoaded, RouteRecordRaw } from 'vue-router' import type { RouteLocationNormalizedLoaded, RouteRecordRaw } from 'vue-router'
const emit = defineEmits(['to-register'])
const appStore = useAppStore() const appStore = useAppStore()
const permissionStore = usePermissionStore() const permissionStore = usePermissionStore()
@ -162,6 +164,11 @@ const getRole = async () => {
push({ path: redirect.value || permissionStore.addRouters[0].path }) push({ path: redirect.value || permissionStore.addRouters[0].path })
} }
} }
//
const toRegister = () => {
emit('to-register')
}
</script> </script>
<template> <template>
@ -186,9 +193,16 @@ const getRole = async () => {
</template> </template>
<template #login> <template #login>
<div class="w-[100%]">
<ElButton :loading="loading" type="primary" class="w-[100%]" @click="signIn"> <ElButton :loading="loading" type="primary" class="w-[100%]" @click="signIn">
{{ t('login.login') }} {{ t('login.login') }}
</ElButton> </ElButton>
</div>
<div class="w-[100%] mt-15px">
<ElButton class="w-[100%]" @click="toRegister">
{{ t('login.register') }}
</ElButton>
</div>
</template> </template>
<template #otherIcon> <template #otherIcon>

View File

@ -0,0 +1,109 @@
<script setup lang="ts">
import { Form } from '@/components/Form'
import { reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules'
import { useForm } from '@/hooks/web/useForm'
import { ElButton } from 'element-plus'
const emit = defineEmits(['to-login'])
const { register } = useForm()
const { t } = useI18n()
const schema = reactive<FormSchema[]>([
{
field: 'title',
colProps: {
span: 24
}
},
{
field: 'user_name',
label: t('login.username'),
value: '',
component: 'Input',
colProps: {
span: 24
},
componentProps: {
placeholder: t('login.usernamePlaceholder')
}
},
{
field: 'password',
label: t('login.password'),
value: 'admin',
component: 'InputPassword',
colProps: {
span: 24
},
componentProps: {
style: {
width: '100%'
},
placeholder: t('login.passwordPlaceholder')
}
},
{
field: 'check_password',
label: t('login.checkPassword'),
value: 'admin',
component: 'InputPassword',
colProps: {
span: 24
},
componentProps: {
style: {
width: '100%'
},
placeholder: t('login.passwordPlaceholder')
}
},
{
field: 'register',
colProps: {
span: 24
}
}
])
const rules = {
username: [required],
password: [required]
}
const toLogin = () => {
emit('to-login')
}
</script>
<template>
<Form
:schema="schema"
:rules="rules"
label-position="top"
hide-required-asterisk
size="large"
class="dark:(border-1 border-[var(--el-border-color)] border-solid)"
@register="register"
>
<template #title>
<h2 class="text-2xl font-bold text-center w-[100%]">{{ t('login.register') }}</h2>
</template>
<template #register>
<div class="w-[100%]">
<ElButton type="primary" class="w-[100%]">
{{ t('login.register') }}
</ElButton>
</div>
<div class="w-[100%] mt-15px">
<ElButton class="w-[100%]" @click="toLogin">
{{ t('login.hasUser') }}
</ElButton>
</div>
</template>
</Form>
</template>

View File

@ -1,3 +1,4 @@
import LoginForm from './LoginForm.vue' import LoginForm from './LoginForm.vue'
import RegisterForm from './RegisterForm.vue'
export { LoginForm } export { LoginForm, RegisterForm }