|
@@ -162,7 +162,8 @@
|
|
|
noticeNumber,
|
|
|
queryCircularManagementReceiveList,
|
|
|
getStaffHomeShowList,
|
|
|
- gChartsData
|
|
|
+ gChartsData,
|
|
|
+ getAdminId
|
|
|
} from '@/model/home/index'
|
|
|
import {
|
|
|
getUserVesselList,
|
|
@@ -327,6 +328,19 @@
|
|
|
},
|
|
|
|
|
|
},
|
|
|
+ activated(){
|
|
|
+ if ('WebSocket' in window) {
|
|
|
+ if (process.env.NODE_ENV === 'production') {
|
|
|
+ this.websocket = new WebSocket('wss://www.zthymaoyi.com/wss/websocket/?adminId=84f62127b7384dcdbaeaddfe460329fc' )
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.websocket = new WebSocket('ws://localhost:8080/websocket/?adminId=84f62127b7384dcdbaeaddfe460329fc' )
|
|
|
+ }
|
|
|
+ this.initWebSocket()
|
|
|
+ } else {
|
|
|
+ alert('当前浏览器不支持websocket')
|
|
|
+ }
|
|
|
+ },
|
|
|
async created() {
|
|
|
//获取快捷路口列表
|
|
|
this.getRouteList()
|
|
@@ -342,6 +356,22 @@
|
|
|
}
|
|
|
},
|
|
|
async mounted() {
|
|
|
+ // getAdminId().toPromise().then(response => {
|
|
|
+ this.loading = false
|
|
|
+ // WebSocket
|
|
|
+ // this.$store.dispatch('setAdminId', response.data.data)
|
|
|
+ if ('WebSocket' in window) {
|
|
|
+ if (process.env.NODE_ENV === 'production') {
|
|
|
+ this.websocket = new WebSocket('wss://www.zthymaoyi.com/wss/websocket/84f62127b7384dcdbaeaddfe460329fc' )
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.websocket = new WebSocket('ws://192.168.1.115:8090/websocket/1' )
|
|
|
+ }
|
|
|
+ this.initWebSocket()
|
|
|
+ } else {
|
|
|
+ alert('当前浏览器不支持websocket')
|
|
|
+ }
|
|
|
+ // })
|
|
|
let that = this
|
|
|
this.getChartsData()
|
|
|
// this.timer = setInterval(function(){
|
|
@@ -416,6 +446,53 @@
|
|
|
this.number.news = news
|
|
|
})
|
|
|
},
|
|
|
+ initWebSocket () {
|
|
|
+ console.log(this.webSocket,this.WebSocket)
|
|
|
+ // 连接错误
|
|
|
+ this.websocket.onerror = this.setErrorMessage
|
|
|
+ // 连接成功
|
|
|
+ this.websocket.onopen = this.setOnopenMessage
|
|
|
+
|
|
|
+ // 收到消息的回调
|
|
|
+ this.websocket.onmessage = this.setOnmessageMessage
|
|
|
+
|
|
|
+ // 连接关闭的回调
|
|
|
+ this.websocket.onclose = this.setOncloseMessage
|
|
|
+
|
|
|
+ // 监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
|
|
|
+ window.onbeforeunload = this.onbeforeunload
|
|
|
+ },
|
|
|
+ setErrorMessage () {
|
|
|
+ console.log(11111111)
|
|
|
+ console.log('WebSocket连接发生错误 状态码:' + this.websocket.readyState)
|
|
|
+ },
|
|
|
+ setOnopenMessage () {
|
|
|
+ console.log(222222222)
|
|
|
+ console.log('WebSocket连接成功 状态码:' + this.websocket.readyState)
|
|
|
+ },
|
|
|
+ setOnmessageMessage (event) {
|
|
|
+ console.log(3333)
|
|
|
+ // 根据服务器推送的消息做自己的业务处理
|
|
|
+ console.log('服务端返回:' + event.data)
|
|
|
+ var msg = event.data.split('$')
|
|
|
+ var that = this
|
|
|
+ this.$notify.warning({
|
|
|
+ title: '新消息提醒',
|
|
|
+ message: msg[0],
|
|
|
+ duration: 0,
|
|
|
+ onClick() {
|
|
|
+ that.$router.push({
|
|
|
+ path: msg[1] }) // 你要跳转的路由 还可以传参 当然也可以通过其他方式跳转
|
|
|
+ }
|
|
|
+ })
|
|
|
+ var currentPage = that.$router.history.current.path
|
|
|
+ that.$router.push({ path: '/' })
|
|
|
+ that.$router.push({ path: currentPage })
|
|
|
+ },
|
|
|
+ setOncloseMessage () {
|
|
|
+ debugger
|
|
|
+ console.log('WebSocket连接关闭 状态码:' + this.websocket.readyState)
|
|
|
+ },
|
|
|
//跳转
|
|
|
contract(index){
|
|
|
if(index == 0){
|