rtone.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div id="rtone">
  3. <div class="daystatics">
  4. <div class="item">
  5. <span>累计完成进尺 :</span><span>{{ data.leijijinchi }}</span
  6. >m
  7. </div>
  8. <div class="item">
  9. <span>月 完 成 进尺 :</span><span>{{ data.yuejinchi }}</span
  10. >m
  11. </div>
  12. <div class="item">
  13. <span>日 平 均 进尺 :</span><span>{{ data.rizuigaojinchi }}</span
  14. >m
  15. </div>
  16. <div class="item">
  17. <span>班 最 高 进尺 :</span> <span>{{ data.banzuigaojinchi }}</span
  18. >m
  19. </div>
  20. <div class="item">
  21. <span>日 最 高 进尺 :</span><span>{{ data.rizuigaojinchi }}</span
  22. >m
  23. </div>
  24. <div class="item">
  25. <span>当 前___人 员 :</span
  26. ><span id="six">{{ data.dangqianrenyuan }}</span>
  27. </div>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import { mapState } from "vuex";
  33. export default {
  34. data() {
  35. return {
  36. data: {
  37. dangqianrenyuan: "0",
  38. qnm: "0",
  39. banzuigaojinchi: "0",
  40. rizuigaojinchi: "0",
  41. leijijinchi: "0",
  42. yuejinchi: "0",
  43. rijinchi: "0",
  44. },
  45. };
  46. },
  47. mounted() {
  48. this.websocket = new WebSocket(`ws://${this.websocketIP}/hbase/ws/belt/53`);
  49. this.initWebSocket();
  50. },
  51. methods: {
  52. initWebSocket() {
  53. // 连接错误
  54. this.websocket.onerror = () => {
  55. console.log(
  56. "WebSocket连接发生错误 状态码:" + this.websocket.readyState
  57. );
  58. };
  59. // 连接成功
  60. this.websocket.onopen = () => {
  61. console.log(
  62. "WebSocket连接成功 状态码:" + this.websocket.readyState
  63. );
  64. };
  65. // 收到消息的回调
  66. this.websocket.onmessage = (event) => {
  67. if (JSON.parse(event.data).length) {
  68. this.changeState(JSON.parse(event.data));
  69. }
  70. };
  71. // 连接关闭的回调
  72. this.websocket.onclose = () => {
  73. console.log(
  74. "WebSocket连接关闭 状态码:" + this.websocket.readyState
  75. );
  76. };
  77. // 通过$once来监听定时器,在beforeDestroy钩子可以被清除。
  78. this.$once("hook:beforeDestroy", () => {
  79. this.websocket.close();
  80. });
  81. },
  82. changeState(data) {
  83. this.data = data[0];
  84. },
  85. close() {
  86. this.websocket.close();
  87. console.log(123);
  88. },
  89. },
  90. computed: {
  91. ...mapState(["websocketIP"]),
  92. },
  93. };
  94. </script>
  95. <style lang="less" scoped>
  96. .daystatics {
  97. display: grid;
  98. grid-template-columns: repeat(1, 500px);
  99. margin-top: -40px;
  100. .item {
  101. color: #4adefe;
  102. font-size: 18px;
  103. margin-left: 30px;
  104. }
  105. .item span:nth-of-type(1) {
  106. display: inline-block;
  107. color: #4adefe;
  108. font-size: 18px;
  109. width: 140px;
  110. }
  111. .item span:nth-of-type(2) {
  112. display: inline-block;
  113. text-indent: -47px;
  114. color: #f3db5c;
  115. font-size: 25px;
  116. }
  117. }
  118. li {
  119. width: 100%;
  120. height: 100%;
  121. color: #4adefe;
  122. display: flex;
  123. /* flex-direction: column; */
  124. font-size: 18px;
  125. position: relative;
  126. }
  127. span {
  128. border-radius: 0.7px;
  129. width: 116.5px;
  130. height: 38.625px;
  131. color: #f3db5c;
  132. font-size: 25px;
  133. /* background-color: rgb(133, 158, 231); */
  134. margin: 0 -0.675px 0.25px;
  135. text-align: center;
  136. }
  137. </style>