feat: 字典相关放入auth store 中
parent
6cd86eb9c3
commit
b7465498dc
|
|
@ -4,17 +4,24 @@ import { ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
|
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 { notification } from 'ant-design-vue';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
import { getAuthPermissionInfoApi, loginApi, logoutApi } from '#/api';
|
import { getAuthPermissionInfoApi, loginApi, logoutApi } from '#/api';
|
||||||
|
import { getSimpleDictDataList } from '#/api/system/dict-data';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
const dictStore = useDictStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const loginLoading = ref(false);
|
const loginLoading = ref(false);
|
||||||
|
|
@ -51,6 +58,14 @@ export const useAuthStore = defineStore('auth', () => {
|
||||||
await router.push(authPermissionInfo.homePath || DEFAULT_HOME_PATH);
|
await router.push(authPermissionInfo.homePath || DEFAULT_HOME_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置字典数据
|
||||||
|
dictStore.setDictCacheByApi(
|
||||||
|
getSimpleDictDataList,
|
||||||
|
{},
|
||||||
|
'label',
|
||||||
|
'value',
|
||||||
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
authPermissionInfo?.user.realName ||
|
authPermissionInfo?.user.realName ||
|
||||||
authPermissionInfo.user.nickname
|
authPermissionInfo.user.nickname
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { computed, ref, watchEffect } from 'vue';
|
||||||
import { AuthenticationLogin, Verification, z } from '@vben/common-ui';
|
import { AuthenticationLogin, Verification, z } from '@vben/common-ui';
|
||||||
import { useAppConfig } from '@vben/hooks';
|
import { useAppConfig } from '@vben/hooks';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { useDictStore, useTenantStore } from '@vben/stores';
|
import { useTenantStore } from '@vben/stores';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
checkCaptcha,
|
checkCaptcha,
|
||||||
|
|
@ -15,7 +15,6 @@ import {
|
||||||
getTenantByWebsite,
|
getTenantByWebsite,
|
||||||
getTenantIdByName,
|
getTenantIdByName,
|
||||||
} from '#/api';
|
} from '#/api';
|
||||||
import { getSimpleDictDataList } from '#/api/system/dict-data';
|
|
||||||
import { useAuthStore } from '#/store';
|
import { useAuthStore } from '#/store';
|
||||||
|
|
||||||
defineOptions({ name: 'Login' });
|
defineOptions({ name: 'Login' });
|
||||||
|
|
@ -27,7 +26,6 @@ const { tenantEnable, captchaEnable } = useAppConfig(
|
||||||
|
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const tenantStore = useTenantStore();
|
const tenantStore = useTenantStore();
|
||||||
const dictStore = useDictStore();
|
|
||||||
|
|
||||||
const captchaType = 'blockPuzzle';
|
const captchaType = 'blockPuzzle';
|
||||||
const loginData = ref<Recordable<any>>({});
|
const loginData = ref<Recordable<any>>({});
|
||||||
|
|
@ -103,16 +101,14 @@ const handleLogin = async (values: any) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleVerifySuccess = async ({ captchaVerification }: any) => {
|
const handleVerifySuccess = async ({ captchaVerification }: any) => {
|
||||||
await authStore.authLogin(
|
try {
|
||||||
{
|
await authStore.authLogin({
|
||||||
...loginData.value,
|
...loginData.value,
|
||||||
captchaVerification,
|
captchaVerification,
|
||||||
},
|
});
|
||||||
() => {
|
} catch (error) {
|
||||||
// 设置字典数据
|
console.error('Error in handleLogin:', error);
|
||||||
dictStore.setDictCacheByApi(getSimpleDictDataList, 'label', 'value');
|
}
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
watchEffect(async () => {
|
watchEffect(async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue