Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4783f1c9
authored
Dec 01, 2025
by
Lin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 登录表单加密/获取用户信息接口联调
1 parent
162683cc
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
158 additions
and
59 deletions
apps/frontend-micro/venus-base/src/utils/request.ts
apps/frontend/venus-agentic/venus-agentic-assisant/src/App.vue
apps/frontend/venus-agentic/venus-agentic-base/src/api/user.ts
apps/frontend/venus-agentic/venus-agentic-base/src/config/center.ts
apps/frontend/venus-agentic/venus-agentic-base/src/config/gscrequest.ts
apps/frontend/venus-agentic/venus-agentic-base/src/layouts/BasicLayout.vue
apps/frontend/venus-agentic/venus-agentic-base/src/layouts/components/UserInfo.vue
apps/frontend/venus-agentic/venus-agentic-base/src/stores/user.ts
apps/frontend/venus-agentic/venus-agentic-base/src/views/Login.vue
apps/frontend-micro/venus-base/src/utils/request.ts
View file @
4783f1c
...
...
@@ -29,7 +29,7 @@ service.interceptors.request.use(
// 添加 token
const
token
=
getToken
();
if
(
token
&&
config
.
headers
)
{
config
.
headers
.
Authorization
=
`
Bearer
${
token
}
`
;
config
.
headers
.
Authorization
=
`
${
token
}
`
;
}
// 添加时间戳防止缓存
...
...
apps/frontend/venus-agentic/venus-agentic-assisant/src/App.vue
View file @
4783f1c
<
script
setup
lang=
"ts"
>
import
{
onMounted
}
from
'vue'
;
import
{
login
}
from
'./api/example'
;
onMounted
(()
=>
{
login
(
'admin'
,
'123456'
);
console
.
log
(
'Vue3 微应用已挂载'
);
});
</
script
>
...
...
apps/frontend/venus-agentic/venus-agentic-base/src/api/user.ts
View file @
4783f1c
...
...
@@ -6,23 +6,18 @@ import type { ApiResponse } from '@/types/api';
import
type
{
ChangePasswordParams
,
LoginParams
,
LoginResponse
,
UpdateUserInfoParams
,
UserInfo
,
}
from
'@/types/user'
;
import
{
getToken
}
from
'@/utils/auth'
;
import
{
get
,
post
}
from
'@/utils/request'
;
import
{
post
}
from
'@/utils/request'
;
import
gscPost
from
'@/config/gscrequest'
;
// 数据看板指标统计
export
function
getdataBoard
(
data
:
any
)
{
return
gscPost
(
'/dataBoard/indexs'
,
data
);
}
// ==================== 开发环境使用模拟 API ====================
// 取消下面的注释以使用模拟 API 进行开发测试
// 测试账号:admin/123456, user/123456, guest/123456
import
{
mockGetUserInfo
,
mockLogin
,
mockLogout
}
from
'./mock'
;
import
{
mockLogout
}
from
'./mock'
;
const
USE_MOCK_API
=
true
;
// 开发时设置为 true,生产环境设置为 false
...
...
@@ -38,8 +33,12 @@ export const login = (data: LoginParams) => {
export
const
getPublicKey
=
(
data
:
any
)
=>
{
return
gscPost
(
'/login/publicKey'
,
data
,{
returnAll
:
true
});
};
/**
* 获取当前用户信息
*/
export
const
getUserInfo
=
()
=>
{
return
gscPost
(
'/login/currLoginUser'
,
{},
{
returnAll
:
true
});
};
/**
* 用户登出
*/
...
...
@@ -50,16 +49,6 @@ export const logout = () => {
return
post
<
ApiResponse
<
void
>>
(
'/auth/logout'
);
};
/**
* 获取用户信息
*/
export
const
getUserInfo
=
()
=>
{
if
(
USE_MOCK_API
)
{
const
token
=
getToken
()
||
''
;
return
mockGetUserInfo
(
token
);
}
return
get
<
ApiResponse
<
UserInfo
>>
(
'/user/info'
);
};
/**
* 刷新 Token
...
...
apps/frontend/venus-agentic/venus-agentic-base/src/config/center.ts
View file @
4783f1c
...
...
@@ -41,6 +41,39 @@ export function getGscApi(): null | Request {
}
/**
* 方案2:更新 GSC API 实例的 Authorization header
* 如果 Request 类支持更新 headers,可以使用此方法
* @param token 访问令牌
*/
export
function
updateGscApiAuth
(
token
:
string
|
null
):
void
{
if
(
!
gscApiInstance
)
{
console
.
warn
(
'[配置中心] GSC API 实例未初始化,无法更新 Authorization'
);
return
;
}
// 尝试更新 headers(如果 Request 类支持)
// 注意:需要根据 glsk-toolkit 的 Request 类实际 API 调整
try
{
if
(
gscApiInstance
.
headers
)
{
// 如果支持直接更新 headers
gscApiInstance
.
headers
.
Authorization
=
token
?
`Bearer
${
token
}
`
:
''
;
}
else
if
(
gscApiInstance
.
setHeader
)
{
// 如果支持 setHeader 方法
gscApiInstance
.
setHeader
(
'Authorization'
,
token
?
`Bearer
${
token
}
`
:
''
);
}
else
if
(
gscApiInstance
.
updateHeaders
)
{
// 如果支持 updateHeaders 方法
gscApiInstance
.
updateHeaders
({
Authorization
:
token
?
`Bearer
${
token
}
`
:
''
,
});
}
else
{
console
.
warn
(
'[配置中心] Request 实例不支持动态更新 headers'
);
}
}
catch
(
error
)
{
console
.
error
(
'[配置中心] 更新 Authorization 失败:'
,
error
);
}
}
/**
* 等待配置加载完成
* @returns Promise<void>
*/
...
...
@@ -78,7 +111,7 @@ export async function fetchConfig(): Promise<any> {
sessionId
:
'd5629aee-28c7-4def-a8fa-95d76c978dc7'
,
},
headers
:
{
'Authorization'
:
'
Bearer global-token
'
,
'Authorization'
:
''
,
'X-App-Version'
:
'1.0.0'
},
events
:
{
...
...
apps/frontend/venus-agentic/venus-agentic-base/src/config/gscrequest.ts
View file @
4783f1c
...
...
@@ -2,8 +2,13 @@
* GSC 请求封装
*/
import
{
getGscApi
}
from
'./center'
;
import
{
getToken
}
from
'@/utils/auth'
;
export
const
gscPost
=
(
url
:
string
,
data
:
any
,
_config
=
{})
=>
{
/**
* 方案1:在每次请求时动态添加 token(推荐)
* 优点:简单直接,每次请求都使用最新的 token
*/
export
const
gscPost
=
(
url
:
string
,
data
:
any
,
_config
:
any
=
{})
=>
{
const
gscApi
=
getGscApi
();
if
(
!
gscApi
)
{
...
...
@@ -14,8 +19,18 @@ export const gscPost = (url: string, data: any, _config = {}) => {
return
Promise
.
reject
(
error
);
}
// 动态获取 token 并添加到请求配置中
const
token
=
getToken
();
const
configWithAuth
=
{
...
_config
,
headers
:
{
...(
_config
.
headers
||
{}),
...(
token
?
{
Authorization
:
`
${
token
}
`
}
:
{}),
},
};
console
.
log
(
'[GSC请求] 发起请求:'
,
url
,
data
);
return
gscApi
.
post
(
url
,
data
,
_config
);
return
gscApi
.
post
(
url
,
data
,
configWithAuth
);
};
// 默认导出
...
...
apps/frontend/venus-agentic/venus-agentic-base/src/layouts/BasicLayout.vue
View file @
4783f1c
...
...
@@ -204,11 +204,11 @@ watch(
<Breadcrumb
:breadcrumbs=
"breadcrumbs"
/>
</div>
<div
class=
"header-right"
>
<div
class=
"top-tools"
>
<
!--
<
div
class=
"top-tools"
>
<el-icon
size=
"16"
style=
"margin-right: 6px"
><Download
/></el-icon>
<span>
下载中心
</span>
</div>
<
NotificationCenter
/
>
</div>
-->
<
!--
<NotificationCenter
/>
--
>
<UserInfo
/>
</div>
</div>
...
...
apps/frontend/venus-agentic/venus-agentic-base/src/layouts/components/UserInfo.vue
View file @
4783f1c
<
script
setup
lang=
"ts"
>
import
{
onMounted
,
onUnmounted
,
ref
}
from
'vue'
;
import
{
computed
,
onMounted
,
onUnmounted
,
ref
}
from
'vue'
;
import
{
useRouter
}
from
'vue-router'
;
import
{
useUserStore
}
from
'@/stores'
;
...
...
@@ -10,6 +10,22 @@ const userStore = useUserStore();
// 下拉菜单显示状态
const
showDropdown
=
ref
(
false
);
// 获取用户名首字母(英文字母转为大写)
const
userInitial
=
computed
(()
=>
{
const
userName
=
userStore
.
userName
||
''
;
if
(
!
userName
)
return
''
;
// 获取第一个字符
const
firstChar
=
userName
.
charAt
(
0
);
// 如果是英文字母,转换为大写;否则直接返回
if
(
/
[
a-zA-Z
]
/
.
test
(
firstChar
))
{
return
firstChar
.
toUpperCase
();
}
return
firstChar
;
});
// 确认对话框显示状态
const
showConfirmDialog
=
ref
(
false
);
...
...
@@ -81,7 +97,7 @@ onUnmounted(() => {
<
template
>
<div
class=
"user-info"
v-if=
"userStore.isLoggedIn"
>
<div
class=
"user-info-card"
@
click
.
stop=
"toggleDropdown"
>
<div
class=
"avatar"
></div>
<div
class=
"avatar"
>
{{
userInitial
}}
</div>
<p
class=
"name"
>
{{
userStore
.
userName
}}
</p>
</div>
...
...
@@ -227,6 +243,11 @@ onUnmounted(() => {
background
:
#e6efff
;
border-radius
:
50%
;
opacity
:
1
;
color
:
#1956fe
;
font-size
:
16px
;
font-weight
:
Bold
;
text-align
:
center
;
line-height
:
28px
;
}
.user-info-card
.name
{
...
...
apps/frontend/venus-agentic/venus-agentic-base/src/stores/user.ts
View file @
4783f1c
...
...
@@ -2,8 +2,6 @@ import type { LoginParams, UserInfo } from '@/types/user';
import
{
computed
,
ref
}
from
'vue'
;
import
{
ElMessage
}
from
'element-plus'
;
import
{
getUserInfo
as
getUserInfoApi
,
login
as
loginApi
,
...
...
@@ -11,6 +9,8 @@ import {
}
from
'@/api/user'
;
import
{
removeToken
,
setToken
}
from
'@/utils/auth'
;
import
{
defineStore
}
from
'pinia'
;
// 可选:如果使用方案2,需要导入此函数
// import { updateGscApiAuth } from '@/config/center';
/**
* 用户状态管理
...
...
@@ -24,7 +24,7 @@ export const useUserStore = defineStore('user', () => {
// 计算属性
const
isLoggedIn
=
computed
(()
=>
!!
token
.
value
);
const
userName
=
computed
(()
=>
userInfo
.
value
?.
name
||
''
);
const
userName
=
computed
(()
=>
userInfo
.
value
?.
user
name
||
''
);
const
userAvatar
=
computed
(()
=>
userInfo
.
value
?.
avatar
||
''
);
const
userId
=
computed
(()
=>
userInfo
.
value
?.
id
||
''
);
...
...
@@ -40,12 +40,32 @@ export const useUserStore = defineStore('user', () => {
captchaKey
:
loginParams
.
captchaKey
,
};
const
response
=
await
loginApi
(
requestData
);
let
{
data
:
accessToken
}
=
response
.
data
;
token
.
value
=
accessToken
;
setToken
(
accessToken
);
return
response
||
response
.
data
;
let
{
code
,
data
:
accessToken
,
msg
}
=
response
.
data
;
// 只有返回 200 状态码(code === 0 表示成功)时才继续处理
if
(
code
===
0
&&
accessToken
)
{
token
.
value
=
accessToken
;
setToken
(
accessToken
);
// 可选:如果使用方案2,同步更新 GSC API 的 Authorization header
// updateGscApiAuth(accessToken);
// 登录成功后,自动调用 getUserInfo 获取用户信息并缓存
try
{
await
getUserInfo
();
}
catch
(
error
:
any
)
{
console
.
error
(
'获取用户信息失败:'
,
error
);
// 即使获取用户信息失败,登录流程也继续,返回登录响应
}
return
response
||
response
.
data
;
}
else
{
// 登录失败
throw
new
Error
(
msg
||
'登录失败'
);
}
}
catch
(
error
:
any
)
{
console
.
error
(
'登录失败:'
,
error
);
throw
error
;
}
};
...
...
@@ -65,6 +85,10 @@ export const useUserStore = defineStore('user', () => {
permissions
.
value
=
[];
roles
.
value
=
[];
removeToken
();
// 可选:如果使用方案2,清空 GSC API 的 Authorization header
// updateGscApiAuth(null);
console
.
log
(
'退出'
);
// 同步清空 qiankun 全局状态中的用户信息
syncUserToQiankun
();
...
...
@@ -76,17 +100,24 @@ export const useUserStore = defineStore('user', () => {
*/
const
getUserInfo
=
async
()
=>
{
try
{
// 调用 getUserInfo API,传空对象作为参数
const
response
=
await
getUserInfoApi
();
const
user
=
response
.
data
;
userInfo
.
value
=
user
;
roles
.
value
=
user
.
roles
||
[];
permissions
.
value
=
user
.
permissions
||
[];
// 同步用户信息到 qiankun 全局状态
syncUserToQiankun
();
return
{
success
:
true
,
data
:
user
};
// 根据实际 API 响应结构获取用户信息
const
user
=
response
?.
data
?.
data
;
if
(
user
)
{
userInfo
.
value
=
user
;
roles
.
value
=
user
.
roles
||
[];
permissions
.
value
=
user
.
permissions
||
[];
// 同步用户信息到 qiankun 全局状态
syncUserToQiankun
();
return
{
success
:
true
,
data
:
user
};
}
else
{
throw
new
Error
(
'用户信息为空'
);
}
}
catch
(
error
:
any
)
{
console
.
error
(
'获取用户信息失败:'
,
error
);
return
{
success
:
false
,
message
:
error
.
message
||
'获取用户信息失败'
};
...
...
apps/frontend/venus-agentic/venus-agentic-base/src/views/Login.vue
View file @
4783f1c
...
...
@@ -5,7 +5,7 @@ import { useRoute, useRouter } from 'vue-router';
import
{
GLInput
,
GLButton
}
from
'@venus/common-ui-vue'
;
import
{
getCaptcha
}
from
'@/api/user'
;
import
{
useUserStore
}
from
'@/stores'
;
import
{
El
Button
,
ElCheckbox
,
ElInput
}
from
'element-plus'
;
import
{
El
Checkbox
}
from
'element-plus'
;
import
JSEncrypt
from
'jsencrypt'
;
import
{
getPublicKey
}
from
'@/api/user'
;
const
router
=
useRouter
();
...
...
@@ -70,17 +70,28 @@ const handleLogin = async () => {
try
{
// 调用登录接口
// const publicKey = await getPublicKey({});
// const encryptedPassword = rsaEncrypt(loginForm?.password, publicKey);
// loginForm.password = encryptedPassword;
const
result
=
await
userStore
.
login
(
loginForm
);
console
.
log
(
'userStore'
,
result
);
let
{
code
,
msg
}
=
result
.
data
;
if
(
code
!==
0
)
{
const
redirect
=
(
route
.
query
.
redirect
as
string
)
||
'/home'
;
router
.
push
(
redirect
);
}
else
{
ElMessage
.
error
(
msg
||
'登录失败'
);
const
publicKey
=
await
getPublicKey
({});
const
encryptedPassword
=
rsaEncrypt
(
loginForm
?.
password
,
publicKey
?.
data
?.
data
);
let
requestData
=
{
username
:
loginForm
.
username
,
password
:
encryptedPassword
,
captcha
:
loginForm
.
captcha
,
captchaKey
:
loginForm
.
captchaKey
,
};
try
{
const
result
=
await
userStore
.
login
(
requestData
);
let
{
code
,
msg
}
=
result
.
data
;
if
(
code
==
0
)
{
// 登录成功,getUserInfo 已在 login 方法中自动调用
ElMessage
.
success
(
'登录成功'
);
const
redirect
=
(
route
.
query
.
redirect
as
string
)
||
'/home'
;
router
.
push
(
redirect
);
}
else
{
ElMessage
.
error
(
msg
||
'登录失败'
);
refreshCaptcha
();
}
}
catch
(
error
:
any
)
{
ElMessage
.
error
(
error
.
message
||
'登录失败'
);
refreshCaptcha
();
}
}
catch
(
error
:
any
)
{
...
...
@@ -89,6 +100,7 @@ const handleLogin = async () => {
}
};
const
rsaEncrypt
=
(
data
:
any
,
publicKeyBase64
:
any
)
=>
{
console
.
log
(
'publicKeyBase64'
,
publicKeyBase64
);
try
{
const
encrypt
=
new
JSEncrypt
();
// 将Base64公钥转换为PEM格式
...
...
Write
Preview
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