From 2dd1e01183c6e2c356c8e253683f88579e2d4417 Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 5 Jan 2023 14:21:07 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=AE=80=E5=8C=96login=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/hooks/web/useVxeCrudSchemas.ts | 2 +- yudao-ui-admin-vue3/src/utils/auth.ts | 47 ++++++------------- .../src/views/Login/components/LoginForm.vue | 42 +++-------------- 3 files changed, 23 insertions(+), 68 deletions(-) diff --git a/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts b/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts index c799aae71..951ddd9c9 100644 --- a/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts +++ b/yudao-ui-admin-vue3/src/hooks/web/useVxeCrudSchemas.ts @@ -165,7 +165,7 @@ const filterSearchSchema = (crudSchema: VxeCrudSchema): VxeFormItemProps[] => { // 添加搜索按钮 const buttons: VxeFormItemProps = { span: 24, - align: 'center', + align: 'right', collapseNode: searchSchema.length > spanLength, itemRender: { name: '$buttons', diff --git a/yudao-ui-admin-vue3/src/utils/auth.ts b/yudao-ui-admin-vue3/src/utils/auth.ts index be7ba91f4..de720346b 100644 --- a/yudao-ui-admin-vue3/src/utils/auth.ts +++ b/yudao-ui-admin-vue3/src/utils/auth.ts @@ -36,45 +36,28 @@ export const formatToken = (token: string): string => { } // ========== 账号相关 ========== -const UsernameKey = 'USERNAME' -const PasswordKey = 'PASSWORD' -const RememberMeKey = 'REMEMBER_ME' +const LoginFormKey = 'LOGINFORM' -export const getUsername = () => { - return wsCache.get(UsernameKey) +export type LoginFormType = { + tenantName: string + username: string + password: string + rememberMe: boolean } -export const setUsername = (username: string) => { - wsCache.set(UsernameKey, username, { exp: 30 * 24 * 60 * 60 }) +export const getLoginForm = () => { + const loginForm: LoginFormType = wsCache.get(LoginFormKey) + loginForm.password = decrypt(loginForm.password) as string + return loginForm } -export const removeUsername = () => { - wsCache.delete(UsernameKey) +export const setLoginForm = (loginForm: LoginFormType) => { + loginForm.password = encrypt(loginForm.password) as string + wsCache.set(LoginFormKey, loginForm, { exp: 30 * 24 * 60 * 60 }) } -export const getPassword = () => { - const password = wsCache.get(PasswordKey) - return password ? decrypt(password) : undefined -} - -export const setPassword = (password: string) => { - wsCache.set(PasswordKey, encrypt(password), { exp: 30 * 24 * 60 * 60 }) -} - -export const removePassword = () => { - wsCache.delete(PasswordKey) -} - -export const getRememberMe = () => { - return wsCache.get(RememberMeKey) === true -} - -export const setRememberMe = (rememberMe: boolean) => { - wsCache.set(RememberMeKey, rememberMe, { exp: 30 * 24 * 60 * 60 }) -} - -export const removeRememberMe = () => { - wsCache.delete(RememberMeKey) +export const removeLoginForm = () => { + wsCache.delete(LoginFormKey) } // ========== 租户相关 ========== 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 aaac013bb..a2655f729 100644 --- a/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue +++ b/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue @@ -148,7 +148,6 @@ import { useIcon } from '@/hooks/web/useIcon' import { useMessage } from '@/hooks/web/useMessage' import { required } from '@/utils/formRules' import * as authUtil from '@/utils/auth' -import { decrypt } from '@/utils/jsencrypt' import { Verify } from '@/components/Verifition' import { usePermissionStore } from '@/store/modules/permission' import * as LoginApi from '@/api/login' @@ -180,10 +179,6 @@ const loginData = reactive({ isShowPassword: false, captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE, tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE, - token: '', - loading: { - signIn: false - }, loginForm: { tenantName: '芋道源码', username: 'admin', @@ -194,22 +189,10 @@ const loginData = reactive({ }) const socialList = [ - { - icon: 'ant-design:github-filled', - type: 0 - }, - { - icon: 'ant-design:wechat-filled', - type: 30 - }, - { - icon: 'ant-design:alipay-circle-filled', - type: 0 - }, - { - icon: 'ant-design:dingtalk-circle-filled', - type: 20 - } + { icon: 'ant-design:github-filled', type: 0 }, + { icon: 'ant-design:wechat-filled', type: 30 }, + { icon: 'ant-design:alipay-circle-filled', type: 0 }, + { icon: 'ant-design:dingtalk-circle-filled', type: 20 } ] // 获取验证码 @@ -232,12 +215,7 @@ const getTenantId = async () => { } // 记住我 const getCookie = () => { - const username = authUtil.getUsername() - const password = authUtil.getPassword() - ? decrypt(authUtil.getPassword() as unknown as string) - : undefined - const rememberMe = authUtil.getRememberMe() - const tenantName = authUtil.getTenantName() + const { username, password, rememberMe, tenantName } = authUtil.getLoginForm() loginData.loginForm = { ...loginData.loginForm, username: username ? username : loginData.loginForm.username, @@ -266,15 +244,9 @@ const handleLogin = async (params) => { background: 'rgba(0, 0, 0, 0.7)' }) if (loginData.loginForm.rememberMe) { - authUtil.setUsername(loginData.loginForm.username) - authUtil.setPassword(loginData.loginForm.password) - authUtil.setRememberMe(loginData.loginForm.rememberMe) - authUtil.setTenantName(loginData.loginForm.tenantName) + authUtil.setLoginForm(loginData.loginForm) } else { - authUtil.removeUsername() - authUtil.removePassword() - authUtil.removeRememberMe() - authUtil.removeTenantName() + authUtil.removeLoginForm() } authUtil.setToken(res) if (!redirect.value) {