Table.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div id="table">
  3. <h1 align="center" style="color: #4adefe">供电系统组态图</h1>
  4. <div class="header">
  5. <img
  6. src="@/assets/img/供电系统组态图.svg"
  7. style="
  8. filter: invert(75%) sepia(10%) saturate(2634%) hue-rotate(153deg)
  9. brightness(101%) contrast(102%);
  10. "
  11. id="imgSwitch"
  12. />
  13. </div>
  14. <el-main>
  15. <div class="table1">
  16. <el-row :gutter="40">
  17. <el-col :span="2" style="color: #4adefe; margin-right: -65px"
  18. >负荷:</el-col
  19. >
  20. <el-col :span="1">{{ load[0] }}</el-col>
  21. <el-col :span="1">{{ load[1] }}</el-col>
  22. <el-col :offset="1" :span="1">{{ load[2] }}</el-col>
  23. <el-col :span="1">{{ load[3] }}</el-col>
  24. <el-col :offset="1" :span="1">{{ load[4] }}</el-col>
  25. <el-col :span="1">{{ load[5] }}</el-col>
  26. <el-col :span="1">{{ load[6] }}</el-col>
  27. <el-col style="margin-left: 230px" :span="1">{{ load[7] }}</el-col>
  28. <el-col style="margin-left: 30px" :span="1">{{ load[8] }}</el-col>
  29. <el-col style="margin-left: 20px" :span="1">{{ load[9] }}</el-col>
  30. <el-col style="margin-left: 20px" :span="1">{{ load[10] }}</el-col>
  31. <el-col style="margin-left: 20px" :span="1">{{ load[11] }}</el-col>
  32. <el-col style="margin-left: 30px" :span="1">{{ load[12] }}</el-col>
  33. <el-col style="margin-left: 30px" :span="1">{{ load[13] }}</el-col>
  34. </el-row>
  35. <el-row :gutter="40" style="margin-top: 20px">
  36. <el-col :span="2" style="color: #4adefe; margin-right: -65px"
  37. >电压:</el-col
  38. >
  39. <el-col :span="1">{{ voltage[0] }}</el-col>
  40. <el-col :span="1">{{ voltage[1] }}</el-col>
  41. <el-col :offset="1" :span="1">{{ voltage[2] }}</el-col>
  42. <el-col :span="1">{{ voltage[3] }}</el-col>
  43. <el-col :offset="1" :span="1">{{ voltage[4] }}</el-col>
  44. <el-col :span="1">{{ voltage[5] }}</el-col>
  45. <el-col :span="1">{{ voltage[6] }}</el-col>
  46. <el-col style="margin-left: 230px" :span="1">{{ voltage[7] }}</el-col>
  47. <el-col style="margin-left: 30px" :span="1">{{ voltage[8] }}</el-col>
  48. <el-col style="margin-left: 20px" :span="1">{{ voltage[9] }}</el-col>
  49. <el-col style="margin-left: 20px" :span="1">{{ voltage[10] }}</el-col>
  50. <el-col style="margin-left: 20px" :span="1">{{ voltage[11] }}</el-col>
  51. <el-col style="margin-left: 30px" :span="1">{{ voltage[12] }}</el-col>
  52. <el-col style="margin-left: 30px" :span="1">{{ voltage[13] }}</el-col>
  53. </el-row>
  54. <el-row :gutter="40" style="margin-top: 20px">
  55. <el-col :span="2" style="color: #4adefe; margin-right: -65px"
  56. >电流:</el-col
  57. >
  58. <el-col :span="1">{{ current[0] }}</el-col>
  59. <el-col :span="1">{{ current[1] }}</el-col>
  60. <el-col :offset="1" :span="1">{{ current[2] }}</el-col>
  61. <el-col :span="1">{{ current[3] }}</el-col>
  62. <el-col :offset="1" :span="1">{{ current[4] }}</el-col>
  63. <el-col :span="1">{{ current[5] }}</el-col>
  64. <el-col :span="1">{{ current[6] }}</el-col>
  65. <el-col style="margin-left: 230px" :span="1">{{ current[7] }}</el-col>
  66. <el-col style="margin-left: 30px" :span="1">{{ current[8] }}</el-col>
  67. <el-col style="margin-left: 20px" :span="1">{{ current[9] }}</el-col>
  68. <el-col style="margin-left: 20px" :span="1">{{ current[10] }}</el-col>
  69. <el-col style="margin-left: 20px" :span="1">{{ current[11] }}</el-col>
  70. <el-col style="margin-left: 30px" :span="1">{{ current[12] }}</el-col>
  71. <el-col style="margin-left: 30px" :span="1">{{ current[13] }}</el-col>
  72. </el-row>
  73. <el-row :gutter="40" style="margin-top: 20px">
  74. <el-col :span="2" style="color: #4adefe; margin-right: -65px"
  75. >Cos:</el-col
  76. >
  77. <el-col :span="1">{{ cos[0] }}</el-col>
  78. <el-col :span="1">{{ cos[1] }}</el-col>
  79. <el-col :offset="1" :span="1">{{ cos[2] }}</el-col>
  80. <el-col :span="1">{{ cos[3] }}</el-col>
  81. <el-col :offset="1" :span="1">{{ cos[4] }}</el-col>
  82. <el-col :span="1">{{ cos[5] }}</el-col>
  83. <el-col :span="1">{{ cos[6] }}</el-col>
  84. <el-col style="margin-left: 230px" :span="1">{{ cos[7] }}</el-col>
  85. <el-col style="margin-left: 30px" :span="1">{{ cos[8] }}</el-col>
  86. <el-col style="margin-left: 20px" :span="1">{{ cos[9] }}</el-col>
  87. <el-col style="margin-left: 20px" :span="1">{{ cos[10] }}</el-col>
  88. <el-col style="margin-left: 20px" :span="1">{{ cos[11] }}</el-col>
  89. <el-col style="margin-left: 30px" :span="1">{{ cos[12] }}</el-col>
  90. <el-col style="margin-left: 30px" :span="1">{{ cos[13] }}</el-col>
  91. </el-row>
  92. </div>
  93. </el-main>
  94. <el-row style="margin-top: -40px">
  95. <el-col :offset="6" :span="7"
  96. ><div class="grid-content bg-purple">
  97. <table class="table2">
  98. <tr align="left">
  99. <td>Ua(KV):<span>{{bottom.Ua1}}KV</span></td>
  100. <td>Uab(KV):<span>{{bottom.Uab1}}KV</span></td>
  101. </tr>
  102. <tr align="left">
  103. <td>Ub(KV):<span>{{bottom.Ub1}}KV</span></td>
  104. <td>Ubc(KV):<span>{{bottom.Ubc1}}KV</span></td>
  105. </tr>
  106. <tr align="left">
  107. <td>Uc(KV):<span>{{bottom.Uc1}}KV</span></td>
  108. <td>Uca(KV):<span>{{bottom.Uca1}}KV</span></td>
  109. </tr>
  110. </table>
  111. </div></el-col
  112. >
  113. <el-col :span="8"
  114. ><div class="grid-content bg-purple">
  115. <table class="table2">
  116. <tr align="left">
  117. <td>Ua(KV):<span>{{bottom.Ua2}}KV</span></td>
  118. <td>Uab(KV):<span>{{bottom.Uab2}}KV</span></td>
  119. </tr>
  120. <tr align="left">
  121. <td>Ub(KV):<span>{{bottom.Ub2}}KV</span></td>
  122. <td>Ubc(KV):<span>{{bottom.Ubc2}}KV</span></td>
  123. </tr>
  124. <tr align="left">
  125. <td>Uc(KV):<span>{{bottom.Uc2}}KV</span></td>
  126. <td>Uca(KV):<span>{{bottom.Uca2}}KV</span></td>
  127. </tr>
  128. </table>
  129. </div></el-col
  130. >
  131. </el-row>
  132. </div>
  133. </template>
  134. <script>
  135. import { mapState } from "vuex";
  136. export default {
  137. name: "Table",
  138. data() {
  139. return {
  140. bottom:{
  141. Ua1:22,
  142. Uab1:34,
  143. Ub1:36,
  144. Ubc1:23,
  145. Uc1:43,
  146. Uca1:39,
  147. Ua2:22,
  148. Uab2:36,
  149. Ub2:35,
  150. Ubc2:37,
  151. Uc2:33,
  152. Uca2:29,
  153. },
  154. load: new Array(14).fill("0"),
  155. voltage: new Array(14).fill("0"),
  156. current: new Array(14).fill("0"),
  157. cos: new Array(14).fill("0"),
  158. };
  159. },
  160. methods: {
  161. getBottomData(){
  162. let interval = setInterval(() => {
  163. this.bottom.Ua1= this.getRandomNum(20,30)
  164. this.bottom.Uab1= this.getRandomNum(25,35)
  165. this.bottom.Ub1= this.getRandomNum(27,33)
  166. this.bottom.Ubc1= this.getRandomNum(25,37)
  167. this.bottom.Uc1= this.getRandomNum(25,30)
  168. this.bottom.Uca1= this.getRandomNum(26,34)
  169. this.bottom.Ua2= this.getRandomNum(20,30)
  170. this.bottom.Uab2= this.getRandomNum(25,35)
  171. this.bottom.Ub2= this.getRandomNum(27,33)
  172. this.bottom.Ubc2= this.getRandomNum(25,37)
  173. this.bottom.Uc2= this.getRandomNum(25,30)
  174. this.bottom.Uca2= this.getRandomNum(26,34)
  175. }, 3000);
  176. this.$once("hook:beforeDestroy", () => {
  177. clearInterval(interval);
  178. });
  179. },
  180. getData(data, type) {
  181. console.log(data[0]);
  182. this.load.splice(0, 1, data[0]["fuhe_after"]);
  183. this.cos.splice(0, 1, data[0]["gonglvyinshu_after"]);
  184. this.current.splice(0, 1, data[0]["dianliu_after"]);
  185. this.voltage.splice(0, 1, data[0]["dianya_after"]);
  186. let data1 = [];
  187. let data2 = [];
  188. let data3 = [];
  189. let data4 = [];
  190. for (let i = 0; i < 13; i++) {
  191. data1.push(this.getRandomNum(5000, 5200));
  192. data2.push(this.getRandomNum(10, 15));
  193. data3.push(this.getRandomNum(300, 400));
  194. data4.push(Math.random().toFixed(1));
  195. }
  196. // 伪造数据
  197. this.load.splice(1, 13, ...data1);
  198. this.voltage.splice(1, 13, ...data2);
  199. this.current.splice(1, 13, ...data3);
  200. this.cos.splice(1, 13, ...data4);
  201. },
  202. initWebSocket(websocket, type) {
  203. // 连接错误
  204. websocket.onerror = () => {
  205. console.log("WebSocket连接发生错误 状态码:" + websocket.readyState);
  206. };
  207. // 连接成功
  208. websocket.onopen = () => {
  209. console.log("WebSocket连接成功 状态码:" + websocket.readyState);
  210. };
  211. // 收到消息的回调
  212. websocket.onmessage = (event) => {
  213. // console.log("onmessage", event);
  214. if (JSON.parse(event.data).length) {
  215. this.getData(JSON.parse(event.data), type);
  216. }
  217. };
  218. // 连接关闭的回调
  219. websocket.onclose = () => {
  220. console.log("WebSocket连接关闭 状态码:" + websocket.readyState);
  221. };
  222. // 通过$once来监听定时器,在beforeDestroy钩子可以被清除。
  223. this.$once("hook:beforeDestroy", () => {
  224. websocket.close();
  225. });
  226. },
  227. },
  228. computed: {
  229. ...mapState(["websocketIP"]),
  230. },
  231. mounted() {
  232. // websocket
  233. // 采泵1
  234. let pump1 = new WebSocket(`ws://${this.websocketIP}/hbase/ws/belt/62`);
  235. this.initWebSocket(pump1, "pump1");
  236. // 伪造底部数据
  237. this.getBottomData();
  238. },
  239. };
  240. </script>
  241. <style scoped>
  242. .table1 {
  243. width: 100%;
  244. height: 250px;
  245. color: #f3db5c;
  246. margin: 0px auto;
  247. }
  248. .table2 {
  249. /* margin: 60px; */
  250. border-collapse: separate;
  251. border-spacing: 20px 5px; /* 水平间距 垂直间距 */
  252. /* width: 550px; */
  253. bottom: 20px;
  254. font-size: 20px;
  255. line-height: 20px;
  256. color: #4adefe;
  257. /* position: absolute; */
  258. }
  259. .table2 span {
  260. color: #f3db5c;
  261. padding-left: 40px;
  262. }
  263. .table4 {
  264. width: 300px;
  265. bottom: 0px;
  266. right: 0px;
  267. line-height: 10px;
  268. color: white;
  269. position: absolute;
  270. }
  271. .header {
  272. width: 100%;
  273. height: 400px;
  274. transform: translateY(-70%);
  275. margin-left: 20px;
  276. }
  277. #imgSwitch {
  278. width: 95%;
  279. height: 100;
  280. /* padding-bottom: 100px; */
  281. /* left: 50px; */
  282. /* margin-left: 30px; */
  283. }
  284. </style>