Ver código fonte

小航同学优化

wyh 2 anos atrás
pai
commit
a1d2a6c420
1 arquivos alterados com 69 adições e 0 exclusões
  1. 69 0
      itdmWeb/src/views/dashboard/IndexBdc.vue

+ 69 - 0
itdmWeb/src/views/dashboard/IndexBdc.vue

@@ -249,6 +249,12 @@ import ItdmTaskList from '../module-iTDM/itdmFirstPage/ItdmTaskList.vue'
     },
     data() {
       return {
+
+        // path: 'ws://127.0.0.1:8080/itdmServer/itdmWebsocket/list2',
+        path: 'ws://192.168.2.244:8080/itdmServer/itdmWebsocket/list3',
+        socket: '',
+
+
         loading: true,
         loading2: false,
         listBdc: {},
@@ -339,6 +345,8 @@ import ItdmTaskList from '../module-iTDM/itdmFirstPage/ItdmTaskList.vue'
       }
     },
     created() {
+      this.init()
+
       this.getListBdc()
       this.zhengchang()
       // this.loadDataSource1()
@@ -347,6 +355,10 @@ import ItdmTaskList from '../module-iTDM/itdmFirstPage/ItdmTaskList.vue'
         this.loading = !this.loading
       }, 1000)
     },
+    destroyed () {
+      // 销毁监听
+      this.socket.close()
+    },
     methods:{
       // 获取首页数据
       getListBdc(){
@@ -439,6 +451,63 @@ import ItdmTaskList from '../module-iTDM/itdmFirstPage/ItdmTaskList.vue'
           }
           return item.type==this.indexRegisterType
         })
+      },
+
+
+      // websocket
+      init: function () {
+        if(typeof(WebSocket) === "undefined"){
+            alert("您的浏览器不支持socket")
+        }else{
+          // 实例化socket
+          this.socket = new WebSocket(this.path)
+          // 监听socket连接
+          this.socket.onopen = this.open
+          // 监听socket错误信息
+          this.socket.onerror = this.error
+          // 监听socket消息
+          this.socket.onmessage = this.getMessage
+          // 监听销毁
+          this.socket.onclose = this.close
+        }
+      },
+      open: function () {
+          console.log("socket连接成功")
+      },
+      error: function () {
+          console.log("连接错误")
+      },
+      getMessage: function (msg) {
+        // console.log(msg.data,JSON.parse(msg.data))
+        // console.log(JSON.parse(msg.data).length)
+        var wsData = JSON.parse(msg.data)
+        console.log(wsData)
+        for (var i = 0; i < wsData.length; i++) {
+          console.log(11111122222,wsData[i].name)
+          if (wsData[i].name == '打开大屏') {
+            console.log('打开大屏',wsData[i].data)
+
+            // let routeDate = this.$router.resolve({path: '/itdmScreen/itdmScreenIndex'})
+            // window.open(routerDate.href,'_blank')
+            // this.$router.push({path: '/itdmScreen/itdmScreenIndex'})
+            if (wsData[i].data == 1) {
+              let routeData = this.$router.resolve({
+              path: '/itdmScreen/itdmScreenIndex',
+              name: 'itdmScreen',
+              component: () => import(/* webpackChunkName: "user" */ '@/views/module-iTDM/itdmScreen/itdmScreenIndex.vue')
+              });
+              window.open(routeData.href, '_blank');
+              
+            }
+
+            // let routeData = this.$router.resolve({
+            // path: '/itdmScreen/itdmScreenIndex',
+            // name: 'itdmScreen',
+            // component: () => import(/* webpackChunkName: "user" */ '@/views/module-iTDM/itdmScreen/itdmScreenIndex.vue')
+            // });
+            // window.open(routeData.href, '_blank');
+          }
+        }
       }
     }
   }