From c8823752d003988c7a4910c0d29df7f12c128979 Mon Sep 17 00:00:00 2001 From: xingyu Date: Wed, 20 Jul 2022 00:07:16 +0800 Subject: [PATCH] perf: loginform code --- yudao-ui-admin-vue3/src/config/axios/index.ts | 10 ++++- .../src/views/Login/components/LoginForm.vue | 42 +++++++++++++++---- .../src/views/Login/components/MobileForm.vue | 35 +++++++--------- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/yudao-ui-admin-vue3/src/config/axios/index.ts b/yudao-ui-admin-vue3/src/config/axios/index.ts index 4230e4800..69ce0df80 100644 --- a/yudao-ui-admin-vue3/src/config/axios/index.ts +++ b/yudao-ui-admin-vue3/src/config/axios/index.ts @@ -124,7 +124,15 @@ service.interceptors.response.use( }, (error: AxiosError) => { console.log('err' + error) // for debug - ElMessage.error(error.message) + let { message } = error + if (message === 'Network Error') { + message = '后端接口连接异常' + } else if (message.includes('timeout')) { + message = '系统接口请求超时' + } else if (message.includes('Request failed with status code')) { + message = '系统接口' + message.substr(message.length - 3) + '异常' + } + ElMessage.error(message) return Promise.reject(error) } ) 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 a79ef4275..eb3db84d4 100644 --- a/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue +++ b/yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue @@ -13,7 +13,14 @@ import { } from 'element-plus' import { reactive, ref, unref, onMounted, computed, watch } from 'vue' import * as LoginApi from '@/api/login' -import { setToken, setTenantId } from '@/utils/auth' +import { + setToken, + setTenantId, + getUsername, + getRememberMe, + getPassword, + getTenantName +} from '@/utils/auth' import { useUserStoreWithOut } from '@/store/modules/user' import { useCache } from '@/hooks/web/useCache' import { usePermissionStore } from '@/store/modules/permission' @@ -40,7 +47,6 @@ const iconHouse = useIcon({ icon: 'ep:house' }) const iconAvatar = useIcon({ icon: 'ep:avatar' }) const iconLock = useIcon({ icon: 'ep:lock' }) const iconCircleCheck = useIcon({ icon: 'ep:circle-check' }) -const remember = ref(false) const LoginRules = { tenantName: [required], username: [required], @@ -61,6 +67,7 @@ const loginData = reactive({ tenantName: '芋道源码', username: 'admin', password: 'admin123', + rememberMe: false, code: '', uuid: '' } @@ -77,6 +84,20 @@ const getTenantId = async () => { const res = await LoginApi.getTenantIdByNameApi(loginData.loginForm.tenantName) setTenantId(res) } +// 记住我 +const getCookie = () => { + const username = getUsername() + const password = getPassword() + const rememberMe = getRememberMe() + const tenantName = getTenantName() + loginData.loginForm = { + ...loginData.loginForm, + username: username ? username : loginData.loginForm.username, + password: password ? password : loginData.loginForm.password, + rememberMe: rememberMe ? getRememberMe() : false, + tenantName: tenantName ? tenantName : loginData.loginForm.tenantName + } +} // 登录 const handleLogin = async () => { await getTenantId() @@ -103,7 +124,7 @@ const getRoutes = async () => { // 后端过滤菜单 const res = await LoginApi.getAsyncRoutesApi() wsCache.set('roleRouters', res) - await permissionStore.generateRoutes(res).catch(() => {}) + await permissionStore.generateRoutes(res) permissionStore.getAddRouters.forEach((route) => { addRoute(route as RouteRecordRaw) // 动态添加可访问路由表 }) @@ -120,8 +141,9 @@ watch( immediate: true } ) -onMounted(() => { - getCode() +onMounted(async () => { + await getCode() + getCookie() })