Commit 3d429703 authored by neogcg's avatar neogcg

alarm dialog

parent 3498673b
......@@ -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
......
......@@ -10,12 +10,13 @@ import depart from './modules/depart'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
app,
settings,
user,
depart,
},
getters
})
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment