多租户:登录界面,根据 host 域名获取对应的租户编号

(cherry picked from commit 85ee558bef)
This commit is contained in:
YunaiV 2023-11-06 19:42:28 +08:00 committed by shizhong
parent e2047eb6e9
commit adba0142f1
2 changed files with 30 additions and 10 deletions

View File

@ -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' })

View File

@ -18,11 +18,11 @@
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item v-if="loginData.tenantEnable === 'true'" prop="tenantName">
<el-input
type="primary"
link
v-model="loginData.loginForm.tenantName"
:placeholder="t('login.tenantNamePlaceholder')"
:prefix-icon="iconHouse"
link
type="primary"
/>
</el-form-item>
</el-col>
@ -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: typeredirectencode
@ -308,6 +322,7 @@ watch(
)
onMounted(() => {
getCookie()
getTenantByWebsite()
})
</script>