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
86c33e1f
authored
Oct 02, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【功能优化】WebSocket 使用 refreshToken 认证,解决无法刷新访问令牌的问题
parent
40512afb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
src/views/infra/webSocket/index.vue
+4
-2
src/views/mall/promotion/kefu/index.vue
+4
-2
No files found.
src/views/infra/webSocket/index.vue
View file @
86c33e1f
...
...
@@ -71,7 +71,7 @@
<
script
lang=
"ts"
setup
>
import
{
formatDate
}
from
'@/utils/formatTime'
import
{
useWebSocket
}
from
'@vueuse/core'
import
{
get
Access
Token
}
from
'@/utils/auth'
import
{
get
Refresh
Token
}
from
'@/utils/auth'
import
*
as
UserApi
from
'@/api/system/user'
defineOptions
({
name
:
'InfraWebSocket'
})
...
...
@@ -79,7 +79,9 @@ defineOptions({ name: 'InfraWebSocket' })
const
message
=
useMessage
()
// 消息弹窗
const
server
=
ref
(
(
import
.
meta
.
env
.
VITE_BASE_URL
+
'/infra/ws'
).
replace
(
'http'
,
'ws'
)
+
'?token='
+
getAccessToken
()
(
import
.
meta
.
env
.
VITE_BASE_URL
+
'/infra/ws'
).
replace
(
'http'
,
'ws'
)
+
'?token='
+
getRefreshToken
()
// 使用 getRefreshToken() 方法,而不使用 getAccessToken() 方法的原因:WebSocket 无法方便的刷新访问令牌
)
// WebSocket 服务地址
const
getIsOpen
=
computed
(()
=>
status
.
value
===
'OPEN'
)
// WebSocket 连接是否打开
const
getTagColor
=
computed
(()
=>
(
getIsOpen
.
value
?
'success'
:
'red'
))
// WebSocket 连接的展示颜色
...
...
src/views/mall/promotion/kefu/index.vue
View file @
86c33e1f
...
...
@@ -25,7 +25,7 @@
import
{
KeFuConversationList
,
KeFuMessageList
,
MemberBrowsingHistory
}
from
'./components'
import
{
WebSocketMessageTypeConstants
}
from
'./components/tools/constants'
import
{
KeFuConversationRespVO
}
from
'@/api/mall/promotion/kefu/conversation'
import
{
get
Access
Token
}
from
'@/utils/auth'
import
{
get
Refresh
Token
}
from
'@/utils/auth'
import
{
useWebSocket
}
from
'@vueuse/core'
defineOptions
({
name
:
'KeFu'
})
...
...
@@ -34,7 +34,9 @@ const message = useMessage() // 消息弹窗
// ======================= WebSocket start =======================
const
server
=
ref
(
(
import
.
meta
.
env
.
VITE_BASE_URL
+
'/infra/ws'
).
replace
(
'http'
,
'ws'
)
+
'?token='
+
getAccessToken
()
(
import
.
meta
.
env
.
VITE_BASE_URL
+
'/infra/ws'
).
replace
(
'http'
,
'ws'
)
+
'?token='
+
getRefreshToken
()
// 使用 getRefreshToken() 方法,而不使用 getAccessToken() 方法的原因:WebSocket 无法方便的刷新访问令牌
)
// WebSocket 服务地址
/** 发起 WebSocket 连接 */
...
...
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