index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <div class="param_config_page">
  3. <!-- 固定在顶部的头部区域 -->
  4. <div class="fixed_header" ref="fixedHeader">
  5. <HeaderComponent title="硫酸钠-参数配置" backTo="/controlPage/flowSelect" />
  6. <PageNav :items="paramItems_Na2SO4" :currentCode="paramPageCode" />
  7. </div>
  8. <!-- 主内容区(包含设备导航) -->
  9. <div class="main_container">
  10. <div class="main_content">
  11. <!-- 设备列表区域 -->
  12. <div class="content_area">
  13. <!-- 加载状态 -->
  14. <div v-if="isLoading" class="loading">正在加载参数配置...</div>
  15. <!-- 错误状态 -->
  16. <div v-if="hasError" class="error">
  17. <p>加载配置失败: {{ errorMessage }}</p>
  18. <button @click="loadConfigData">重试</button>
  19. </div>
  20. <div v-else class="config_container">
  21. <!-- 按罐体分组 -->
  22. <div v-for="(equipments, tankName) in filteredDeviceConfigGroup" :key="tankName"
  23. class="tank_section" :id="`tank_${tankName}`">
  24. <h2 class="tank_title">{{ tankName }}</h2>
  25. <div class="params_grid">
  26. <!-- 显示参数加载状态 -->
  27. <div v-if="!isInitialParamsLoaded" class="loading">加载参数中...</div>
  28. <!-- 确保初始参数加载完成后再渲染组件 -->
  29. <ParamConfigComponent v-if="isInitialParamsLoaded" v-for="equipment in equipments"
  30. :key="equipment.code" :title="equipment.title + '-' + equipment.equipmentName"
  31. :code="equipment.code" :initial-params="getInitialParams(equipment.code)"
  32. :id="`device_${equipment.code}`" />
  33. </div>
  34. </div>
  35. <!-- 无数据提示 -->
  36. <div v-if="isEmptyData" class="no_data">未获取到设备配置信息</div>
  37. </div>
  38. </div>
  39. <!-- 右侧罐体导航(使用导航组件) -->
  40. <TankNavigation :tanks="tankNavList" :current-index="currentNavIndex" :header-height="headerHeight"
  41. @tankClick="scrollToTank" @scrollPositionChange="handleScrollPositionChange" />
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script setup>
  47. import { ref, onMounted, computed, watchEffect, onBeforeUnmount } from 'vue'
  48. import { useRoute } from 'vue-router'
  49. import HeaderComponent from '@/components/DCS/HeaderComponent.vue'
  50. import PageNav from '@/components/GeneralComponents/control/PageNavComponent.vue'
  51. import { getPageEquipmentGroupByTankByFlowCode } from '@/api/hnyz/equipment'
  52. import { paramItems_Na2SO4 } from '@/config'
  53. import ParamConfigComponent from '@/components/GeneralComponents/control/paramConfigComponent.vue'
  54. import TankNavigation from '@/components/GeneralComponents/control/TankNavigationComponent.vue'
  55. import { getAllParamConfigDataByCodeList } from '@/api/hnyz/param'
  56. const route = useRoute()
  57. // 状态变量
  58. const isLoading = ref(true)
  59. const hasError = ref(false)
  60. const errorMessage = ref('')
  61. const isEmptyData = ref(false)
  62. const flowCode = ref(route.name.replace(/_.+$/, '_Control'))
  63. const paramPageCode = ref(route.name)
  64. const fixedHeader = ref(null)
  65. const headerHeight = ref(0)
  66. // 新增:标记初始参数是否加载完成
  67. const isInitialParamsLoaded = ref(false)
  68. // 导航相关变量 - 只处理最外层罐体
  69. const tankNavList = ref([]) // 罐体导航列表数据
  70. const currentNavIndex = ref(-1) // 当前激活的导航项索引
  71. // 设备配置和初始参数数据
  72. const deviceConfigGroup = ref({})
  73. const initialParamData = ref({})
  74. // 过滤后的设备配置(排除阀门)
  75. const filteredDeviceConfigGroup = computed(() => {
  76. const filtered = {}
  77. Object.entries(deviceConfigGroup.value).forEach(([tankName, equipments]) => {
  78. const validEquipments = equipments.filter(equip =>
  79. ![1, 5].includes(Number(equip.equipmentType))
  80. )
  81. if (validEquipments.length > 0) {
  82. filtered[tankName] = validEquipments
  83. }
  84. })
  85. isEmptyData.value = Object.keys(filtered).length === 0
  86. return filtered
  87. })
  88. // 生成罐体导航列表(只包含最外层罐体,不包含子设备)
  89. const generateTankNavList = computed(() => {
  90. const navList = []
  91. // 直接遍历罐体名称,不处理子设备
  92. Object.keys(filteredDeviceConfigGroup.value).forEach(tankName => {
  93. // 生成简短名称用于导航显示
  94. const shortName = tankName.length > 18
  95. ? tankName.substring(0, 17) + '...'
  96. : tankName
  97. navList.push({
  98. uniqueId: `tank_${tankName}`, // 与罐体DOM元素ID对应
  99. tankName,
  100. shortName,
  101. fullName: tankName
  102. })
  103. })
  104. return navList
  105. })
  106. // 计算固定头部高度
  107. const calculateHeaderHeight = () => {
  108. if (fixedHeader.value) {
  109. headerHeight.value = fixedHeader.value.offsetHeight
  110. }
  111. }
  112. // 处理滚动位置变化事件
  113. function handleScrollPositionChange(index) {
  114. currentNavIndex.value = index
  115. }
  116. // 加载设备配置和初始参数
  117. async function loadConfigData() {
  118. try {
  119. isLoading.value = true
  120. hasError.value = false
  121. // 重置参数加载状态
  122. isInitialParamsLoaded.value = false
  123. // 1. 获取设备列表(按罐体分组)
  124. const res = await getPageEquipmentGroupByTankByFlowCode(flowCode.value)
  125. deviceConfigGroup.value = Object.fromEntries(
  126. Object.entries(res.data || {}).filter(([_, equipments]) => equipments?.length > 0)
  127. )
  128. // 2. 加载初始参数值(若有设备)
  129. if (Object.keys(filteredDeviceConfigGroup.value).length > 0) {
  130. await loadInitialParamValues()
  131. } else {
  132. // 没有设备时也标记参数加载完成
  133. isInitialParamsLoaded.value = true
  134. }
  135. } catch (err) {
  136. hasError.value = true
  137. errorMessage.value = err.message || '加载配置失败'
  138. console.error('加载配置失败', err)
  139. // 错误时也标记参数加载完成,避免一直显示加载状态
  140. isInitialParamsLoaded.value = true
  141. } finally {
  142. isLoading.value = false
  143. }
  144. }
  145. // 加载所有设备的初始参数值
  146. async function loadInitialParamValues() {
  147. try {
  148. const allCodes = []
  149. Object.values(filteredDeviceConfigGroup.value).forEach(equipments => {
  150. equipments.forEach(equip => allCodes.push(equip.code))
  151. })
  152. const res = await getAllParamConfigDataByCodeList(allCodes)
  153. // console.log('加载初始参数结果', res)
  154. initialParamData.value = res.data || {}
  155. } catch (err) {
  156. console.error('加载初始参数失败', err)
  157. initialParamData.value = {}
  158. } finally {
  159. // 无论成功失败,都标记参数加载完成
  160. isInitialParamsLoaded.value = true
  161. }
  162. }
  163. // 获取设备的初始参数
  164. function getInitialParams(code) {
  165. const paramCount = getParamCountByCode(code)
  166. // console.log('获取初始参数', code, paramCount, initialParamData.value)
  167. return initialParamData.value[code] || new Array(paramCount).fill(0)
  168. }
  169. // 辅助函数:根据设备code获取参数数量
  170. function getParamCountByCode(code) {
  171. const type = getDeviceTypeByCode(code)
  172. const paramCount = paramTemplates[type] || 0
  173. return paramCount
  174. }
  175. // 辅助函数:根据设备code判断类型
  176. function getDeviceTypeByCode(code) {
  177. const upperType = code.toUpperCase()
  178. if (upperType.startsWith('PH')) return 'ph'
  179. if (upperType.startsWith('PT')) return 'pressuregauge'
  180. if (upperType.startsWith('TT')) return 'thermometer'
  181. if (upperType.startsWith('FIT')) return 'flowmeter'
  182. if (upperType.startsWith('P') || upperType.startsWith('M')) return 'pump'
  183. if (upperType.startsWith('LT')) return 'levelmeter'
  184. return 'unknown'
  185. }
  186. // 滚动到指定罐体(而非子设备)
  187. function scrollToTank(tank, index) {
  188. currentNavIndex.value = index
  189. const element = document.getElementById(`tank_${tank.tankName}`)
  190. if (element) {
  191. // 平滑滚动到罐体位置,考虑头部高度
  192. window.scrollTo({
  193. top: element.offsetTop - headerHeight.value - 20,
  194. behavior: 'smooth'
  195. })
  196. }
  197. }
  198. // 参数模板定义(不同设备类型的参数数量)
  199. const paramTemplates = {
  200. pump: 3,
  201. flowmeter: 5,
  202. thermometer: 2,
  203. ph: 3,
  204. levelmeter: 5,
  205. pressuregauge: 3,
  206. unknown: 0
  207. }
  208. // 初始化
  209. onMounted(() => {
  210. // 计算头部高度
  211. calculateHeaderHeight()
  212. // 监听窗口大小变化,重新计算头部高度
  213. window.addEventListener('resize', calculateHeaderHeight)
  214. loadConfigData()
  215. // 当罐体列表变化时更新导航
  216. watchEffect(() => {
  217. tankNavList.value = generateTankNavList.value
  218. currentNavIndex.value = -1
  219. })
  220. })
  221. onBeforeUnmount(() => {
  222. window.removeEventListener('resize', calculateHeaderHeight)
  223. })
  224. </script>
  225. <style scoped>
  226. .param_config_page {
  227. width: 100%;
  228. min-height: 100vh;
  229. padding: 0;
  230. background-color: #252525;
  231. }
  232. /* 固定头部样式 */
  233. .fixed_header {
  234. position: fixed;
  235. top: 0;
  236. left: 0;
  237. right: 0;
  238. z-index: 1000;
  239. background-color: #252525;
  240. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  241. }
  242. /* 主容器样式(避免被固定头部遮挡) */
  243. .main_container {
  244. padding: 140px 20px 24px;
  245. box-sizing: border-box;
  246. }
  247. /* 主内容区布局 */
  248. .main_content {
  249. display: flex;
  250. gap: 20px;
  251. max-width: 1700px;
  252. margin: 0 auto;
  253. }
  254. .content_area {
  255. flex: 1;
  256. min-width: 1350px;
  257. }
  258. .config_container {
  259. width: 100%;
  260. padding: 20px 0;
  261. }
  262. .tank_section {
  263. margin-bottom: 30px;
  264. background: #1a1a1a;
  265. border-radius: 8px;
  266. padding: 20px;
  267. border: 1px solid #72E0FF;
  268. scroll-margin-top: 160px;
  269. /* 滚动定位预留空间 */
  270. }
  271. .tank_title {
  272. margin: 0 0 20px 0;
  273. padding-bottom: 10px;
  274. border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  275. font-size: 18px;
  276. color: #76E1FF;
  277. }
  278. .params_grid {
  279. display: grid;
  280. grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  281. gap: 20px;
  282. }
  283. /* 状态提示样式 */
  284. .loading,
  285. .error,
  286. .no_data {
  287. width: 100%;
  288. margin: 20px auto;
  289. padding: 20px;
  290. border-radius: 8px;
  291. text-align: center;
  292. background-color: rgba(255, 255, 255, 0.1);
  293. color: #fff;
  294. }
  295. .loading {
  296. color: #1890ff;
  297. }
  298. .error {
  299. color: #f5222d;
  300. }
  301. .error button {
  302. padding: 8px 16px;
  303. background: #f5222d;
  304. color: white;
  305. border: none;
  306. border-radius: 4px;
  307. cursor: pointer;
  308. margin-top: 10px;
  309. }
  310. .error button:hover {
  311. background: #d91111;
  312. }
  313. /* 响应式调整 */
  314. @media (max-width: 1400px) {
  315. .params_grid {
  316. grid-template-columns: repeat(2, 1fr);
  317. gap: 20px;
  318. }
  319. }
  320. @media (max-width: 1200px) {
  321. .main_container {
  322. padding: 140px 15px 16px;
  323. }
  324. .main_content {
  325. max-width: 100%;
  326. }
  327. .content_area {
  328. min-width: auto;
  329. }
  330. }
  331. @media (max-width: 992px) {
  332. .main_content {
  333. flex-direction: column;
  334. }
  335. .params_grid {
  336. grid-template-columns: 1fr;
  337. gap: 16px;
  338. }
  339. .main_container {
  340. padding: 120px 15px 16px;
  341. }
  342. }
  343. @media (max-width: 768px) {
  344. .tank_section {
  345. padding: 15px;
  346. margin-bottom: 20px;
  347. }
  348. .params_grid {
  349. gap: 14px;
  350. }
  351. }
  352. </style>