From b7465498dc381e243c9ba831fe069053d8f374d0 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 26 Nov 2024 12:01:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AD=97=E5=85=B8=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=94=BE=E5=85=A5auth=20store=20=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/store/auth.ts | 17 ++++++++++++++++- .../src/views/_core/authentication/login.vue | 18 +++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/apps/web-antd/src/store/auth.ts b/apps/web-antd/src/store/auth.ts index 22f75e22..c85f2404 100644 --- a/apps/web-antd/src/store/auth.ts +++ b/apps/web-antd/src/store/auth.ts @@ -4,17 +4,24 @@ import { ref } from 'vue'; import { useRouter } from 'vue-router'; import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants'; -import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores'; +import { + resetAllStores, + useAccessStore, + useDictStore, + useUserStore, +} from '@vben/stores'; import { notification } from 'ant-design-vue'; import { defineStore } from 'pinia'; import { getAuthPermissionInfoApi, loginApi, logoutApi } from '#/api'; +import { getSimpleDictDataList } from '#/api/system/dict-data'; import { $t } from '#/locales'; export const useAuthStore = defineStore('auth', () => { const accessStore = useAccessStore(); const userStore = useUserStore(); + const dictStore = useDictStore(); const router = useRouter(); const loginLoading = ref(false); @@ -51,6 +58,14 @@ export const useAuthStore = defineStore('auth', () => { await router.push(authPermissionInfo.homePath || DEFAULT_HOME_PATH); } + // 设置字典数据 + dictStore.setDictCacheByApi( + getSimpleDictDataList, + {}, + 'label', + 'value', + ); + if ( authPermissionInfo?.user.realName || authPermissionInfo.user.nickname diff --git a/apps/web-antd/src/views/_core/authentication/login.vue b/apps/web-antd/src/views/_core/authentication/login.vue index 4138dd55..9505e923 100644 --- a/apps/web-antd/src/views/_core/authentication/login.vue +++ b/apps/web-antd/src/views/_core/authentication/login.vue @@ -7,7 +7,7 @@ import { computed, ref, watchEffect } from 'vue'; import { AuthenticationLogin, Verification, z } from '@vben/common-ui'; import { useAppConfig } from '@vben/hooks'; import { $t } from '@vben/locales'; -import { useDictStore, useTenantStore } from '@vben/stores'; +import { useTenantStore } from '@vben/stores'; import { checkCaptcha, @@ -15,7 +15,6 @@ import { getTenantByWebsite, getTenantIdByName, } from '#/api'; -import { getSimpleDictDataList } from '#/api/system/dict-data'; import { useAuthStore } from '#/store'; defineOptions({ name: 'Login' }); @@ -27,7 +26,6 @@ const { tenantEnable, captchaEnable } = useAppConfig( const authStore = useAuthStore(); const tenantStore = useTenantStore(); -const dictStore = useDictStore(); const captchaType = 'blockPuzzle'; const loginData = ref>({}); @@ -103,16 +101,14 @@ const handleLogin = async (values: any) => { }; const handleVerifySuccess = async ({ captchaVerification }: any) => { - await authStore.authLogin( - { + try { + await authStore.authLogin({ ...loginData.value, captchaVerification, - }, - () => { - // 设置字典数据 - dictStore.setDictCacheByApi(getSimpleDictDataList, 'label', 'value'); - }, - ); + }); + } catch (error) { + console.error('Error in handleLogin:', error); + } }; watchEffect(async () => {