feat: 字典相关放入auth store 中

pull/49/head
xingyu4j 2024-11-26 12:01:43 +08:00
parent 6cd86eb9c3
commit b7465498dc
2 changed files with 23 additions and 12 deletions

View File

@ -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

View File

@ -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<Recordable<any>>({});
@ -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 () => {