Commit e54babf2 authored by neogcg's avatar neogcg

3/10

parent 3d429703
......@@ -11,8 +11,7 @@ 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
......
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
......@@ -11,8 +11,8 @@ const port = process.env.port || process.env.npm_config_port || 8886 // dev port
const rewriteDefaultConfig = {
changeOrigin: true,
target: 'http://8.142.143.40:8886',
// target: 'http://192.168.0.111:8886',
// target: 'http://8.142.143.40:8886',
target: 'http://192.168.0.111:8886',
// ws: true,
headers: {
referer: 'laddercloud.cn'
......
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