From 54f9d0c10fbe16050304f06dd186b8f8b16ecf02 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 16 Apr 2025 18:35:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20sso=20=E5=8D=95?= =?UTF-8?q?=E7=82=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/api/request.ts | 3 + apps/web-antd/src/router/routes/core.ts | 8 + apps/web-antd/src/store/auth.ts | 2 +- .../_core/authentication/social-login.vue | 3 +- .../views/_core/authentication/sso-login.vue | 205 ++++++++++++++++++ .../common-ui/src/ui/authentication/index.ts | 1 + .../src/ui/authentication/qrcode-login.vue | 3 +- 7 files changed, 222 insertions(+), 3 deletions(-) create mode 100644 apps/web-antd/src/views/_core/authentication/sso-login.vue diff --git a/apps/web-antd/src/api/request.ts b/apps/web-antd/src/api/request.ts index b6375aaff..8c36097ff 100644 --- a/apps/web-antd/src/api/request.ts +++ b/apps/web-antd/src/api/request.ts @@ -51,6 +51,9 @@ function createRequestClient(baseURL: string, options?: RequestClientOptions) { async function doRefreshToken() { const accessStore = useAccessStore(); const refreshToken = accessStore.refreshToken as string; + if (!refreshToken) { + throw new Error('Refresh token is null!'); + } const resp = await refreshTokenApi(refreshToken); const newToken = resp?.data?.data?.accessToken; // add by 芋艿:这里一定要抛出 resp.data,从而触发 authenticateResponseInterceptor 中,刷新令牌失败!!! diff --git a/apps/web-antd/src/router/routes/core.ts b/apps/web-antd/src/router/routes/core.ts index ad8fc861d..5058a2d5b 100644 --- a/apps/web-antd/src/router/routes/core.ts +++ b/apps/web-antd/src/router/routes/core.ts @@ -97,6 +97,14 @@ const coreRoutes: RouteRecordRaw[] = [ title: $t('page.auth.login'), }, }, + { + name: 'SSOLogin', + path: 'sso-login', + component: () => import('#/views/_core/authentication/sso-login.vue'), + meta: { + title: $t('page.auth.login'), + }, + } ], }, ]; diff --git a/apps/web-antd/src/store/auth.ts b/apps/web-antd/src/store/auth.ts index 7f91d4639..4807dfcd8 100644 --- a/apps/web-antd/src/store/auth.ts +++ b/apps/web-antd/src/store/auth.ts @@ -108,7 +108,7 @@ export const useAuthStore = defineStore('auth', () => { let authPermissionInfo: AuthPermissionInfo | null = null; authPermissionInfo = await getAuthPermissionInfoApi(); // userStore - userStore.setUserInfo(authPermissionInfo.user); // TODO @芋艿:这里有报错 + userStore.setUserInfo(authPermissionInfo.user); userStore.setUserRoles(authPermissionInfo.roles); // accessStore accessStore.setAccessMenus(authPermissionInfo.menus); diff --git a/apps/web-antd/src/views/_core/authentication/social-login.vue b/apps/web-antd/src/views/_core/authentication/social-login.vue index a13b01697..f70fcf167 100644 --- a/apps/web-antd/src/views/_core/authentication/social-login.vue +++ b/apps/web-antd/src/views/_core/authentication/social-login.vue @@ -16,7 +16,7 @@ import { getTenantSimpleList, getTenantByWebsite } from '#/api/core/auth'; const { tenantEnable, captchaEnable } = useAppConfig(import.meta.env, import.meta.env.PROD); -defineOptions({ name: 'Login' }); +defineOptions({ name: 'SocialLogin' }); const authStore = useAuthStore(); const accessStore = useAccessStore(); @@ -34,6 +34,7 @@ const fetchTenantList = async () => { if (!tenantEnable) { return; } + try { // 获取租户列表、域名对应租户 const websiteTenantPromise = getTenantByWebsite(window.location.hostname); diff --git a/apps/web-antd/src/views/_core/authentication/sso-login.vue b/apps/web-antd/src/views/_core/authentication/sso-login.vue new file mode 100644 index 000000000..29b0f1c17 --- /dev/null +++ b/apps/web-antd/src/views/_core/authentication/sso-login.vue @@ -0,0 +1,205 @@ + + + diff --git a/packages/effects/common-ui/src/ui/authentication/index.ts b/packages/effects/common-ui/src/ui/authentication/index.ts index 71f41a889..0120531d1 100644 --- a/packages/effects/common-ui/src/ui/authentication/index.ts +++ b/packages/effects/common-ui/src/ui/authentication/index.ts @@ -5,4 +5,5 @@ export { default as AuthenticationLogin } from './login.vue'; export { default as AuthenticationQrCodeLogin } from './qrcode-login.vue'; export { default as AuthenticationRegister } from './register.vue'; export { default as DocLink } from './doc-link.vue'; +export { default as AuthenticationAuthTitle } from './auth-title.vue'; export type { AuthenticationProps } from './types'; diff --git a/packages/effects/common-ui/src/ui/authentication/qrcode-login.vue b/packages/effects/common-ui/src/ui/authentication/qrcode-login.vue index aee41a8db..3813f11d8 100644 --- a/packages/effects/common-ui/src/ui/authentication/qrcode-login.vue +++ b/packages/effects/common-ui/src/ui/authentication/qrcode-login.vue @@ -52,7 +52,8 @@ const props = withDefaults(defineProps(), { const router = useRouter(); -const text = ref('https://vben.vvbin.cn'); +// const text = ref('https://vben.vvbin.cn'); +const text = ref('https://t.zsxq.com/FUtQd'); const qrcode = useQRCode(text, { errorCorrectionLevel: 'H',