FlowControlPage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="dcs_tanks">
  3. <!-- 固定头部 -->
  4. <div class="fixed-header" ref="fixedHeader">
  5. <HeaderComponent title="硫酸钠 - 控制页面" backTo="/controlPage/flowSelect" />
  6. <PageNav :items="navItems" :currentCode="flowCode" />
  7. <PageSwitcher />
  8. </div>
  9. <!-- 主内容区 -->
  10. <div class="main-container">
  11. <div class="main-content">
  12. <!-- 设备区域 -->
  13. <div class="content-area">
  14. <div v-if="isLoading" class="loading">正在加载设备数据...</div>
  15. <div v-if="hasError" class="error">
  16. <p>加载数据失败: {{ errorMessage }}</p>
  17. <button @click="loadInitialData">重试</button>
  18. </div>
  19. <div v-else class="tanks_container">
  20. <div v-for="(equipments, tankName) in deviceConfigGroup" :key="tankName" class="tank_section"
  21. :id="`tank-${tankName}`">
  22. <h2 class="tank_title">{{ tankName }}</h2>
  23. <div class="equipment_grid">
  24. <PumpControlComponent v-if="tankName === '1#反应釜-C3001'" title="原矿进料"
  25. :dataArr="[5, 100, 100]" id="equipment-special-pump" class="equipment_item" />
  26. <WorkModeControl v-if="tankName === '兑卤器低位槽-V3001'" class="equipment_item" />
  27. <component v-for="equipment in equipments" :key="equipment.code"
  28. :is="getComponentByType(equipment.equipmentType)"
  29. :title="equipment.title + '-' + equipment.equipmentName" :code="equipment.code"
  30. :dataArr="getValueByCode(tankName, equipment.code)"
  31. :id="`equipment-${equipment.code}`" class="equipment_item" />
  32. </div>
  33. </div>
  34. <div v-if="isEmptyData" class="no_data">未获取到设备数据</div>
  35. </div>
  36. </div>
  37. <!-- 右侧导航 -->
  38. <TankNavigation :tanks="allTanks" :current-index="currentNavIndex" :header-height="headerHeight"
  39. @tankClick="scrollToTank" @scrollPositionChange="handleScrollPositionChange" />
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <script setup>
  45. import { ref, onMounted, onBeforeUnmount, watch, watchEffect, computed } from 'vue';
  46. import { useRoute } from 'vue-router';
  47. import HeaderComponent from '@/components/DCS/HeaderComponent.vue';
  48. import PageNav from '@/components/GeneralComponents/control/PageNavComponent.vue';
  49. import SensorControl from '@/components/GeneralComponents/control/SensorControl2Component.vue';
  50. import PumpControlComponent from '@/components/GeneralComponents/control/PumpControl2Component.vue';
  51. import ValveControlComponent from '@/components/GeneralComponents/control/ValveControl2Component.vue';
  52. import WorkModeControl from '@/components/GeneralComponents/control/WorkModeControl2Component.vue';
  53. import TankNavigation from '@/components/GeneralComponents/control/TankNavigationComponent.vue';
  54. import { getPageEquipmentGroupByTankByFlowCode } from '@/api/hnyz/equipment';
  55. import { useEquipmentLayout } from '@/hooks/useEquipmentLayout';
  56. import { stompClient } from '@/utils/ws/stompClient';
  57. import { updateZTPageConfig } from '@/api/dcs/configurePage';
  58. import { getFlowNav } from '@/api/hnyz/flow';
  59. const route = useRoute();
  60. const flowCode = computed(() => route.params.flowCode);
  61. const navItems = ref();
  62. const isLoading = ref(true);
  63. const hasError = ref(false);
  64. const errorMessage = ref('');
  65. const isEmptyData = ref(false);
  66. const fixedHeader = ref(null);
  67. const headerHeight = ref(0);
  68. const allTanks = ref([]);
  69. const currentNavIndex = ref(-1);
  70. const deviceConfigGroup = ref({});
  71. const deviceDataGroup = ref({});
  72. const pageParams = ref({});
  73. const { generatePageParams } = useEquipmentLayout();
  74. // 监控路由变化
  75. watch(() => route.params.flowCode, loadInitialData);
  76. // 生成导航罐体列表
  77. watchEffect(() => {
  78. allTanks.value = Object.keys(deviceConfigGroup.value).map(tankName => ({
  79. uniqueId: `tank-${tankName}`,
  80. tankName,
  81. shortName: tankName.length > 18 ? tankName.slice(0, 16) + '...' : tankName
  82. }));
  83. currentNavIndex.value = -1;
  84. });
  85. // 计算固定头部高度
  86. const calculateHeaderHeight = () => { headerHeight.value = fixedHeader.value?.offsetHeight || 0; }
  87. // 加载初始数据
  88. async function loadInitialData() {
  89. try {
  90. isLoading.value = true; hasError.value = false; errorMessage.value = '';
  91. const res = await getPageEquipmentGroupByTankByFlowCode(flowCode.value);
  92. deviceConfigGroup.value = Object.fromEntries(
  93. Object.entries(res.data || {}).filter(([_, eqs]) => eqs?.length)
  94. );
  95. isEmptyData.value = !Object.keys(deviceConfigGroup.value).length;
  96. pageParams.value = generatePageParams(deviceConfigGroup.value);
  97. await updatePageConfig();
  98. } catch (err) {
  99. hasError.value = true;
  100. errorMessage.value = err.message || '加载设备分组失败';
  101. } finally {
  102. isLoading.value = false;
  103. }
  104. }
  105. // 更新页面配置并订阅 WebSocket
  106. async function updatePageConfig() {
  107. try {
  108. await updateZTPageConfig(flowCode.value, pageParams.value);
  109. stompClient.unsubscribeFromPage(flowCode.value);
  110. stompClient.subscribeToPage(flowCode.value, data => {
  111. if (!data) return;
  112. try {
  113. for (const key in data) { deviceDataGroup.value[key] = data[key] || []; }
  114. } catch (err) {
  115. console.error('更新设备数据失败:', err);
  116. }
  117. });
  118. } catch (err) { console.error('页面配置失败:', err); }
  119. }
  120. // 根据设备类型返回组件
  121. function getComponentByType(equipmentType) {
  122. const type = Number(equipmentType);
  123. if ([1, 5].includes(type)) return ValveControlComponent;
  124. if (type === 2) return PumpControlComponent;
  125. if (type === 4) return SensorControl;
  126. return 'div';
  127. }
  128. // 根据罐体名和 code 获取设备数据
  129. function getValueByCode(tankName, code) {
  130. const arr = deviceDataGroup.value[tankName] || [];
  131. const item = arr.find(i => i.code === code);
  132. return item ? item.value : [];
  133. }
  134. // 导航滚动
  135. function scrollToTank(tank, index) {
  136. currentNavIndex.value = index;
  137. const el = document.getElementById(`tank-${tank.tankName}`);
  138. if (!el) return;
  139. window.scrollTo({ top: el.offsetTop - headerHeight.value - 20, behavior: 'smooth' });
  140. }
  141. function handleScrollPositionChange(index) { currentNavIndex.value = index; }
  142. onMounted(async () => {
  143. const res = await getFlowNav('Na2SO4', 'flowSelect');
  144. navItems.value = res.data;
  145. calculateHeaderHeight();
  146. window.addEventListener('resize', calculateHeaderHeight);
  147. loadInitialData();
  148. });
  149. onBeforeUnmount(() => {
  150. stompClient.unsubscribeFromPage(flowCode.value);
  151. window.removeEventListener('resize', calculateHeaderHeight);
  152. });
  153. </script>
  154. <style scoped lang="scss">
  155. .dcs_tanks {
  156. width: 100%;
  157. min-height: 100vh;
  158. background-color: #141414;
  159. box-sizing: border-box;
  160. }
  161. // 固定在顶部的头部区域
  162. .fixed-header {
  163. position: fixed;
  164. top: 0;
  165. left: 0;
  166. right: 0;
  167. z-index: 1000;
  168. background-color: #141414;
  169. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  170. }
  171. // 主容器 - 添加顶部内边距,避免被固定头部遮挡
  172. .main-container {
  173. padding: 140px 32px 24px;
  174. box-sizing: border-box;
  175. }
  176. // 主内容区布局
  177. .main-content {
  178. display: flex;
  179. gap: 20px;
  180. width: 100%;
  181. max-width: 1600px;
  182. margin: 0 auto;
  183. }
  184. .content-area {
  185. flex: 1;
  186. }
  187. // 罐体容器
  188. .tanks_container {
  189. display: flex;
  190. flex-direction: column;
  191. gap: 30px;
  192. width: 100%;
  193. }
  194. // 每个罐体区域
  195. .tank_section {
  196. background: #1a1a1a;
  197. border-radius: 12px;
  198. padding: 20px 24px;
  199. width: 100%;
  200. display: flex;
  201. flex-direction: column;
  202. gap: 20px;
  203. box-sizing: border-box;
  204. scroll-margin-top: 160px;
  205. /* 用于滚动定位时预留空间 */
  206. }
  207. .tank_title {
  208. font-size: 20px;
  209. color: #fff;
  210. padding-bottom: 12px;
  211. border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  212. text-align: center;
  213. margin: 0;
  214. }
  215. // 设备网格布局
  216. .equipment_grid {
  217. display: grid;
  218. grid-template-columns: repeat(4, 1fr);
  219. /* 默认4列布局 */
  220. gap: 24px;
  221. /* 增大间距避免拥挤 */
  222. padding: 12px 0;
  223. }
  224. // 统一设备项样式
  225. .equipment_item {
  226. min-height: 200px;
  227. /* 固定最小高度,确保排列整齐 */
  228. padding: 16px;
  229. background-color: rgba(30, 30, 30, 0.9);
  230. border-radius: 8px;
  231. border: 1px solid rgba(114, 224, 255, 0.15);
  232. box-sizing: border-box;
  233. }
  234. /* 确保子组件正确填充容器 */
  235. :deep(.equipment_item) {
  236. width: 100%;
  237. height: 100%;
  238. .title {
  239. margin-bottom: 16px;
  240. padding-bottom: 8px;
  241. border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  242. white-space: nowrap;
  243. overflow: hidden;
  244. text-overflow: ellipsis;
  245. }
  246. }
  247. /* 无数据提示样式 */
  248. .no_data {
  249. color: white;
  250. margin-top: 20px;
  251. padding: 20px;
  252. border-radius: 8px;
  253. background-color: rgba(255, 255, 255, 0.1);
  254. width: 100%;
  255. text-align: center;
  256. }
  257. /* 状态提示样式 */
  258. .loading,
  259. .error {
  260. color: white;
  261. margin-top: 20px;
  262. padding: 20px;
  263. border-radius: 8px;
  264. background-color: rgba(255, 255, 255, 0.1);
  265. width: 100%;
  266. text-align: center;
  267. }
  268. .error {
  269. color: #ff4444;
  270. button {
  271. margin-top: 10px;
  272. padding: 8px 16px;
  273. background-color: #00C851;
  274. color: white;
  275. border: none;
  276. border-radius: 4px;
  277. cursor: pointer;
  278. transition: background-color 0.2s;
  279. &:hover {
  280. background-color: #007E33;
  281. }
  282. }
  283. }
  284. /* 响应式布局 */
  285. @media (max-width: 1400px) {
  286. .equipment_grid {
  287. grid-template-columns: repeat(3, 1fr);
  288. gap: 20px;
  289. }
  290. }
  291. @media (max-width: 1200px) {
  292. .main-container {
  293. padding: 140px 20px 16px;
  294. }
  295. .main-content {
  296. max-width: 100%;
  297. }
  298. .equipment_grid {
  299. grid-template-columns: repeat(3, 1fr);
  300. gap: 18px;
  301. }
  302. }
  303. @media (max-width: 992px) {
  304. .main-content {
  305. flex-direction: column;
  306. }
  307. .equipment_grid {
  308. grid-template-columns: repeat(2, 1fr);
  309. gap: 16px;
  310. }
  311. }
  312. @media (max-width: 768px) {
  313. .main-container {
  314. padding: 120px 16px 16px;
  315. }
  316. .equipment_grid {
  317. grid-template-columns: 1fr;
  318. gap: 14px;
  319. }
  320. .tank_section {
  321. padding: 16px 18px;
  322. gap: 16px; scroll-margin-top: 140px;
  323. }
  324. .equipment_item {
  325. min-height: 180px;
  326. }
  327. }
  328. </style>