Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
O
on-site-service-admin-view
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
external
on-site-service-admin-view
Commits
a5fba3c8
Commit
a5fba3c8
authored
Jul 21, 2022
by
shangtx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 支付成功websocket通知
parent
931e67ee
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
7 deletions
+105
-7
.env.development
.env.development
+2
-1
user.js
src/store/modules/user.js
+13
-5
websocket.js
src/util/websocket.js
+90
-0
Login.vue
src/views/system/Login.vue
+0
-1
No files found.
.env.development
View file @
a5fba3c8
VUE_APP_URL = 'http://localhost:8297/'
VUE_APP_URL = 'http://localhost:8297/'
VUE_APP_WEBSOCKET = 'ws://localhost:8297/websocket'
\ No newline at end of file
src/store/modules/user.js
View file @
a5fba3c8
import
Vue
from
'vue'
import
Vue
from
'vue'
import
{
getInfo
,
login
}
from
"@/api/common/login"
import
{
getInfo
,
login
}
from
"@/api/common/login"
import
{
ACCESS_TOKEN
,
BEARER
}
from
"@/store/mutation-types"
import
{
ACCESS_TOKEN
,
BEARER
}
from
"@/store/mutation-types"
import
SocketService
from
'@/util/websocket'
const
user
=
{
const
user
=
{
state
:
{
state
:
{
...
@@ -12,6 +13,7 @@ const user = {
...
@@ -12,6 +13,7 @@ const user = {
roles
:
[],
roles
:
[],
info
:
{},
info
:
{},
buttons
:
null
,
buttons
:
null
,
websocket
:
null
,
},
},
mutations
:
{
mutations
:
{
...
@@ -33,11 +35,14 @@ const user = {
...
@@ -33,11 +35,14 @@ const user = {
SET_BUTTONS
:
(
state
,
buttons
)
=>
{
SET_BUTTONS
:
(
state
,
buttons
)
=>
{
state
.
buttons
=
buttons
state
.
buttons
=
buttons
},
},
SET_WEBSOCKET
:
(
state
,
websocket
)
=>
{
state
.
websocket
=
websocket
}
},
},
actions
:
{
actions
:
{
// 登录
// 登录
Login
({
commit
},
userInfo
)
{
Login
({
commit
},
userInfo
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
login
(
userInfo
).
then
(
response
=>
{
login
(
userInfo
).
then
(
response
=>
{
if
(
response
.
code
==
SYS_CONST
.
REQUEST
.
SUCCEED
)
{
if
(
response
.
code
==
SYS_CONST
.
REQUEST
.
SUCCEED
)
{
...
@@ -57,7 +62,7 @@ const user = {
...
@@ -57,7 +62,7 @@ const user = {
})
})
},
},
// 获取用户信息
// 获取用户信息
GetInfo
({
commit
})
{
GetInfo
({
commit
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
getInfo
().
then
(
response
=>
{
getInfo
().
then
(
response
=>
{
let
data
=
response
.
data
;
let
data
=
response
.
data
;
...
@@ -74,6 +79,9 @@ const user = {
...
@@ -74,6 +79,9 @@ const user = {
commit
(
'SET_AVATAR'
,
data
.
userInfo
.
avatar
);
commit
(
'SET_AVATAR'
,
data
.
userInfo
.
avatar
);
commit
(
'SET_BUTTONS'
,
buttonAuthList
);
commit
(
'SET_BUTTONS'
,
buttonAuthList
);
SocketService
.
init
(
data
.
userInfo
.
id
)
resolve
(
response
)
resolve
(
response
)
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
reject
(
error
)
reject
(
error
)
...
@@ -82,7 +90,7 @@ const user = {
...
@@ -82,7 +90,7 @@ const user = {
},
},
// 登出
// 登出
Logout
({
commit
})
{
Logout
({
commit
})
{
return
new
Promise
((
resolve
)
=>
{
return
new
Promise
((
resolve
)
=>
{
commit
(
'SET_TOKEN'
,
''
);
commit
(
'SET_TOKEN'
,
''
);
commit
(
'SET_ROLES'
,
[]);
commit
(
'SET_ROLES'
,
[]);
...
...
src/util/websocket.js
0 → 100644
View file @
a5fba3c8
import
store
from
'@/store'
import
{
notification
}
from
'ant-design-vue'
export
default
class
SocketService
{
static
webSocket
=
null
static
reConnectTimeout
=
1000
static
init
(
userId
)
{
const
ws
=
new
WebSocket
(
`
${
process
.
env
.
VUE_APP_WEBSOCKET
}
?userId=
${
userId
}
`
)
this
.
reConnectTimeout
=
1000
ws
.
onmessage
=
this
.
onmessage
ws
.
onerror
=
this
.
onerror
ws
.
onclose
=
this
.
onclose
ws
.
onopen
=
this
.
onopen
this
.
webSocket
=
ws
store
.
commit
(
'SET_WEBSOCKET'
,
ws
)
return
ws
}
static
onclose
()
{
console
.
info
(
'连接关闭'
)
}
static
onopen
()
{
console
.
info
(
'连接建立'
)
}
static
onerror
()
{
console
.
info
(
'连接发生错误'
)
store
.
commit
(
'SET_WEBSOCKET'
,
null
)
}
static
reconnect
()
{
this
.
webSocket
=
null
setTimeout
(()
=>
{
console
.
info
(
'reconnect at '
,
new
Date
())
this
.
init
(
store
.
getters
.
userInfo
.
id
)
this
.
reConnectTimeout
=
this
.
reConnectTimeout
+
5000
},
this
.
reConnectTimeout
)
}
static
onmessage
(
e
)
{
console
.
info
(
'from server'
,
e
)
const
{
data
}
=
e
if
(
data
==
1
)
{
notification
.
open
({
message
:
'消息提醒'
,
description
:
'用户已支付,请派单'
,
key
:
'orderNotification'
,
btn
:
h
=>
{
return
h
(
'a-button'
,
{
props
:
{
type
:
'primary'
,
size
:
'small'
,
},
on
:
{
click
:
()
=>
this
.
$notification
.
close
(
'orderNotification'
),
},
},
'确定'
,
);
},
});
}
}
}
// 心跳检测
// eslint-disable-next-line no-unused-vars
const
heartCheck
=
{
interval
:
60000
,
intervalObj
:
null
,
start
:
function
()
{
console
.
log
(
'start heart check'
);
this
.
intervalObj
&&
clearInterval
(
this
.
intervalObj
);
this
.
intervalObj
=
setInterval
(
function
()
{
//发送测试信息,后端收到后,返回一个消息,
console
.
info
(
'heart beat check'
)
SocketService
.
webSocket
.
send
(
'hello'
);
},
this
.
interval
)
}
}
\ No newline at end of file
src/views/system/Login.vue
View file @
a5fba3c8
...
@@ -180,7 +180,6 @@ export default {
...
@@ -180,7 +180,6 @@ export default {
this
.
$store
this
.
$store
.
dispatch
(
"GenerateRoutes"
,
initRouterTree
(
menuList
))
.
dispatch
(
"GenerateRoutes"
,
initRouterTree
(
menuList
))
.
then
(()
=>
{
.
then
(()
=>
{
console
.
info
(
'this.$store.getters.addRouters'
,
this
.
$store
.
getters
.
addRouters
)
this
.
$router
.
addRoutes
(
this
.
$store
.
getters
.
addRouters
);
this
.
$router
.
addRoutes
(
this
.
$store
.
getters
.
addRouters
);
let
redirectPath
=
this
.
$route
.
query
.
redirect
;
let
redirectPath
=
this
.
$route
.
query
.
redirect
;
if
(
redirectPath
)
{
if
(
redirectPath
)
{
...
...
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