From 5d5fe6419cd368bb278d01552ef1c760973b7cb5 Mon Sep 17 00:00:00 2001 From: YIN Date: Wed, 8 Apr 2026 09:04:52 +0800 Subject: [PATCH] =?UTF-8?q?pki=E7=99=BB=E5=BD=95bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/store/auth.ts | 47 ++++++++++++++++++++++++++++++++- package.json | 3 ++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/apps/web-antd/src/store/auth.ts b/apps/web-antd/src/store/auth.ts index 16c3554..9459287 100644 --- a/apps/web-antd/src/store/auth.ts +++ b/apps/web-antd/src/store/auth.ts @@ -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) { + // 异步处理用户登录操作并获取 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, diff --git a/package.json b/package.json index 2f8b8ab..6a08800 100644 --- a/package.json +++ b/package.json @@ -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",