Commit d604c6c5fbad1668a408edcc95c9c19c317ea4d3
1 parent
95325704
refactor: login
Showing
4 changed files
with
44 additions
and
51 deletions
yudao-ui-admin-vue3/src/views/Login/Login.vue
| @@ -59,21 +59,18 @@ | @@ -59,21 +59,18 @@ | ||
| 59 | </div> | 59 | </div> |
| 60 | </template> | 60 | </template> |
| 61 | <script setup lang="ts"> | 61 | <script setup lang="ts"> |
| 62 | -import { LoginForm, MobileForm, RegisterForm, QrCodeForm } from './components' | ||
| 63 | -import { ThemeSwitch } from '@/components/ThemeSwitch' | ||
| 64 | -import { LocaleDropdown } from '@/components/LocaleDropdown' | ||
| 65 | -import { useI18n } from '@/hooks/web/useI18n' | ||
| 66 | import { underlineToHump } from '@/utils' | 62 | import { underlineToHump } from '@/utils' |
| 67 | -import { useAppStore } from '@/store/modules/app' | 63 | +import { useI18n } from '@/hooks/web/useI18n' |
| 68 | import { useDesign } from '@/hooks/web/useDesign' | 64 | import { useDesign } from '@/hooks/web/useDesign' |
| 65 | +import { useAppStore } from '@/store/modules/app' | ||
| 66 | +import { ThemeSwitch } from '@/components/ThemeSwitch' | ||
| 67 | +import { LocaleDropdown } from '@/components/LocaleDropdown' | ||
| 68 | +import { LoginForm, MobileForm, RegisterForm, QrCodeForm } from './components' | ||
| 69 | 69 | ||
| 70 | const { t } = useI18n() | 70 | const { t } = useI18n() |
| 71 | - | 71 | +const appStore = useAppStore() |
| 72 | const { getPrefixCls } = useDesign() | 72 | const { getPrefixCls } = useDesign() |
| 73 | - | ||
| 74 | const prefixCls = getPrefixCls('login') | 73 | const prefixCls = getPrefixCls('login') |
| 75 | - | ||
| 76 | -const appStore = useAppStore() | ||
| 77 | </script> | 74 | </script> |
| 78 | 75 | ||
| 79 | <style lang="less" scoped> | 76 | <style lang="less" scoped> |
yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue
| @@ -137,7 +137,7 @@ | @@ -137,7 +137,7 @@ | ||
| 137 | </el-form> | 137 | </el-form> |
| 138 | </template> | 138 | </template> |
| 139 | <script setup lang="ts"> | 139 | <script setup lang="ts"> |
| 140 | -import { useIcon } from '@/hooks/web/useIcon' | 140 | +import { reactive, ref, unref, onMounted, computed, watch } from 'vue' |
| 141 | import LoginFormTitle from './LoginFormTitle.vue' | 141 | import LoginFormTitle from './LoginFormTitle.vue' |
| 142 | import { | 142 | import { |
| 143 | ElForm, | 143 | ElForm, |
| @@ -150,20 +150,24 @@ import { | @@ -150,20 +150,24 @@ import { | ||
| 150 | ElDivider, | 150 | ElDivider, |
| 151 | ElLoading | 151 | ElLoading |
| 152 | } from 'element-plus' | 152 | } from 'element-plus' |
| 153 | -import { reactive, ref, unref, onMounted, computed, watch } from 'vue' | ||
| 154 | -import * as LoginApi from '@/api/login' | ||
| 155 | -import { setToken, setTenantId } from '@/utils/auth' | ||
| 156 | -import { usePermissionStore } from '@/store/modules/permission' | 153 | +import Cookies from 'js-cookie' |
| 157 | import { useRouter } from 'vue-router' | 154 | import { useRouter } from 'vue-router' |
| 155 | +import type { RouteLocationNormalizedLoaded } from 'vue-router' | ||
| 158 | import { useI18n } from '@/hooks/web/useI18n' | 156 | import { useI18n } from '@/hooks/web/useI18n' |
| 157 | +import { useIcon } from '@/hooks/web/useIcon' | ||
| 159 | import { required } from '@/utils/formRules' | 158 | import { required } from '@/utils/formRules' |
| 159 | +import { setToken, setTenantId } from '@/utils/auth' | ||
| 160 | +import { decrypt, encrypt } from '@/utils/jsencrypt' | ||
| 160 | import { Icon } from '@/components/Icon' | 161 | import { Icon } from '@/components/Icon' |
| 161 | -import { LoginStateEnum, useLoginState, useFormValid } from './useLogin' | ||
| 162 | -import type { RouteLocationNormalizedLoaded } from 'vue-router' | ||
| 163 | import { Verify } from '@/components/Verifition' | 162 | import { Verify } from '@/components/Verifition' |
| 164 | -import Cookies from 'js-cookie' | ||
| 165 | -import { decrypt, encrypt } from '@/utils/jsencrypt' | 163 | +import { usePermissionStore } from '@/store/modules/permission' |
| 164 | +import * as LoginApi from '@/api/login' | ||
| 165 | +import { LoginStateEnum, useLoginState, useFormValid } from './useLogin' | ||
| 166 | 166 | ||
| 167 | +const { t } = useI18n() | ||
| 168 | +const iconHouse = useIcon({ icon: 'ep:house' }) | ||
| 169 | +const iconAvatar = useIcon({ icon: 'ep:avatar' }) | ||
| 170 | +const iconLock = useIcon({ icon: 'ep:lock' }) | ||
| 167 | const { currentRoute, push } = useRouter() | 171 | const { currentRoute, push } = useRouter() |
| 168 | const permissionStore = usePermissionStore() | 172 | const permissionStore = usePermissionStore() |
| 169 | const formLogin = ref() | 173 | const formLogin = ref() |
| @@ -173,16 +177,12 @@ const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN) | @@ -173,16 +177,12 @@ const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN) | ||
| 173 | const iconSize = 30 | 177 | const iconSize = 30 |
| 174 | const iconColor = '#999' | 178 | const iconColor = '#999' |
| 175 | const redirect = ref<string>('') | 179 | const redirect = ref<string>('') |
| 176 | -const { t } = useI18n() | ||
| 177 | -const iconHouse = useIcon({ icon: 'ep:house' }) | ||
| 178 | -const iconAvatar = useIcon({ icon: 'ep:avatar' }) | ||
| 179 | -const iconLock = useIcon({ icon: 'ep:lock' }) | 180 | +const loginLoading = ref(false) |
| 180 | const LoginRules = { | 181 | const LoginRules = { |
| 181 | tenantName: [required], | 182 | tenantName: [required], |
| 182 | username: [required], | 183 | username: [required], |
| 183 | password: [required] | 184 | password: [required] |
| 184 | } | 185 | } |
| 185 | -const loginLoading = ref(false) | ||
| 186 | const loginData = reactive({ | 186 | const loginData = reactive({ |
| 187 | isShowPassword: false, | 187 | isShowPassword: false, |
| 188 | captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE, | 188 | captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE, |
| @@ -202,7 +202,6 @@ const loginData = reactive({ | @@ -202,7 +202,6 @@ const loginData = reactive({ | ||
| 202 | // blockPuzzle 滑块 clickWord 点击文字 | 202 | // blockPuzzle 滑块 clickWord 点击文字 |
| 203 | const verify = ref() | 203 | const verify = ref() |
| 204 | const captchaType = ref('blockPuzzle') | 204 | const captchaType = ref('blockPuzzle') |
| 205 | - | ||
| 206 | // 获取验证码 | 205 | // 获取验证码 |
| 207 | const getCode = async () => { | 206 | const getCode = async () => { |
| 208 | // 情况一,未开启:则直接登录 | 207 | // 情况一,未开启:则直接登录 |
| @@ -210,7 +209,6 @@ const getCode = async () => { | @@ -210,7 +209,6 @@ const getCode = async () => { | ||
| 210 | await handleLogin({}) | 209 | await handleLogin({}) |
| 211 | return | 210 | return |
| 212 | } | 211 | } |
| 213 | - | ||
| 214 | // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录 | 212 | // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录 |
| 215 | // 弹出验证码 | 213 | // 弹出验证码 |
| 216 | verify.value.show() | 214 | verify.value.show() |
yudao-ui-admin-vue3/src/views/Login/components/MobileForm.vue
| @@ -85,31 +85,34 @@ | @@ -85,31 +85,34 @@ | ||
| 85 | </el-form> | 85 | </el-form> |
| 86 | </template> | 86 | </template> |
| 87 | <script setup lang="ts"> | 87 | <script setup lang="ts"> |
| 88 | -import { useIcon } from '@/hooks/web/useIcon' | ||
| 89 | import { reactive, ref, unref, watch, computed } from 'vue' | 88 | import { reactive, ref, unref, watch, computed } from 'vue' |
| 90 | -import LoginFormTitle from './LoginFormTitle.vue' | ||
| 91 | -import { ElForm, ElFormItem, ElInput, ElRow, ElCol, ElMessage } from 'element-plus' | 89 | +import { ElForm, ElFormItem, ElInput, ElRow, ElCol } from 'element-plus' |
| 90 | +import { useRouter } from 'vue-router' | ||
| 91 | +import type { RouteLocationNormalizedLoaded } from 'vue-router' | ||
| 92 | import { useI18n } from '@/hooks/web/useI18n' | 92 | import { useI18n } from '@/hooks/web/useI18n' |
| 93 | -import { required } from '@/utils/formRules' | ||
| 94 | -import { getTenantIdByNameApi, sendSmsCodeApi, smsLoginApi } from '@/api/login' | 93 | +import { useIcon } from '@/hooks/web/useIcon' |
| 95 | import { useCache } from '@/hooks/web/useCache' | 94 | import { useCache } from '@/hooks/web/useCache' |
| 96 | -import { usePermissionStore } from '@/store/modules/permission' | ||
| 97 | -import { useRouter } from 'vue-router' | 95 | +import { useMessage } from '@/hooks/web/useMessage' |
| 98 | import { setToken } from '@/utils/auth' | 96 | import { setToken } from '@/utils/auth' |
| 99 | -import type { RouteLocationNormalizedLoaded } from 'vue-router' | 97 | +import { required } from '@/utils/formRules' |
| 98 | +import { usePermissionStore } from '@/store/modules/permission' | ||
| 99 | +import { getTenantIdByNameApi, sendSmsCodeApi, smsLoginApi } from '@/api/login' | ||
| 100 | +import LoginFormTitle from './LoginFormTitle.vue' | ||
| 100 | import { useLoginState, LoginStateEnum, useFormValid } from './useLogin' | 101 | import { useLoginState, LoginStateEnum, useFormValid } from './useLogin' |
| 101 | -const formSmsLogin = ref() | ||
| 102 | -const { validForm } = useFormValid(formSmsLogin) | ||
| 103 | -const { handleBackLogin, getLoginState } = useLoginState() | ||
| 104 | -const getShow = computed(() => unref(getLoginState) === LoginStateEnum.MOBILE) | ||
| 105 | -const iconHouse = useIcon({ icon: 'ep:house' }) | ||
| 106 | -const iconCellphone = useIcon({ icon: 'ep:cellphone' }) | ||
| 107 | -const iconCircleCheck = useIcon({ icon: 'ep:circle-check' }) | 102 | + |
| 103 | +const { t } = useI18n() | ||
| 108 | const { wsCache } = useCache() | 104 | const { wsCache } = useCache() |
| 105 | +const message = useMessage() | ||
| 109 | const permissionStore = usePermissionStore() | 106 | const permissionStore = usePermissionStore() |
| 110 | const { currentRoute, push } = useRouter() | 107 | const { currentRoute, push } = useRouter() |
| 108 | +const formSmsLogin = ref() | ||
| 111 | const loginLoading = ref(false) | 109 | const loginLoading = ref(false) |
| 112 | -const { t } = useI18n() | 110 | +const iconHouse = useIcon({ icon: 'ep:house' }) |
| 111 | +const iconCellphone = useIcon({ icon: 'ep:cellphone' }) | ||
| 112 | +const iconCircleCheck = useIcon({ icon: 'ep:circle-check' }) | ||
| 113 | +const { validForm } = useFormValid(formSmsLogin) | ||
| 114 | +const { handleBackLogin, getLoginState } = useLoginState() | ||
| 115 | +const getShow = computed(() => unref(getLoginState) === LoginStateEnum.MOBILE) | ||
| 113 | 116 | ||
| 114 | const rules = { | 117 | const rules = { |
| 115 | tenantName: [required], | 118 | tenantName: [required], |
| @@ -146,11 +149,7 @@ const getSmsCode = async () => { | @@ -146,11 +149,7 @@ const getSmsCode = async () => { | ||
| 146 | await getTenantId() | 149 | await getTenantId() |
| 147 | smsVO.smsCode.mobile = loginData.loginForm.mobileNumber | 150 | smsVO.smsCode.mobile = loginData.loginForm.mobileNumber |
| 148 | await sendSmsCodeApi(smsVO.smsCode).then(async () => { | 151 | await sendSmsCodeApi(smsVO.smsCode).then(async () => { |
| 149 | - // 提示验证码发送成功 | ||
| 150 | - ElMessage({ | ||
| 151 | - type: 'success', | ||
| 152 | - message: t('login.SmsSendMsg') | ||
| 153 | - }) | 152 | + message.success(t('login.SmsSendMsg')) |
| 154 | // 设置倒计时 | 153 | // 设置倒计时 |
| 155 | mobileCodeTimer.value = 60 | 154 | mobileCodeTimer.value = 60 |
| 156 | let msgTimer = setInterval(() => { | 155 | let msgTimer = setInterval(() => { |
yudao-ui-admin-vue3/src/views/Login/components/RegisterForm.vue
| @@ -35,22 +35,21 @@ | @@ -35,22 +35,21 @@ | ||
| 35 | </template> | 35 | </template> |
| 36 | 36 | ||
| 37 | <script setup lang="ts"> | 37 | <script setup lang="ts"> |
| 38 | -import { Form } from '@/components/Form' | ||
| 39 | import { computed, reactive, ref, unref } from 'vue' | 38 | import { computed, reactive, ref, unref } from 'vue' |
| 39 | +import { ElInput, FormRules } from 'element-plus' | ||
| 40 | +import { Form } from '@/components/Form' | ||
| 40 | import { useI18n } from '@/hooks/web/useI18n' | 41 | import { useI18n } from '@/hooks/web/useI18n' |
| 41 | import { useForm } from '@/hooks/web/useForm' | 42 | import { useForm } from '@/hooks/web/useForm' |
| 42 | -import { ElInput, FormRules } from 'element-plus' | ||
| 43 | import { useValidator } from '@/hooks/web/useValidator' | 43 | import { useValidator } from '@/hooks/web/useValidator' |
| 44 | import { useLoginState, LoginStateEnum } from './useLogin' | 44 | import { useLoginState, LoginStateEnum } from './useLogin' |
| 45 | import LoginFormTitle from './LoginFormTitle.vue' | 45 | import LoginFormTitle from './LoginFormTitle.vue' |
| 46 | import { FormSchema } from '@/types/form' | 46 | import { FormSchema } from '@/types/form' |
| 47 | 47 | ||
| 48 | +const { t } = useI18n() | ||
| 49 | +const { required } = useValidator() | ||
| 48 | const { register, elFormRef } = useForm() | 50 | const { register, elFormRef } = useForm() |
| 49 | const { handleBackLogin, getLoginState } = useLoginState() | 51 | const { handleBackLogin, getLoginState } = useLoginState() |
| 50 | const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER) | 52 | const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER) |
| 51 | -const { t } = useI18n() | ||
| 52 | - | ||
| 53 | -const { required } = useValidator() | ||
| 54 | 53 | ||
| 55 | const schema = reactive<FormSchema[]>([ | 54 | const schema = reactive<FormSchema[]>([ |
| 56 | { | 55 | { |