From bf12cb89df2ffe4ec2d9c4c9e81df1de0d7e5e85 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Wed, 23 Nov 2022 11:45:57 +0800 Subject: [PATCH] perf: login --- .../src/views/Login/components/LoginForm.vue | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue b/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue index 3b63d175b..b47918807 100644 --- a/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue +++ b/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue @@ -104,29 +104,29 @@
@@ -165,19 +165,21 @@ import * as LoginApi from '@/api/login' import { LoginStateEnum, useLoginState, useFormValid } from './useLogin' const { t } = useI18n() -const iconHouse = useIcon({ icon: 'ep:house' }) -const iconAvatar = useIcon({ icon: 'ep:avatar' }) -const iconLock = useIcon({ icon: 'ep:lock' }) -const { currentRoute, push } = useRouter() -const permissionStore = usePermissionStore() const formLogin = ref() const { validForm } = useFormValid(formLogin) const { setLoginState, getLoginState } = useLoginState() -const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN) -const iconSize = 30 -const iconColor = '#999' +const { currentRoute, push } = useRouter() +const permissionStore = usePermissionStore() const redirect = ref('') const loginLoading = ref(false) +const iconHouse = useIcon({ icon: 'ep:house' }) +const iconAvatar = useIcon({ icon: 'ep:avatar' }) +const iconLock = useIcon({ icon: 'ep:lock' }) +const verify = ref() +const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字 + +const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN) + const LoginRules = { tenantName: [required], username: [required], @@ -192,26 +194,26 @@ const loginData = reactive({ signIn: false }, loginForm: { - tenantName: '芋道源码', - username: 'admin', - password: 'admin123', + tenantName: Cookies.get('tenantName') ? Cookies.get('tenantName') : '芋道源码', + username: Cookies.get('username') ? Cookies.get('username') : 'admin', + password: Cookies.get('password') + ? (decrypt(Cookies.get('password')) as unknown as string) + : 'admin123', captchaVerification: '', rememberMe: false } }) -// blockPuzzle 滑块 clickWord 点击文字 -const verify = ref() -const captchaType = ref('blockPuzzle') + // 获取验证码 const getCode = async () => { // 情况一,未开启:则直接登录 if (loginData.captchaEnable === 'false') { await handleLogin({}) - return + } else { + // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录 + // 弹出验证码 + verify.value.show() } - // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录 - // 弹出验证码 - verify.value.show() } //获取租户ID const getTenantId = async () => { @@ -221,7 +223,9 @@ const getTenantId = async () => { // 记住我 const getCookie = () => { const username = Cookies.get('username') - const password = Cookies.get('password') ? decrypt(Cookies.get('password')) : undefined + const password = Cookies.get('password') + ? (decrypt(Cookies.get('password')) as unknown as string) + : undefined const rememberMe = Cookies.get('rememberMe') const tenantName = Cookies.get('tenantName') loginData.loginForm = { @@ -253,7 +257,9 @@ const handleLogin = async (params) => { }) if (loginData.loginForm.rememberMe) { Cookies.set('username', loginData.loginForm.username, { expires: 30 }) - Cookies.set('password', encrypt(loginData.loginForm.password), { expires: 30 }) + Cookies.set('password', encrypt(loginData.loginForm.password as unknown as string), { + expires: 30 + }) Cookies.set('rememberMe', loginData.loginForm.rememberMe, { expires: 30 }) Cookies.set('tenantName', loginData.loginForm.tenantName, { expires: 30 }) } else {