From c2358e213211d801cde77761a2056be3f55573e8 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 20 Mar 2025 23:12:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20request=20&&=20login=20&&=20router?= =?UTF-8?q?=E3=80=90e6939e22=E3=80=91=EF=BC=88login.vue=20=E5=92=8C=20requ?= =?UTF-8?q?est.ts=20=E5=A2=9E=E5=8A=A0=E7=A7=9F=E6=88=B7=E7=9A=84=E9=80=89?= =?UTF-8?q?=E6=8B=A9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/.env.development | 2 - apps/web-antd/src/api/core/auth.ts | 42 ++++++++- apps/web-antd/src/api/request.ts | 7 +- .../src/views/_core/authentication/login.vue | 85 +++++++++++++------ .../src/langs/en-US/authentication.json | 1 + .../src/langs/zh-CN/authentication.json | 1 + packages/stores/src/modules/access.ts | 10 ++- 7 files changed, 113 insertions(+), 35 deletions(-) diff --git a/apps/web-antd/.env.development b/apps/web-antd/.env.development index fa8b5b0c8..5d29cd97b 100644 --- a/apps/web-antd/.env.development +++ b/apps/web-antd/.env.development @@ -11,8 +11,6 @@ VITE_DEVTOOLS=false # 是否注入全局loading VITE_INJECT_APP_LOADING=true -# 默认租户名称 -VITE_APP_DEFAULT_TENANT_NAME=芋道源码 # 默认登录用户名 VITE_APP_DEFAULT_USERNAME=admin # 默认登录密码 diff --git a/apps/web-antd/src/api/core/auth.ts b/apps/web-antd/src/api/core/auth.ts index b225591f7..f5e74caf3 100644 --- a/apps/web-antd/src/api/core/auth.ts +++ b/apps/web-antd/src/api/core/auth.ts @@ -21,6 +21,13 @@ export namespace AuthApi { data: string; status: number; } + + /** 租户信息返回值 */ + export interface TenantResult { + id: number; + name: string; + } + } /** @@ -34,7 +41,8 @@ export async function loginApi(data: AuthApi.LoginParams) { * 刷新 accessToken */ export async function refreshTokenApi() { - return baseRequestClient.post('/auth/refresh', { + // TODO @芋艿:refreshToken 传递 + return baseRequestClient.post('/system/auth/refresh', { withCredentials: true, }); } @@ -43,7 +51,7 @@ export async function refreshTokenApi() { * 退出登录 */ export async function logoutApi() { - return baseRequestClient.post('/auth/logout', { + return baseRequestClient.post('/system/auth/logout', { withCredentials: true, }); } @@ -62,4 +70,32 @@ export function getAuthPermissionInfoApi() { return requestClient.get( '/system/auth/get-permission-info', ); -} \ No newline at end of file +} + +/** + * 获取租户列表 + */ +export function getTenantSimpleList() { + return requestClient.get( + `/system/tenant/simple-list`, + ); +} + +/** + * 使用租户域名,获得租户信息 + */ +export function getTenantByWebsite(website: string) { + // TODO @芋艿:改成 params 传递? + return requestClient.get(`/system/tenant/get-by-website?website=${website}`); +} + +// TODO 芋艿:后续怎么放好。 +// // 获取验证图片 以及token +// export async function getCaptcha(data: any) { +// return baseRequestClient.post('/system/captcha/get', data); +// } +// +// // 滑动或者点选验证 +// export async function checkCaptcha(data: any) { +// return baseRequestClient.post('/system/captcha/check', data); +// } \ No newline at end of file diff --git a/apps/web-antd/src/api/request.ts b/apps/web-antd/src/api/request.ts index e5e2ef439..3d1892332 100644 --- a/apps/web-antd/src/api/request.ts +++ b/apps/web-antd/src/api/request.ts @@ -19,7 +19,7 @@ import { useAuthStore } from '#/store'; import { refreshTokenApi } from './core'; -const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD); +const { apiURL, tenantEnable } = useAppConfig(import.meta.env, import.meta.env.PROD); function createRequestClient(baseURL: string, options?: RequestClientOptions) { const client = new RequestClient({ @@ -67,10 +67,7 @@ function createRequestClient(baseURL: string, options?: RequestClientOptions) { config.headers.Authorization = formatToken(accessStore.accessToken); config.headers['Accept-Language'] = preferences.app.locale; - config.headers['tenant-id'] = 1 - // TODO @芋艿:优化一下 - // config.headers['tenant-id'] = - // tenantEnable && tenantId ? tenantId : undefined; + config.headers['tenant-id'] = tenantEnable ? accessStore.tenantId : undefined; return config; }, }); diff --git a/apps/web-antd/src/views/_core/authentication/login.vue b/apps/web-antd/src/views/_core/authentication/login.vue index e033384cf..cfd49f570 100644 --- a/apps/web-antd/src/views/_core/authentication/login.vue +++ b/apps/web-antd/src/views/_core/authentication/login.vue @@ -1,48 +1,85 @@