From 8ed93030a4dbc9816c850e0ff66cc01231a4d00b Mon Sep 17 00:00:00 2001 From: shiningrise Date: Thu, 18 Sep 2025 09:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=8E=AF=E5=A2=83=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E6=B3=9B=E5=9F=9F=E5=90=8D=E8=AE=BF=E9=97=AE=EF=BC=8C?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E6=A0=B9=E6=8D=AE=E5=9F=9F=E5=90=8D=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E7=A7=9F=E6=88=B7=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web/src/api/login/index.ts | 10 +++++++++- Web/src/views/login/component/account.vue | 3 ++- Web/src/views/login/index.vue | 10 ++++++++-- Web/vite.config.ts | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Web/src/api/login/index.ts b/Web/src/api/login/index.ts index 71ed9461..fb54d4e7 100644 --- a/Web/src/api/login/index.ts +++ b/Web/src/api/login/index.ts @@ -1,5 +1,7 @@ import request from '/@/utils/request'; - +enum Api { + GetTenantIdByHostname = '/api/sysAuth/tenantIdByHostname', +} /** * (不建议写成 request.post(xxx),因为这样 post 时,无法 params 与 data 同时传参) * @@ -25,3 +27,9 @@ export function useLoginApi() { }, }; } + +export const getTenantIdByHostname = (hostname: string) => + request({ + url: `${Api.GetTenantIdByHostname}/${hostname}`, + method: 'get', + }); diff --git a/Web/src/views/login/component/account.vue b/Web/src/views/login/component/account.vue index 8fb513d9..cda82f49 100644 --- a/Web/src/views/login/component/account.vue +++ b/Web/src/views/login/component/account.vue @@ -229,7 +229,8 @@ const onSignIn = async () => { const publicKey = window.__env__.VITE_SM_PUBLIC_KEY; const password = sm2.doEncrypt(state.ruleForm.password, publicKey, 1); - const tenantid = route.query.tid ?? 0; + //const tenantid = route.query.tid ?? 0; + const tenantid = Local.get('tid') ?? 0; const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthLoginPost({ ...state.ruleForm, password: password, tenantId: Number(tenantid) })); if (err) { getCaptcha(); // 重新获取验证码 diff --git a/Web/src/views/login/index.vue b/Web/src/views/login/index.vue index 722afd53..3552f35f 100644 --- a/Web/src/views/login/index.vue +++ b/Web/src/views/login/index.vue @@ -102,7 +102,7 @@ import { Local } from '/@/utils/storage'; // 引入多语言 import { languageList, getCountryCode } from '/@/i18n'; import '/node_modules/flag-icons/css/flag-icons.min.css'; - +import { getTenantIdByHostname } from '/@/api/login/index'; // 引入组件 const Account = defineAsyncComponent(() => import('/@/views/login/component/account.vue')); const Mobile = defineAsyncComponent(() => import('/@/views/login/component/mobile.vue')); @@ -129,7 +129,13 @@ onMounted(async () => { if (!route.query.tid) Local.remove('tid'); var tenantid = Number(route.query.tid); if (isNaN(tenantid)) { - tenantid = 0; + // 确保hostname不包含端口号 + const hostnameWithoutPort = window.location.hostname; + const data = await getTenantIdByHostname(hostnameWithoutPort); + console.log('tenantid', data.data.result); + tenantid = data.data.result; + if (tenantid > 99999) + Local.set('tid', tenantid); } else if (tenantid > 99999) { Local.set('tid', tenantid); } diff --git a/Web/vite.config.ts b/Web/vite.config.ts index 312533e7..3798a14f 100644 --- a/Web/vite.config.ts +++ b/Web/vite.config.ts @@ -101,6 +101,7 @@ const viteConfig = defineConfig((mode: ConfigEnv) => { port: env.VITE_PORT as unknown as number, open: JSON.parse(env.VITE_OPEN), hmr: true, + allowedHosts:true, proxy: { '^/[Uu]pload': { target: env.VITE_API_URL,