App.vue 2.35 KB
Newer Older
Pan's avatar
Pan committed
1 2
<template>
  <div id="app">
花裤衩's avatar
花裤衩 committed
3
    <router-view />
neogcg's avatar
neogcg committed
4 5 6 7 8 9 10 11
    <audio
      controls="controls"
      id="my_audio"
      src="./assets/audio/alarm.mp3"
      style="display: none"
      hidden="hidden"
    />
    <!-- <div class="tips" v-if="tflag">
yanzhongrong's avatar
yanzhongrong committed
12 13
      <p>提示</p>
      <span>有一条新告警</span>
neogcg's avatar
neogcg committed
14
    </div> -->
Pan's avatar
Pan committed
15 16 17 18
  </div>
</template>

<script>
neogcg's avatar
neogcg committed
19 20 21 22
import { receiveMessage } from "@/utils/websocket";
import socket from "@/utils/websocket";
import { mapState } from "vuex";
import EventBus from "@/utils/bus";
Pan's avatar
Pan committed
23
export default {
neogcg's avatar
neogcg committed
24
  name: "App",
yanzhongrong's avatar
yanzhongrong committed
25
  data() {
neogcg's avatar
neogcg committed
26
    return {
yanzhongrong's avatar
yanzhongrong committed
27 28
      websocket: null,
      tflag: false,
neogcg's avatar
neogcg committed
29
    };
yanzhongrong's avatar
yanzhongrong committed
30 31
  },
  computed: {
neogcg's avatar
neogcg committed
32
    ...mapState("user", ["userBaseInfo", "token"]),
yanzhongrong's avatar
yanzhongrong committed
33
    userId() {
neogcg's avatar
neogcg committed
34 35
      return this.userBaseInfo.userId;
    },
neogcg's avatar
neogcg committed
36 37 38
    usertoken() {
      return this.token;
    },
yanzhongrong's avatar
yanzhongrong committed
39 40 41 42 43
  },
  methods: {
    receiveMessage,
    closeWebsocket() {
      if (this.websocket) {
neogcg's avatar
neogcg committed
44
        this.websocket.close();
yanzhongrong's avatar
yanzhongrong committed
45 46 47 48
      }
    },
  },
  mounted() {
neogcg's avatar
neogcg committed
49 50 51
    // this.websocket = socket({
    //   onmessage: this.receiveMessage,
    // });
neogcg's avatar
neogcg committed
52 53

    EventBus.$on("dialogAlarm", (data) => {
yanzhongrong's avatar
yanzhongrong committed
54
      // 接收消息之后 声音弹窗显示
neogcg's avatar
neogcg committed
55
      this.tflag = data;
yanzhongrong's avatar
yanzhongrong committed
56
      setTimeout(() => {
neogcg's avatar
neogcg committed
57 58 59
        this.tflag = false;
      }, 3000);
    });
neogcg's avatar
neogcg committed
60 61 62
    EventBus.$on("cancelWS", () => {
      this.websocket.close();
    });
neogcg's avatar
neogcg committed
63 64 65
    // EventBus.$on("wsOpen", () => {
    //   this.websocket.onopen();
    // });
yanzhongrong's avatar
yanzhongrong committed
66 67
  },
  watch: {
neogcg's avatar
neogcg committed
68
    usertoken: {
yanzhongrong's avatar
yanzhongrong committed
69 70 71
      immediate: true,
      handler(newV) {
        if (newV) {
neogcg's avatar
neogcg committed
72
          this.closeWebsocket();
yanzhongrong's avatar
yanzhongrong committed
73
          this.websocket = socket({
neogcg's avatar
neogcg committed
74 75
            onmessage: this.receiveMessage,
          });
yanzhongrong's avatar
yanzhongrong committed
76
        }
neogcg's avatar
neogcg committed
77 78
      },
    },
neogcg's avatar
neogcg committed
79 80 81 82 83 84 85 86 87 88 89
    // userId: {
    //   immediate: true,
    //   handler(newV) {
    //     if (newV) {
    //       this.closeWebsocket();
    //       this.websocket = socket({
    //         onmessage: this.receiveMessage,
    //       });
    //     }
    //   },
    // },
yanzhongrong's avatar
yanzhongrong committed
90
  },
neogcg's avatar
neogcg committed
91
};
Pan's avatar
Pan committed
92
</script>
许倩倩's avatar
许倩倩 committed
93 94
<style lang="scss" scoped>
#app {
yanzhongrong's avatar
yanzhongrong committed
95 96 97
  // & ::v-deep .el-table__body tr:hover>td{
  //   background-color: #bed5ff !important;
  // }
neogcg's avatar
neogcg committed
98

yanzhongrong's avatar
yanzhongrong committed
99 100 101
  // & ::v-deep .el-table__body tr.current-row>td{
  //   background-color: #bed5ff !important;
  // }
许倩倩's avatar
许倩倩 committed
102
}
neogcg's avatar
neogcg committed
103
.tips {
yanzhongrong's avatar
yanzhongrong committed
104 105 106 107 108 109
  width: 400px;
  height: 80px;
  background: #fff;
  box-shadow: 0px 2px 14px #888888;
  border-radius: 5px;
  padding: 0 20px 20px 20px;
neogcg's avatar
neogcg committed
110
  position: absolute;
yanzhongrong's avatar
yanzhongrong committed
111
  text-align: center;
neogcg's avatar
neogcg committed
112 113
  top: calc(50% - 40px);
  left: calc(50% - 200px);
yanzhongrong's avatar
yanzhongrong committed
114
}
许倩倩's avatar
许倩倩 committed
115
</style>