pki登录bug修复

master
YIN 2026-04-08 09:04:52 +08:00
parent e7f1634003
commit 5d5fe6419c
2 changed files with 48 additions and 2 deletions

View File

@ -10,7 +10,7 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
import { notification } from 'ant-design-vue';
import { defineStore } from 'pinia';
import { doLogout, getUserInfoApi, loginApi, seeConnectionClose } from '#/api';
import { doLogout, getUserInfoApi, loginApi, seeConnectionClose, pkiLogin } from '#/api';
import { $t } from '#/locales';
import { useDictStore } from './dict';
@ -82,6 +82,50 @@ export const useAuthStore = defineStore('auth', () => {
};
}
async function authPKILogin(params: any, onSuccess?: () => Promise<void> | void) {
// 异步处理用户登录操作并获取 accessToken
let userInfo: null | UserInfo = null;
try {
loginLoading.value = true;
const { access_token } = await pkiLogin(params);
// 将 accessToken 存储到 accessStore 中
accessStore.setAccessToken(access_token);
accessStore.setRefreshToken(access_token);
// 获取用户信息并存储到 accessStore 中
userInfo = await fetchUserInfo();
/**
*
*/
userStore.setUserInfo(userInfo);
/**
*
*/
accessStore.setAccessCodes(userInfo.permissions);
if (accessStore.loginExpired) {
accessStore.setLoginExpired(false);
} else {
onSuccess ? await onSuccess?.() : await router.push(DEFAULT_HOME_PATH);
}
if (userInfo?.realName) {
notification.success({
description: `${$t('authentication.loginSuccessDesc')}:${userInfo?.realName}`,
duration: 3,
message: $t('authentication.loginSuccess'),
});
}
} finally {
loginLoading.value = false;
}
return {
userInfo,
};
}
async function logout(redirect: boolean = true) {
try {
await seeConnectionClose();
@ -143,6 +187,7 @@ export const useAuthStore = defineStore('auth', () => {
return {
$reset,
authLogin,
authPKILogin,
fetchUserInfo,
loginLoading,
logout,

View File

@ -27,8 +27,9 @@
"scripts": {
"build": "cross-env NODE_OPTIONS=--max-old-space-size=8192 turbo build",
"build:analyze": "turbo build:analyze",
"build:antd": "pnpm run build --filter=@vben/web-antd",
"build:antd": "pnpm run build NODE_OPTIONS=--max-old-space-size=8192 --filter=@vben/web-antd",
"build:docker": "./scripts/deploy/build-local-docker-image.sh",
"build:antd:fix": "node --max-old-space-size=8192 node_modules/vite/bin/vite.js build --config vite.config.antd.ts",
"changeset": "pnpm exec changeset",
"check": "pnpm run check:circular && pnpm run check:dep && pnpm run check:type && pnpm check:cspell",
"check:circular": "vsh check-circular",