Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e9299c67
authored
Nov 06, 2023
by
YunaiV
Committed by
owen
Nov 09, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多租户:登录界面,根据 host 域名获取对应的租户编号
parent
a08e9bea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
8 deletions
+28
-8
src/api/login/index.ts
+5
-0
src/views/Login/components/LoginForm.vue
+23
-8
No files found.
src/api/login/index.ts
View file @
e9299c67
...
...
@@ -27,6 +27,11 @@ export const getTenantIdByName = (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
loginOut
=
()
=>
{
return
request
.
post
({
url
:
'/system/auth/logout'
})
...
...
src/views/Login/components/LoginForm.vue
View file @
e9299c67
...
...
@@ -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
.
getTenantIdByName
(
loginData
.
loginForm
.
tenantName
)
...
...
@@ -230,6 +230,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
)
=>
{
...
...
@@ -278,10 +287,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
.
getTenantIdByName
(
value
)
authUtil
.
setTenantId
(
res
)
})
// 尝试先通过 tenantName 获取租户
await
getTenantId
()
// 如果获取不到,则需要弹出提示,进行处理
if
(
!
authUtil
.
getTenantId
())
{
await
message
.
prompt
(
'请输入租户名称'
,
t
(
'common.reminder'
)).
then
(
async
({
value
})
=>
{
const
res
=
await
LoginApi
.
getTenantIdByName
(
value
)
authUtil
.
setTenantId
(
res
)
})
}
}
// 计算 redirectUri
// tricky: type、redirect需要先encode一次,否则钉钉回调会丢失。
...
...
@@ -307,6 +321,7 @@ watch(
)
onMounted
(()
=>
{
getCookie
()
getTenantByWebsite
()
})
</
script
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment