|
|
@@ -11,9 +11,8 @@ import { ElNotification } from 'element-plus';
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
|
|
import {
|
|
|
- getAccessCodesApi,
|
|
|
+ // getAccessCodesApi,
|
|
|
getLoginCaptchaApi,
|
|
|
- getUserInfoApi,
|
|
|
loginApi,
|
|
|
logoutApi,
|
|
|
} from '#/api';
|
|
|
@@ -26,6 +25,8 @@ export const useAuthStore = defineStore('auth', () => {
|
|
|
|
|
|
const loginLoading = ref(false);
|
|
|
|
|
|
+ const userStorage = useStorage('user');
|
|
|
+
|
|
|
/**
|
|
|
* 异步处理登录操作
|
|
|
* Asynchronously handle the login process
|
|
|
@@ -66,6 +67,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|
|
// "grouplist": "1"
|
|
|
|
|
|
const { token: accessToken } = res;
|
|
|
+ userStorage.setItem(res);
|
|
|
|
|
|
// 如果成功获取到 accessToken
|
|
|
if (accessToken) {
|
|
|
@@ -73,12 +75,14 @@ export const useAuthStore = defineStore('auth', () => {
|
|
|
accessStore.setAccessToken(accessToken);
|
|
|
|
|
|
// 获取用户信息并存储到 accessStore 中
|
|
|
- const [fetchUserInfoResult, accessCodes] = await Promise.all([
|
|
|
- fetchUserInfo(),
|
|
|
- getAccessCodesApi(),
|
|
|
- ]);
|
|
|
+ const fetchUserInfoResult = (await fetchUserInfo()) as any;
|
|
|
+ const accessCodes = fetchUserInfoResult.popedom;
|
|
|
+ // const [fetchUserInfoResult, accessCodes] = await Promise.all([
|
|
|
+ // fetchUserInfo(),
|
|
|
+ // getAccessCodesApi(),
|
|
|
+ // ]);
|
|
|
|
|
|
- userInfo = fetchUserInfoResult;
|
|
|
+ userInfo = fetchUserInfoResult as any;
|
|
|
|
|
|
userStore.setUserInfo(userInfo);
|
|
|
accessStore.setAccessCodes(accessCodes);
|
|
|
@@ -88,7 +92,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|
|
} else {
|
|
|
onSuccess
|
|
|
? await onSuccess?.()
|
|
|
- : await router.push(userInfo.homePath || DEFAULT_HOME_PATH);
|
|
|
+ : await router.push(userInfo?.homePath || DEFAULT_HOME_PATH);
|
|
|
}
|
|
|
|
|
|
if (userInfo?.realName) {
|
|
|
@@ -129,10 +133,11 @@ export const useAuthStore = defineStore('auth', () => {
|
|
|
}
|
|
|
|
|
|
async function fetchUserInfo() {
|
|
|
- let userInfo: null | UserInfo = null;
|
|
|
- userInfo = await getUserInfoApi();
|
|
|
- userStore.setUserInfo(userInfo);
|
|
|
- return userInfo;
|
|
|
+ const userInfoData = userStorage.getItem();
|
|
|
+ // let userInfo: null | UserInfo = null;
|
|
|
+ // userInfo = await getUserInfoApi();
|
|
|
+ userStore.setUserInfo(userInfoData as any);
|
|
|
+ return userInfoData;
|
|
|
}
|
|
|
|
|
|
function $reset() {
|