Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
csbr-daop
/
fe-data-trusted-space
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
c154a02a
authored
2026-03-12 16:46:27 +0800
by
lihua
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
使用接口获取APPKey
1 parent
0b0869a4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
17 deletions
default.conf
src/api/modules/queryService.ts
src/main.ts
src/store/modules/sysConfig.ts
src/views/portal/portalLogin.vue
default.conf
View file @
c154a02
...
...
@@ -26,6 +26,19 @@ server {
expires
-
1
s
;
}
# idaas api
location
/
idaas
/ {
resolver
169
.
254
.
25
.
10
valid
=
30
s
;
proxy_set_header
Host
$
host
;
proxy_set_header
X
-
Real
-
IP
$
remote_addr
;
proxy_set_header
X
-
Forwarded
-
For
$
proxy_add_x_forwarded_for
;
proxy_set_header
X
-
Forwarded
-
Proto
$
scheme
;
proxy_set_header
X
-
Forwarded
-
Port
$
server_port
;
proxy_pass
http
://
ms
-
idaas
-
server
-
service
-
release
.
tds
:
8080
/;
# 门户idaas http测试环境
}
location
/
api
/ {
resolver
127
.
0
.
0
.
11
valid
=
10
s
;
proxy_set_header
Host
$
host
;
...
...
@@ -37,12 +50,12 @@ server {
}
# 专门处理 config.json 的 location
#
location = /config.json {
#
# 启用 sub_filter 并指定 MIME 类型为 application/json
# sub_filter '{{{API_BASE_URL}}}' '${API_BASE_URL
}';
#
sub_filter_once off;
#
sub_filter_types application/json; # 关键:允许替换 JSON 类型
#
}
location
= /
config
.
json
{
# 启用 sub_filter 并指定 MIME 类型为 application/json
sub_filter
'{{{APP_KEY}}}'
'${APP_KEY
}'
;
sub_filter_once
off
;
sub_filter_types
application
/
json
;
# 关键:允许替换 JSON 类型
}
error_page
500
502
503
504
/
50
x
.
html
;
location
= /
50
x
.
html
{
...
...
src/api/modules/queryService.ts
View file @
c154a02
import
request
from
"@/utils/request"
;
/** 获取appKey */
export
const
getAppKey
=
()
=>
{
return
request
({
url
:
`
${
import
.
meta
.
env
.
VITE_APP_USER_API_BASEURL
}
/staff/getAppKey`
,
method
:
"get"
,
});
};
/** 获取数往知来接入idaas的token。 */
export
const
getTokenByCode
=
(
params
)
=>
{
return
request
({
...
...
src/main.ts
View file @
c154a02
...
...
@@ -8,6 +8,7 @@ import router from './router'
import
useSettingsStore
from
'./store/modules/settings'
;
import
{
ElMessage
}
from
"element-plus"
import
{
getPublicIP
,
openMessageBox
}
from
"@/utils/common"
import
sysConfigStore
from
'@/store/modules/sysConfig'
// pinia设置
import
{
createPinia
}
from
'pinia'
...
...
@@ -43,4 +44,6 @@ app.mount('#main-app')
getPublicIP
().
then
((
ip
)
=>
{
localStorage
.
setItem
(
'ipAddress'
,
ip
);
})
\ No newline at end of file
})
sysConfigStore
().
loadingAppKey
();
\ No newline at end of file
...
...
src/store/modules/sysConfig.ts
View file @
c154a02
import
{
getAppKey
}
from
'@/api/modules/queryService'
import
{
ElMessage
}
from
'element-plus'
;
const
sysConfigStore
=
defineStore
(
// 唯一ID
'
c
onfig'
,
'
sysC
onfig'
,
()
=>
{
let
configMap
:
any
=
{};
/** 动态appkey值,从接口获取 */
let
appKey
=
''
;
const
loadingAppKey
=
()
=>
{
getAppKey
().
then
((
res
:
any
)
=>
{
if
(
res
?.
code
==
'00000'
)
{
appKey
=
res
.
data
;
}
else
{
ElMessage
.
error
(
'appKey获取失败'
);
}
})
}
// 封装请求配置文件的函数
const
loadConfig
=
async
()
=>
{
try
{
...
...
@@ -24,13 +40,19 @@ const sysConfigStore = defineStore(
}
const
getConfig
=
(
field
)
=>
{
//
if (import.meta.env.MODE == 'nginx' || import.meta.env.MODE == 'development') {
//
return import.meta.env.VITE_appKey
//
}
if
(
import
.
meta
.
env
.
MODE
==
'nginx'
||
import
.
meta
.
env
.
MODE
==
'development'
)
{
return
import
.
meta
.
env
.
VITE_appKey
}
return
(
field
?
configMap
[
field
]
:
configMap
)
||
'69afd501e4b08251f6cf6419'
;
}
const
getAppKeyValue
=
()
=>
{
return
appKey
;
}
return
{
loadingAppKey
,
getAppKeyValue
,
configMap
,
loadConfig
,
setConfig
,
...
...
src/views/portal/portalLogin.vue
View file @
c154a02
...
...
@@ -749,7 +749,7 @@ const imgCheckDialog = ref(false)
let
LOGINCODE
=
{
grant_type
:
'authorization_code'
,
response_type
:
'code'
,
client_id
:
sysConfigStore
().
get
Config
(
'appKey'
),
client_id
:
sysConfigStore
().
get
AppKeyValue
(
),
scope
:
'other'
,
state
:
'authorization-life'
,
loginRedirectUrl
:
window
.
location
.
origin
// 登录重定向域名
...
...
@@ -767,7 +767,7 @@ async function beforeLogin() {
let
formData
=
await
beforeLoginFormRef
.
value
.
getData
();
let
_logonUser
=
formData
.
logonUser
;
let
password
=
formData
.
password
;
loginStore
.
encodePwd
=
CryptoJS
.
AES
.
encrypt
(
password
,
sysConfigStore
().
get
Config
(
'appKey'
)).
toString
();
loginStore
.
encodePwd
=
CryptoJS
.
AES
.
encrypt
(
password
,
sysConfigStore
().
get
AppKeyValue
(
)).
toString
();
loading
.
value
=
true
;
let
loginRes
=
await
idaasStore
.
login
(
formData
);
loading
.
value
=
false
;
...
...
@@ -850,7 +850,7 @@ async function handleLogin(params) {
//const result = isJsonString(res) ? JSON.parse(res) : res;
// let scope = result.data.authorities?.map(a => a.authority).join(' ');
if
(
!
client_id
)
{
client_id
=
sysConfigStore
().
get
Config
(
'appKey'
);
client_id
=
sysConfigStore
().
get
AppKeyValue
(
);
}
let
hrefOrigin
=
window
.
location
.
origin
;
if
(
!
redirect_uri
)
{
...
...
@@ -1041,12 +1041,12 @@ const passKeyLogin = () => {
let
client_id
=
route
.
query
.
client_id
;
let
redirect_uri
=
route
.
query
.
redirect_uri
;
if
(
!
client_id
)
{
client_id
=
sysConfigStore
().
get
Config
(
'appKey'
);
client_id
=
sysConfigStore
().
get
AppKeyValue
(
);
}
let
hrefOrigin
=
window
.
location
.
origin
;
if
(
!
redirect_uri
)
{
//redirect_uri = import.meta.env.VITE_redirectUrl
redirect_uri
=
hrefOrigin
+
'/
login
'
;
redirect_uri
=
hrefOrigin
+
'/'
;
}
let
state
=
createStateHashCode
();
let
url
=
`
${
hrefOrigin
}
/idaas/oauth2/authorize?response_type=
${
LOGINCODE
.
response_type
}
&client_id=
${
client_id
}
&scope=other&state=
${
state
}
&redirect_uri=
${
encodeURIComponent
(
redirect_uri
)}
`
...
...
@@ -1067,7 +1067,7 @@ const passKeyLogin = () => {
function
toCheckSmsCode
()
{
let
isCheckSms
=
loginStore
.
isCheckSms
;
if
(
isCheckSms
)
{
let
password
=
CryptoJS
.
AES
.
decrypt
(
loginStore
.
encodePwd
||
''
,
sysConfigStore
().
get
Config
(
'appKey'
)).
toString
(
CryptoJS
.
enc
.
Utf8
)
let
password
=
CryptoJS
.
AES
.
decrypt
(
loginStore
.
encodePwd
||
''
,
sysConfigStore
().
get
AppKeyValue
(
)).
toString
(
CryptoJS
.
enc
.
Utf8
)
let
principal
=
idaasStore
.
idaasUserInfo
.
principal
formType
.
value
=
'login'
;
nextTick
(()
=>
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment