index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="preview">
  3. <div ref="pageRef" class="page">
  4. <HeaderComponent :title="title"></HeaderComponent>
  5. <div class="content_page">
  6. <PageDrawer :pages="pageItems_Na2SO4" class="page_drawer" />
  7. <PageSwitcher class="page_switcher" />
  8. <!-- 阀门 -->
  9. <div class="valves">
  10. <component v-for="item in deviceConfigGroup.VALVES" :key="item.id"
  11. :is="getComponentName(item.modelId)" :title="getEquipmentTitle(item.equipmentName)"
  12. :valveStatusArr="getDataArrByCode(item.code)" :rotateAngle="item.rotate || 0"
  13. :iconSize="item.size" :style="getComponentStyle(item)" />
  14. </div>
  15. <!-- 泵 -->
  16. <div class="pumps">
  17. <component v-for="item in deviceConfigGroup.PUMPS" :key="item.id"
  18. :is="getComponentName(item.modelId)" :title="getEquipmentTitle(item.title)"
  19. :pumpDataArr="pumpHelper.getDataArrByCode(item.code)" :isReverse="item.isReverse"
  20. :iconSize="item.size" :style="getComponentStyle(item)" />
  21. </div>
  22. <!-- 罐体 -->
  23. <div class="tanks">
  24. <component v-for="item in deviceConfigGroup.TANKS" :key="item.id"
  25. :is="getComponentName(item.modelId)" :title="getEquipmentTitle(item.title)"
  26. :iconSize="item.size" :iconWidth="item.width" :iconHeight="item.height"
  27. :style="getComponentStyle(item)" />
  28. </div>
  29. <!-- 传感器 -->
  30. <div class="sensors">
  31. <component v-for="item in deviceConfigGroup.SENSORS" :key="item.id"
  32. :is="getComponentName(item.modelId)" :title="getEquipmentTitle(item.equipmentName)"
  33. :sensorSize="item.size" :sensorValue="sensorHelper.getDataArrByCode(item.code)"
  34. :sensorWidth="item.width" :sensorHeight="item.height" :style="getComponentStyle(item)"
  35. :specialCondition="JSON.parse(item.specialCondition)" />
  36. </div>
  37. <!-- 其他设备 -->
  38. <div class="icon_others">
  39. <component v-for="item in deviceConfigGroup.ICONS" :key="item.id"
  40. :is="getComponentName(item.modelId)" :iconSize="item.size"
  41. :iconClass="getIconClass(item.modelId)" :style="getComponentStyle(item)"
  42. :title="getEquipmentTitle(item.title)" />
  43. </div>
  44. <!-- 管道 -->
  45. <div class="pipelines">
  46. <component v-for="item in pipeConfig" :key="item.id" :is="getComponentName(item.modelId)"
  47. :pipeStatus="evaluateCondition(item.flowCondition, true)" :strokeWidth="item.pipeWidth"
  48. :style="getPipelineStyle(item, evaluateCondition(item.reverseCondition))"
  49. :class="getPipelineClass(item.pipeClass, getPipeType(item.dynamicPipelineCondition))" />
  50. </div>
  51. <!-- 大箭头指向 -->
  52. <div class="arrows">
  53. <component v-for="item in deviceConfigGroup.ARROWS" :key="item.id"
  54. :is="getComponentName(item.modelId)" :arrowText="getEquipmentTitle(item.equipmentName)"
  55. :iconSize="item.size" :specialCondition="JSON.parse(item.specialCondition)"
  56. :style="getComponentStyle(item)" />
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script setup>
  63. import PageDrawer from '@/components/GeneralComponents/PageDrawerComponent.vue';
  64. import { computed, onMounted, onBeforeUnmount, reactive } from 'vue';
  65. import { useValveHelper } from '@/hooks/useValveHelper'
  66. import { stompClient } from '@/utils/ws/stompClient';
  67. import { useEquipmentLayout } from '@/hooks/useEquipmentLayout'
  68. import { useComponentHelper } from '@/hooks/useComponentHelper'
  69. import { updateZTPageConfig } from '@/api/dcs/configurePage';
  70. import { pageItems_Na2SO4 } from "@/config"
  71. import { useRoute } from 'vue-router'
  72. import { usePageScale } from '@/utils/dcs/usePageScale'
  73. const { pageRef } = usePageScale()
  74. const route = useRoute()
  75. const pageCode = route.name
  76. const title = pageItems_Na2SO4.find(item => item.code === pageCode).label
  77. // 获取设备布局 & 数据订阅
  78. const {
  79. pipeConfig,//管道配置信息
  80. deviceConfigGroup,//设备配置分组
  81. modelMap,//设备模型映射
  82. pageParams,//页面参数
  83. fetchPageConfig,//获取页面配置
  84. } = useEquipmentLayout(pageCode)
  85. // 组件渲染辅助方法
  86. const {
  87. getComponentName,
  88. getComponentStyle,
  89. getIconClass,
  90. getEquipmentTitle,
  91. getPipelineClass,
  92. getPipelineStyle,
  93. } = useComponentHelper(modelMap)
  94. onMounted(async () => {
  95. await fetchPageConfig(pageCode).then(res => {
  96. updatePageConfig()
  97. })
  98. })
  99. onBeforeUnmount(() => {
  100. // 页面销毁时取消订阅
  101. stompClient.unsubscribeFromPage(pageCode);
  102. });
  103. //阀门数据初始化
  104. const valveArr = [
  105. ]
  106. //传感器数据初始化
  107. const sensorArr = [
  108. ]
  109. //泵数据初始化
  110. const pumpArr = [
  111. ]
  112. //设备数据分组
  113. const deviceDataGroup = reactive({
  114. VALVES: valveArr,
  115. PUMPS: pumpArr,
  116. SENSORS: sensorArr,
  117. })
  118. //更新页面配置
  119. function updatePageConfig() {
  120. updateZTPageConfig(pageCode, pageParams.value)
  121. .then(res => {
  122. stompClient.subscribeToPage(pageCode, (data) => {
  123. deviceDataGroup.VALVES = Object.values(data.VALVES)
  124. deviceDataGroup.PUMPS = Object.values(data.PUMPS)
  125. deviceDataGroup.SENSORS = Object.values(data.SENSORS)
  126. });
  127. })
  128. .catch(err => {
  129. console.log('页面配置失败:', err);
  130. });
  131. }
  132. const pumpHelper = useValveHelper(computed(() => deviceDataGroup.PUMPS))
  133. const { getDataArrByCode } = useValveHelper(computed(() => deviceDataGroup.VALVES))
  134. const sensorHelper = useValveHelper(computed(() => deviceDataGroup.SENSORS))
  135. const {
  136. evaluateCondition, getPipeType
  137. } = useValveHelper(computed(() => [...deviceDataGroup.VALVES, ...deviceDataGroup.PUMPS]))
  138. </script>
  139. <style lang="scss" scoped>
  140. @import '@/assets/styles/dcs/hnyzConfiguratePage.scss';
  141. .page {
  142. width: 1920px;
  143. height: 1080px;
  144. background-color: #0b172c;
  145. .content_page {
  146. position: relative;
  147. width: 100%;
  148. height: 1000px;
  149. .page_drawer {
  150. position: absolute;
  151. right: 2%;
  152. top: -1%;
  153. }
  154. }
  155. }
  156. </style>