From 87bcf33940dc37a9d8a62e0d0bf316e26cee01e8 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Wed, 16 Jul 2025 22:41:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(tenant):=20=E4=BC=98=E5=8C=96=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/auth/index.ts | 29 +++- src/apis/system/type.ts | 1 + src/apis/tenant/management.ts | 6 - src/components/SelectTenant/index.vue | 168 ------------------- src/stores/modules/app.ts | 6 + src/stores/modules/user.ts | 12 +- src/utils/http.ts | 9 +- src/views/login/components/account/index.vue | 14 +- src/views/login/components/email/index.vue | 12 +- src/views/login/components/phone/index.vue | 12 +- 10 files changed, 69 insertions(+), 200 deletions(-) delete mode 100644 src/components/SelectTenant/index.vue diff --git a/src/apis/auth/index.ts b/src/apis/auth/index.ts index 6b7cd93..1547e70 100644 --- a/src/apis/auth/index.ts +++ b/src/apis/auth/index.ts @@ -5,19 +5,32 @@ export type * from './type' const BASE_URL = '/auth' -/** @desc 账号登录 */ -export function accountLogin(req: T.AccountLoginReq) { - return http.post(`${BASE_URL}/login`, req) +const login = (req: T.AccountLoginReq | T.PhoneLoginReq | T.EmailLoginReq, tenantCode?: string) => { + const headers = {} + if (tenantCode) { + headers['X-Tenant-Code'] = tenantCode + } + return http.requestNative({ + url: `${BASE_URL}/login`, + data: req, + method: 'post', + headers, + }) } -/** @desc 手机号登录 */ -export function phoneLogin(req: T.PhoneLoginReq) { - return http.post(`${BASE_URL}/login`, req) +/** @desc 账号登录 */ +export function accountLogin(req: T.AccountLoginReq, tenantCode?: string) { + return login(req, tenantCode) } /** @desc 邮箱登录 */ -export function emailLogin(req: T.EmailLoginReq) { - return http.post(`${BASE_URL}/login`, req) +export function emailLogin(req: T.EmailLoginReq, tenantCode?: string) { + return login(req, tenantCode) +} + +/** @desc 手机号登录 */ +export function phoneLogin(req: T.PhoneLoginReq, tenantCode?: string) { + return login(req, tenantCode) } /** @desc 三方账号登录 */ diff --git a/src/apis/system/type.ts b/src/apis/system/type.ts index 3528a2b..dc4472c 100644 --- a/src/apis/system/type.ts +++ b/src/apis/system/type.ts @@ -335,6 +335,7 @@ export interface BasicConfig { SITE_TITLE: string SITE_COPYRIGHT: string SITE_BEIAN: string + TENANT_ENABLED: boolean } /** 基础配置类型 */ diff --git a/src/apis/tenant/management.ts b/src/apis/tenant/management.ts index abd3e70..3c356d7 100644 --- a/src/apis/tenant/management.ts +++ b/src/apis/tenant/management.ts @@ -1,6 +1,5 @@ import type * as T from './type' import http from '@/utils/http' -import type { TenantCommon } from '@/utils/tenant' export type * from './type' @@ -31,11 +30,6 @@ export function deleteTenant(id: string) { return http.del(`${BASE_URL}/${id}`) } -/** @desc 多租户通用信息查询 */ -export const getTenantCommon = () => { - return http.get(`${BASE_URL}/common`) -} - /** @desc 修改租户管理员密码 */ export const updateTenantAdminUserPwd = (data: any, id: string) => { return http.put(`${BASE_URL}/${id}/admin/pwd`, data) diff --git a/src/components/SelectTenant/index.vue b/src/components/SelectTenant/index.vue deleted file mode 100644 index 4783928..0000000 --- a/src/components/SelectTenant/index.vue +++ /dev/null @@ -1,168 +0,0 @@ - - - - - diff --git a/src/stores/modules/app.ts b/src/stores/modules/app.ts index 286834f..c60079a 100644 --- a/src/stores/modules/app.ts +++ b/src/stores/modules/app.ts @@ -68,6 +68,7 @@ const storeSetup = () => { siteConfig.SITE_TITLE = resMap.get('SITE_TITLE') siteConfig.SITE_COPYRIGHT = resMap.get('SITE_COPYRIGHT') siteConfig.SITE_BEIAN = resMap.get('SITE_BEIAN') + siteConfig.TENANT_ENABLED = resMap.get('TENANT_ENABLED') === 'true' document.title = resMap.get('SITE_TITLE') document .querySelector('link[rel="shortcut icon"]') @@ -122,6 +123,10 @@ const storeSetup = () => { const getForRecord = () => { return siteConfig.SITE_BEIAN } + + const getTenantEnabled = () => { + return siteConfig.TENANT_ENABLED + } return { ...toRefs(settingConfig), ...toRefs(siteConfig), @@ -138,6 +143,7 @@ const storeSetup = () => { getTitle, getCopyright, getForRecord, + getTenantEnabled, } } diff --git a/src/stores/modules/user.ts b/src/stores/modules/user.ts index a363b38..a281342 100644 --- a/src/stores/modules/user.ts +++ b/src/stores/modules/user.ts @@ -50,22 +50,22 @@ const storeSetup = () => { } // 登录 - const accountLogin = async (req: AccountLoginReq) => { - const res = await accountLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.ACCOUNT }) + const accountLogin = async (req: AccountLoginReq, tenantCode?: string) => { + const res = await accountLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.ACCOUNT }, tenantCode) setToken(res.data.token) token.value = res.data.token } // 邮箱登录 - const emailLogin = async (req: EmailLoginReq) => { - const res = await emailLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.EMAIL }) + const emailLogin = async (req: EmailLoginReq, tenantCode?: string) => { + const res = await emailLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.EMAIL }, tenantCode) setToken(res.data.token) token.value = res.data.token } // 手机号登录 - const phoneLogin = async (req: PhoneLoginReq) => { - const res = await phoneLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.PHONE }) + const phoneLogin = async (req: PhoneLoginReq, tenantCode?: string) => { + const res = await phoneLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.PHONE }, tenantCode) setToken(res.data.token) token.value = res.data.token } diff --git a/src/utils/http.ts b/src/utils/http.ts index 536e9e8..54aee08 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -52,17 +52,14 @@ const handleError = (msg: string) => { http.interceptors.request.use( (config: AxiosRequestConfig) => { const token = getToken() + if (!config.headers) { + config.headers = {} + } if (token) { - if (!config.headers) { - config.headers = {} - } config.headers.Authorization = `Bearer ${token}` } const tenantId = getTenantId() if (tenantId) { - if (!config.headers) { - config.headers = {} - } config.headers['X-Tenant-Id'] = tenantId } return config diff --git a/src/views/login/components/account/index.vue b/src/views/login/components/account/index.vue index 32431bd..5ee0ede 100644 --- a/src/views/login/components/account/index.vue +++ b/src/views/login/components/account/index.vue @@ -8,6 +8,9 @@ size="large" @submit="handleLogin" > + + + @@ -40,12 +43,17 @@