Commit 9c43d9fa780d773d334169d44bed72c465acd2b1

Authored by xingyu
1 parent 6eddbffd

feat: add register

yudao-ui-admin-vue3/src/locales/en.ts
... ... @@ -108,7 +108,10 @@ export default {
108 108 login: 'Sign in',
109 109 relogin: 'Sign in again',
110 110 otherLogin: 'Sign in with',
  111 + register: 'Register',
  112 + checkPassword: 'Confirm password',
111 113 remember: 'Remember me',
  114 + hasUser: 'Existing account? Go to login',
112 115 forgetPassword: 'Forget password?',
113 116 tenantNamePlaceholder: 'Please Enter Tenant Name',
114 117 usernamePlaceholder: 'Please Enter Username',
... ...
yudao-ui-admin-vue3/src/locales/zh-CN.ts
... ... @@ -108,7 +108,10 @@ export default {
108 108 login: '登录',
109 109 relogin: '重新登录',
110 110 otherLogin: '其他登录方式',
  111 + register: '注册',
  112 + checkPassword: '确认密码',
111 113 remember: '记住我',
  114 + hasUser: '已有账号?去登录',
112 115 forgetPassword: '忘记密码?',
113 116 tenantNamePlaceholder: '请输入租户名称',
114 117 usernamePlaceholder: '请输入用户名',
... ...
yudao-ui-admin-vue3/src/views/Login/Login.vue
1 1 <script setup lang="ts">
2   -import { LoginForm } from './components'
3   -import { MobileForm } from './components'
  2 +import { LoginForm, MobileForm, RegisterForm } from './components'
4 3 import { ThemeSwitch } from '@/components/ThemeSwitch'
5 4 import { LocaleDropdown } from '@/components/LocaleDropdown'
6 5 import { useI18n } from '@/hooks/web/useI18n'
... ... @@ -8,13 +7,13 @@ import { underlineToHump } from &#39;@/utils&#39;
8 7 import { useAppStore } from '@/store/modules/app'
9 8 import { useDesign } from '@/hooks/web/useDesign'
10 9  
  10 +const { t } = useI18n()
  11 +
11 12 const { getPrefixCls } = useDesign()
12 13  
13 14 const prefixCls = getPrefixCls('login')
14 15  
15 16 const appStore = useAppStore()
16   -
17   -const { t } = useI18n()
18 17 </script>
19 18  
20 19 <template>
... ... @@ -67,6 +66,8 @@ const { t } = useI18n()
67 66 <LoginForm class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white)" />
68 67 <!-- 手机登录 -->
69 68 <MobileForm class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white)" />
  69 + <!-- 注册 -->
  70 + <RegisterForm class="p-20px h-auto m-auto <xl:(rounded-3xl light:bg-white)" />
70 71 </div>
71 72 </Transition>
72 73 </div>
... ...
yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue
... ... @@ -131,7 +131,6 @@ const getRoutes = async () =&gt; {
131 131 permissionStore.setIsAddRouters(true)
132 132 push({ path: redirect.value || permissionStore.addRouters[0].path })
133 133 }
134   -
135 134 watch(
136 135 () => currentRoute.value,
137 136 (route: RouteLocationNormalizedLoaded) => {
... ... @@ -233,24 +232,26 @@ onMounted(async () =&gt; {
233 232 </el-col>
234 233 <el-col :span="24" style="padding-left: 10px; padding-right: 10px">
235 234 <el-form-item>
236   - <el-button :loading="loginLoading" type="primary" class="w-[100%]" @click="handleLogin">{{
237   - t('login.login')
238   - }}</el-button>
  235 + <el-button :loading="loginLoading" type="primary" class="w-[100%]" @click="handleLogin">
  236 + {{ t('login.login') }}
  237 + </el-button>
239 238 </el-form-item>
240 239 </el-col>
241 240 <el-col :span="24" style="padding-left: 10px; padding-right: 10px">
242 241 <el-form-item>
243 242 <el-row justify="space-between" style="width: 100%" :gutter="5">
244 243 <el-col :span="8">
245   - <el-button class="w-[100%]" @click="setLoginState(LoginStateEnum.MOBILE)">{{
246   - t('login.btnMobile')
247   - }}</el-button>
  244 + <el-button class="w-[100%]" @click="setLoginState(LoginStateEnum.MOBILE)">
  245 + {{ t('login.btnMobile') }}
  246 + </el-button>
248 247 </el-col>
249 248 <el-col :span="8">
250 249 <el-button class="w-[100%]">{{ t('login.btnQRCode') }}</el-button>
251 250 </el-col>
252 251 <el-col :span="8">
253   - <el-button class="w-[100%]">{{ t('login.btnRegister') }}</el-button>
  252 + <el-button class="w-[100%]" @click="setLoginState(LoginStateEnum.REGISTER)">
  253 + {{ t('login.btnRegister') }}
  254 + </el-button>
254 255 </el-col>
255 256 </el-row>
256 257 </el-form-item>
... ... @@ -290,6 +291,11 @@ onMounted(async () =&gt; {
290 291 </el-form>
291 292 </template>
292 293 <style lang="less" scoped>
  294 +:deep(.anticon) {
  295 + &:hover {
  296 + color: var(--el-color-primary) !important;
  297 + }
  298 +}
293 299 .login-code {
294 300 width: 100%;
295 301 height: 38px;
... ...
yudao-ui-admin-vue3/src/views/Login/components/RegisterForm.vue 0 → 100644
  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 +
  11 +const { register, elFormRef } = useForm()
  12 +const { handleBackLogin, getLoginState } = useLoginState()
  13 +const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER)
  14 +const { t } = useI18n()
  15 +
  16 +const { required } = useValidator()
  17 +
  18 +const schema = reactive<FormSchema[]>([
  19 + {
  20 + field: 'title',
  21 + colProps: {
  22 + span: 24
  23 + }
  24 + },
  25 + {
  26 + field: 'username',
  27 + label: t('login.username'),
  28 + value: '',
  29 + component: 'Input',
  30 + colProps: {
  31 + span: 24
  32 + },
  33 + componentProps: {
  34 + placeholder: t('login.usernamePlaceholder')
  35 + }
  36 + },
  37 + {
  38 + field: 'password',
  39 + label: t('login.password'),
  40 + value: '',
  41 + component: 'InputPassword',
  42 + colProps: {
  43 + span: 24
  44 + },
  45 + componentProps: {
  46 + style: {
  47 + width: '100%'
  48 + },
  49 + strength: true,
  50 + placeholder: t('login.passwordPlaceholder')
  51 + }
  52 + },
  53 + {
  54 + field: 'check_password',
  55 + label: t('login.checkPassword'),
  56 + value: '',
  57 + component: 'InputPassword',
  58 + colProps: {
  59 + span: 24
  60 + },
  61 + componentProps: {
  62 + style: {
  63 + width: '100%'
  64 + },
  65 + strength: true,
  66 + placeholder: t('login.passwordPlaceholder')
  67 + }
  68 + },
  69 + {
  70 + field: 'code',
  71 + label: t('login.code'),
  72 + colProps: {
  73 + span: 24
  74 + }
  75 + },
  76 + {
  77 + field: 'register',
  78 + colProps: {
  79 + span: 24
  80 + }
  81 + }
  82 +])
  83 +
  84 +const rules: FormRules = {
  85 + username: [required()],
  86 + password: [required()],
  87 + check_password: [required()],
  88 + code: [required()]
  89 +}
  90 +
  91 +const loading = ref(false)
  92 +
  93 +const loginRegister = async () => {
  94 + const formRef = unref(elFormRef)
  95 + formRef?.validate(async (valid) => {
  96 + if (valid) {
  97 + try {
  98 + loading.value = true
  99 + } finally {
  100 + loading.value = false
  101 + }
  102 + }
  103 + })
  104 +}
  105 +</script>
  106 +
  107 +<template>
  108 + <Form
  109 + :schema="schema"
  110 + :rules="rules"
  111 + label-position="top"
  112 + hide-required-asterisk
  113 + size="large"
  114 + v-show="getShow"
  115 + class="dark:(border-1 border-[var(--el-border-color)] border-solid)"
  116 + @register="register"
  117 + >
  118 + <template #title>
  119 + <LoginFormTitle style="width: 100%" />
  120 + </template>
  121 +
  122 + <template #code="form">
  123 + <div class="w-[100%] flex">
  124 + <ElInput v-model="form['code']" :placeholder="t('login.codePlaceholder')" />
  125 + </div>
  126 + </template>
  127 +
  128 + <template #register>
  129 + <div class="w-[100%]">
  130 + <ElButton type="primary" class="w-[100%]" :loading="loading" @click="loginRegister">
  131 + {{ t('login.register') }}
  132 + </ElButton>
  133 + </div>
  134 + <div class="w-[100%] mt-15px">
  135 + <ElButton class="w-[100%]" @click="handleBackLogin">
  136 + {{ t('login.hasUser') }}
  137 + </ElButton>
  138 + </div>
  139 + </template>
  140 + </Form>
  141 +</template>
... ...
yudao-ui-admin-vue3/src/views/Login/components/index.ts
1 1 import LoginForm from './LoginForm.vue'
2 2 import MobileForm from './MobileForm.vue'
3 3 import LoginFormTitle from './LoginFormTitle.vue'
  4 +import RegisterForm from './RegisterForm.vue'
4 5  
5   -export { LoginForm, MobileForm, LoginFormTitle }
  6 +export { LoginForm, MobileForm, LoginFormTitle, RegisterForm }
... ...