Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
W
web-monitor
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
Administrator
web-monitor
Commits
3d429703
Commit
3d429703
authored
Mar 10, 2022
by
neogcg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alarm dialog
parent
3498673b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
1 deletion
+49
-1
main.js
src/main.js
+2
-0
index.js
src/store/index.js
+2
-1
websocket.js
src/utils/websocket.js
+45
-0
No files found.
src/main.js
View file @
3d429703
...
...
@@ -11,6 +11,8 @@ import '@/icons' // icon
import
'@/permission'
// permission control
import
performLoader
from
'@/utils/global_main_loader.js'
import
WS
from
'@/util/websocket'
Vue
.
prototype
.
$ws
=
WS
Vue
.
use
(
ElementUI
,
{
locale
})
performLoader
(
Vue
)
// 所有的第三方插件性质的东西都放到这里面了
Vue
.
config
.
productionTip
=
false
...
...
src/store/index.js
View file @
3d429703
...
...
@@ -10,12 +10,13 @@ import depart from './modules/depart'
Vue
.
use
(
Vuex
)
const
store
=
new
Vuex
.
Store
({
modules
:
{
app
,
settings
,
user
,
depart
,
},
getters
})
...
...
src/utils/websocket.js
0 → 100644
View file @
3d429703
import
store
from
'../store'
const
WS
=
{
$ws
:
null
,
// webscoket实例
wsUrl
:
'ws://192.168.0.111:8885/websocket/1'
,
// websocket链接地址
createWS
:
function
()
{
if
(
'WebSocket'
in
window
)
{
this
.
$ws
=
new
WebSocket
(
wsURl
)
this
.
$ws
.
onopen
=
this
.
wsOpen
this
.
$ws
.
onmessage
=
this
.
wsMessage
this
.
$ws
.
onerror
=
this
.
wsError
this
.
$ws
.
onclose
=
this
.
wsClose
}
else
{
alert
(
'当前浏览器不支持webSocket'
)
}
},
wsOpen
:
function
()
{
this
.
$ws
.
send
(
'连接成功'
)
console
.
log
(
'== websocket open =='
)
heartBeat
.
start
()
},
wsMessage
:
function
(
msg
)
{
console
.
log
(
'== websocket message =='
,
msg
)
heartBeat
.
reset
()
store
.
commit
(
'SET_WS_MSG'
,
msg
.
data
)
},
wsError
:
function
(
err
)
{
console
.
log
(
'== websocket error =='
,
err
)
},
wsClose
:
function
(
event
)
{
console
.
log
(
'== websocket close =='
,
event
)
}
}
const
heartBeat
=
{
timeout
:
30000
,
// 心跳重连时间
timeoutObj
:
null
,
// 定时器
reset
:
function
()
{
clearInterVal
(
this
.
timeoutObj
)
console
.
log
(
'websocket 心跳'
)
WS
.
start
()
},
start
:
function
()
{
this
.
timeoutObj
=
setTimeout
(
function
()
{
if
(
WS
.
$ws
.
readyState
===
1
)
{
WS
.
$ws
.
send
(
'HeartBeat'
)
}
},
this
.
timeout
)
}
}
export
default
WS
\ No newline at end of file
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