realtimeAlarm.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div>
  3. <div class="el-table-content">
  4. <pro-table :height="tabHeight" :loading="tab_loading" :data="filteredData" :config="tableConfig">
  5. <template #default="{ row }">
  6. <div :class="getColor(row.switch_type.toString())">
  7. {{ (row.switch_type
  8. ? (dictStore.getDictLabel("switch_type", row.switch_type) as any)
  9. : undefined
  10. )?.dict_label || row.switch_type }}
  11. </div>
  12. </template>
  13. </pro-table>
  14. </div>
  15. </div>
  16. </template>
  17. <script setup lang="ts">
  18. import { ref } from 'vue';
  19. import { useDictStore } from "@/store";
  20. import BizVarDictAPI, { BizVarDictTable,BizVarDictPageQuery } from '@/api/module_business/vardict'
  21. import MqttUtil, { MqttMessageCallback } from '@/utils/mqttUtil';
  22. const tabHeight = ref('calc(100vh - 70px - 5px - 50px - 10px - 44px)')
  23. const craneInfo = JSON.parse(localStorage.getItem('craneInfo') || '{}')
  24. const tab_loading = ref(true)
  25. const tableConfig = ref([{
  26. prop: 'var_name',
  27. label: '报警内容'
  28. },
  29. {
  30. prop: 'switch_type',
  31. label: '报警级别',
  32. slot: 'true'
  33. }])
  34. const dictStore = useDictStore()
  35. const dictTypes: any = [
  36. 'switch_type'
  37. ]
  38. const mqttConfig = {
  39. wsUrl: import.meta.env.VITE_APP_WS_ENDPOINT || 'ws://127.0.0.1:9001',
  40. topics: ['cdc/'+craneInfo.crane_no+'/alarm/#']
  41. };
  42. const mqttUtil = new MqttUtil(mqttConfig);
  43. const queryFormVarDictData = reactive<BizVarDictPageQuery>({
  44. page_no: 0,
  45. page_size: 0,
  46. crane_no: craneInfo.crane_no,
  47. var_code: undefined,
  48. var_name: undefined,
  49. mec_type: undefined,
  50. switch_type: undefined,
  51. gateway_id: undefined,
  52. var_group: undefined,
  53. var_category: undefined,
  54. is_top_show: undefined,
  55. is_save: undefined,
  56. is_overview_top_show: undefined,
  57. is_home_page_show: undefined,
  58. status: undefined,
  59. created_time: undefined,
  60. updated_time: undefined,
  61. created_id: undefined,
  62. updated_id: undefined,
  63. });
  64. const allData = ref<BizVarDictTable[]>([]);
  65. const filteredData = computed(() => {
  66. return allData.value.filter(item => item.value);
  67. });
  68. const getData = async () => {
  69. const response = await BizVarDictAPI.listBizVarDictAlarms(queryFormVarDictData);
  70. allData.value = response.data.data
  71. tab_loading.value = false
  72. }
  73. const handleMqttMessage: MqttMessageCallback = (topic, payload) => {
  74. let topic_levels = topic.split('/')
  75. let crane_no = topic_levels[1]
  76. let suffix = topic_levels[2]
  77. if (suffix === 'alarm') {
  78. allData.value.forEach((item) => {
  79. if (item.var_code === payload.var_code) {
  80. item.value = payload.value
  81. }
  82. });
  83. }
  84. }
  85. const getColor = (type:string) => {
  86. switch (type) {
  87. case '2':
  88. return 'pilot-lamp-bg-yellow';
  89. case '3':
  90. return 'pilot-lamp-bg-orange';
  91. case '4':
  92. return 'pilot-lamp-bg-red';
  93. }
  94. }
  95. onMounted(async () => {
  96. if (dictTypes.length > 0) {
  97. await dictStore.getDict(dictTypes)
  98. }
  99. getData();
  100. mqttUtil.initConnect(handleMqttMessage);
  101. })
  102. onUnmounted(() => {
  103. mqttUtil.releaseResources();
  104. });
  105. </script>
  106. <style lang="less" scoped>
  107. .el-table-content {
  108. padding: 20px;
  109. background: linear-gradient(to bottom, rgba(20, 66, 140, 0.8) 0%, rgba(18, 31, 52, 1) 15%);
  110. border: 2px solid rgba(40, 73, 136, 1);
  111. height: 100%;
  112. }
  113. .pilot-lamp-bg-red {
  114. color: #F9143D;
  115. }
  116. .pilot-lamp-bg-yellow {
  117. color: #FFD800;
  118. }
  119. .pilot-lamp-bg-orange {
  120. color: #f39902;
  121. }
  122. ::-webkit-scrollbar {
  123. width: 5px;
  124. height: 5px;
  125. }
  126. ::-webkit-scrollbar-track {
  127. border-radius: 10px;
  128. }
  129. ::-webkit-scrollbar-thumb {
  130. border-radius: 7px;
  131. background-color: #798DAE;
  132. }
  133. </style>