From adba0142f17d04db3bebaa51fca27cd7f18b4403 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 6 Nov 2023 19:42:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=A7=9F=E6=88=B7=EF=BC=9A=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=95=8C=E9=9D=A2=EF=BC=8C=E6=A0=B9=E6=8D=AE=20host?= =?UTF-8?q?=20=E5=9F=9F=E5=90=8D=E8=8E=B7=E5=8F=96=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=9A=84=E7=A7=9F=E6=88=B7=E7=BC=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 85ee558bef3937554deb7ab208b4c160590f6d2d) --- src/api/login/index.ts | 5 ++++ src/views/Login/components/LoginForm.vue | 35 +++++++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/api/login/index.ts b/src/api/login/index.ts index 8822d2ea..d503d73a 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -27,6 +27,11 @@ export const getTenantIdByNameApi = (name: string) => { return request.get({ url: '/system/tenant/get-id-by-name?name=' + name }) } +// 使用租户域名,获得租户信息 +export const getTenantByWebsite = (website: string) => { + return request.get({ url: '/system/tenant/get-by-website?website=' + website }) +} + // 登出 export const loginOutApi = () => { return request.post({ url: '/system/auth/logout' }) diff --git a/src/views/Login/components/LoginForm.vue b/src/views/Login/components/LoginForm.vue index d75dc3ca..34968bd2 100644 --- a/src/views/Login/components/LoginForm.vue +++ b/src/views/Login/components/LoginForm.vue @@ -18,11 +18,11 @@ @@ -193,10 +193,10 @@ const loginData = reactive({ }) const socialList = [ - { icon: 'ant-design:github-filled', type: 0 }, { icon: 'ant-design:wechat-filled', type: 30 }, - { icon: 'ant-design:alipay-circle-filled', type: 0 }, - { icon: 'ant-design:dingtalk-circle-filled', type: 20 } + { icon: 'ant-design:dingtalk-circle-filled', type: 20 }, + { icon: 'ant-design:github-filled', type: 0 }, + { icon: 'ant-design:alipay-circle-filled', type: 0 } ] // 获取验证码 @@ -210,7 +210,7 @@ const getCode = async () => { verify.value.show() } } -//获取租户ID +// 获取租户 ID const getTenantId = async () => { if (loginData.tenantEnable === 'true') { const res = await LoginApi.getTenantIdByNameApi(loginData.loginForm.tenantName) @@ -231,6 +231,15 @@ const getCookie = () => { } } } +// 根据域名,获得租户信息 +const getTenantByWebsite = async () => { + const website = location.host + const res = await LoginApi.getTenantByWebsite(website) + if (res) { + loginData.loginForm.tenantName = res.name + authUtil.setTenantId(res.id) + } +} const loading = ref() // ElLoading.service 返回的实例 // 登录 const handleLogin = async (params) => { @@ -279,10 +288,15 @@ const doSocialLogin = async (type: number) => { } else { loginLoading.value = true if (loginData.tenantEnable === 'true') { - await message.prompt('请输入租户名称', t('common.reminder')).then(async ({ value }) => { - const res = await LoginApi.getTenantIdByNameApi(value) - authUtil.setTenantId(res) - }) + // 尝试先通过 tenantName 获取租户 + await getTenantId() + // 如果获取不到,则需要弹出提示,进行处理 + if (!authUtil.getTenantId()) { + await message.prompt('请输入租户名称', t('common.reminder')).then(async ({ value }) => { + const res = await LoginApi.getTenantIdByNameApi(value) + authUtil.setTenantId(res) + }) + } } // 计算 redirectUri // tricky: type、redirect需要先encode一次,否则钉钉回调会丢失。 @@ -308,6 +322,7 @@ watch( ) onMounted(() => { getCookie() + getTenantByWebsite() })