DeviceWorkStatus.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <script setup lang="ts">
  2. import { onMounted, ref, useTemplateRef } from 'vue';
  3. import { useRouter } from 'vue-router';
  4. import { useInfiniteScroll } from '@vueuse/core';
  5. import SvgIcon from '@/components/SvgIcon.vue';
  6. import { useRequest } from '@/hooks/request';
  7. import { getDevWorkRealTimeData, getDevWorkTypeCount, queryDevicesList } from '@/api';
  8. import { DeviceRunningStatus, DeviceStatusQuery } from '@/constants';
  9. import { DevParamChillerUnit, DevParamCtrlCabinet } from '@/constants/device-params';
  10. import { deviceCardData, DeviceType } from './device-card';
  11. import DeviceWorkParams from './DeviceWorkParams.vue';
  12. import DevWorkParamData from './DevWorkParamData.vue';
  13. import type { DevGroupTabCompProps, DevicesListItem, DeviceTypeCount, PageParams } from '@/types';
  14. const props = defineProps<DevGroupTabCompProps>();
  15. const router = useRouter();
  16. const { isLoading, handleRequest } = useRequest();
  17. const deviceTypes = ref<DeviceTypeCount[]>([]);
  18. const activeDeviceType = ref<DeviceType>(DeviceType.空);
  19. const activeDeviceStatus = ref<DeviceStatusQuery>(DeviceStatusQuery.All);
  20. onMounted(() => {
  21. handleRequest(async () => {
  22. deviceTypes.value = await getDevWorkTypeCount(props.deviceGroupId, [
  23. DeviceType.冷水主机,
  24. DeviceType.控制柜,
  25. DeviceType.冷却塔,
  26. DeviceType.冷却泵,
  27. DeviceType.冷冻泵,
  28. ]);
  29. if (deviceTypes.value.length) {
  30. activeDeviceType.value = deviceTypes.value[0].deviceType;
  31. getDeviceList();
  32. }
  33. });
  34. });
  35. /**
  36. * 设备实时数据映射对象
  37. * - 以设备 id 作为 key
  38. * - 时间与设备参数的值构成的对象作为 value
  39. */
  40. type DeviceRTDMap = Record<
  41. number,
  42. {
  43. [key: string]: number | string | undefined;
  44. time?: string;
  45. }
  46. >;
  47. const deviceList = ref<DevicesListItem[]>([]);
  48. const deviceTotal = ref(0);
  49. const deviceRealTimeData = ref<DeviceRTDMap>({});
  50. const pageParams = ref<PageParams>({
  51. pageIndex: 1,
  52. pageSize: 12,
  53. pageSorts: [
  54. {
  55. column: 'id',
  56. asc: true,
  57. },
  58. ],
  59. });
  60. const deviceListEl = useTemplateRef('deviceListEl');
  61. useInfiniteScroll(
  62. deviceListEl,
  63. () => {
  64. getDeviceList();
  65. },
  66. {
  67. distance: 10,
  68. canLoadMore: () => {
  69. if (pageParams.value.pageIndex === 1 || isLoading.value) {
  70. return false;
  71. }
  72. return deviceList.value.length < deviceTotal.value;
  73. },
  74. },
  75. );
  76. const getDeviceList = () => {
  77. handleRequest(async () => {
  78. let runningStatusList = null;
  79. if (activeDeviceStatus.value === DeviceStatusQuery.Offline) {
  80. runningStatusList = [DeviceRunningStatus.Offline];
  81. } else if (activeDeviceStatus.value === DeviceStatusQuery.Online) {
  82. runningStatusList = [DeviceRunningStatus.Stop, DeviceRunningStatus.Run];
  83. }
  84. const { records, total } = await queryDevicesList({
  85. ...pageParams.value,
  86. deviceType: activeDeviceType.value,
  87. runningStatusList,
  88. });
  89. const deviceIds = records.map((item) => item.id);
  90. const deviceParamCode = deviceCardData[activeDeviceType.value]?.paramCodes || [];
  91. const data = await getDevWorkRealTimeData(activeDeviceType.value, deviceIds, deviceParamCode);
  92. const isDeviceChillerUnit = activeDeviceType.value === DeviceType.冷水主机;
  93. data.forEach((item) => {
  94. const { deviceId, deviceParamMapList, ...chillerUnitExtraParams } = item;
  95. if (!deviceRealTimeData.value[deviceId]) {
  96. deviceRealTimeData.value[deviceId] = {};
  97. }
  98. deviceParamMapList.forEach((paramItem) => {
  99. Object.assign(deviceRealTimeData.value[item.deviceId], paramItem);
  100. });
  101. if (isDeviceChillerUnit) {
  102. Object.assign(deviceRealTimeData.value[item.deviceId], chillerUnitExtraParams);
  103. }
  104. });
  105. deviceList.value.push(...records);
  106. deviceTotal.value = total;
  107. pageParams.value.pageIndex++;
  108. });
  109. };
  110. const handleTabClick = () => {
  111. deviceList.value = [];
  112. deviceTotal.value = 0;
  113. deviceRealTimeData.value = {};
  114. setTimeout(() => {
  115. pageParams.value.pageIndex = 1;
  116. getDeviceList();
  117. }, 0);
  118. };
  119. const deviceWorkParamsRef = useTemplateRef('deviceWorkParams');
  120. const currentDevId = ref<number>(0);
  121. const viewDevParam = (id: number, e: MouseEvent) => {
  122. e.stopPropagation();
  123. currentDevId.value = id;
  124. deviceWorkParamsRef.value?.showView();
  125. };
  126. const devWorkParamDataRef = useTemplateRef('devWorkParamData');
  127. const currentDevParamCodes = ref<string[]>([]);
  128. const viewHistoryData = (paramCode: string) => {
  129. currentDevParamCodes.value = [paramCode];
  130. devWorkParamDataRef.value?.showView();
  131. };
  132. /**
  133. * 使用事件委托处理设置了参数编码属性 data-param-code 的元素的点击事件,用来查看该参数的历史数据
  134. */
  135. const handleDevCardClick = (devId: number, e: Event) => {
  136. const target = e.target as HTMLElement;
  137. const { paramCode } = target.dataset;
  138. if (paramCode) {
  139. currentDevId.value = devId;
  140. viewHistoryData(paramCode);
  141. } else {
  142. router.push(`/device-manage/device-list/equipment-details/${devId}`);
  143. }
  144. };
  145. </script>
  146. <template>
  147. <div class="device-work-container">
  148. <div class="device-work-header">
  149. <ATabs
  150. class="button-tabs-card device-type-tab"
  151. v-model:active-key="activeDeviceType"
  152. type="card"
  153. @tab-click="handleTabClick"
  154. >
  155. <ATabPane v-for="item in deviceTypes" :key="item.deviceType" :tab="`${item.deviceTypeName}(${item.count})`" />
  156. </ATabs>
  157. <ATabs class="device-status-tab" v-model:active-key="activeDeviceStatus" @tab-click="handleTabClick">
  158. <ATabPane :key="DeviceStatusQuery.All" :tab="$t('common.entire')" />
  159. <ATabPane :key="DeviceStatusQuery.Online" :tab="$t('common.online')" />
  160. <ATabPane :key="DeviceStatusQuery.Offline" :tab="$t('common.offline')" />
  161. </ATabs>
  162. </div>
  163. <div ref="deviceListEl" class="device-card-list">
  164. <ARow :gutter="[22, 24]">
  165. <ACol v-for="item in deviceList" :key="item.id" :xs="24" :sm="24" :md="24" :lg="24" :xl="12" :xxl="8">
  166. <div class="device-card-container" @click="handleDevCardClick(item.id, $event)">
  167. <div class="device-card-header">
  168. <span
  169. :class="[
  170. 'status-dot',
  171. {
  172. 'device-status-offline': item.runningStatus === DeviceRunningStatus.Offline,
  173. },
  174. ]"
  175. ></span>
  176. <div class="ellipsis-text device-card-header-title">{{ item.deviceName }}</div>
  177. <div
  178. v-if="
  179. activeDeviceType === DeviceType.控制柜 &&
  180. deviceRealTimeData[item.id]?.[DevParamCtrlCabinet.系统控制模式设定]
  181. "
  182. class="ctrl-cabinet-mode"
  183. >
  184. {{ deviceRealTimeData[item.id][DevParamCtrlCabinet.系统控制模式设定] }}
  185. </div>
  186. <template
  187. v-if="
  188. activeDeviceType === DeviceType.冷水主机 &&
  189. deviceRealTimeData[item.id]?.[DevParamChillerUnit.COP] !== undefined
  190. "
  191. >
  192. <div class="device-cop-value">
  193. {{ deviceRealTimeData[item.id][DevParamChillerUnit.COP] }}
  194. </div>
  195. <!-- <div class="device-cop-level">中</div> -->
  196. </template>
  197. <span class="device-card-header-time">{{ deviceRealTimeData[item.id]?.time }}</span>
  198. <SvgIcon class="device-card-header-button" name="adjustment" @click="viewDevParam(item.id, $event)" />
  199. </div>
  200. <component
  201. :is="deviceCardData[activeDeviceType]?.component"
  202. :real-time-data="deviceRealTimeData[item.id]"
  203. :device-detail="JSON.parse(item.deviceDetail || '{}')"
  204. />
  205. </div>
  206. </ACol>
  207. </ARow>
  208. </div>
  209. <DeviceWorkParams ref="deviceWorkParams" :dev-id="currentDevId" @view-history-data="viewHistoryData" />
  210. <DevWorkParamData ref="devWorkParamData" :dev-id="currentDevId" :param-codes="currentDevParamCodes" />
  211. </div>
  212. </template>
  213. <style lang="scss" scoped>
  214. .device-work-container {
  215. display: flex;
  216. flex-direction: column;
  217. height: 100%;
  218. overflow: hidden;
  219. }
  220. .device-work-header {
  221. display: flex;
  222. align-items: center;
  223. justify-content: space-between;
  224. }
  225. .device-type-tab {
  226. width: calc(100% - 200px);
  227. }
  228. :deep(.device-status-tab) {
  229. font-weight: 500;
  230. line-height: 22px;
  231. &.ant-tabs-top > .ant-tabs-nav {
  232. .ant-tabs-tab {
  233. padding: 5px 0;
  234. + .ant-tabs-tab {
  235. margin-left: 24px;
  236. }
  237. }
  238. &::before {
  239. border: none;
  240. }
  241. }
  242. }
  243. .device-card-list {
  244. flex: 1;
  245. overflow: hidden auto;
  246. }
  247. .device-card-container {
  248. position: relative;
  249. height: 328px;
  250. padding: 16px 24px;
  251. background-color: #fff;
  252. border-radius: 12px;
  253. }
  254. .device-card-header {
  255. display: flex;
  256. align-items: center;
  257. margin-bottom: 24px;
  258. }
  259. .device-status-offline {
  260. --status-dot-rgb: 191, 191, 191; // RGB 颜色分量 (灰色)
  261. }
  262. .device-card-header-title {
  263. max-width: 150px;
  264. margin-right: 16px;
  265. margin-left: 8px;
  266. font-size: 16px;
  267. font-weight: 600;
  268. line-height: 28px;
  269. color: var(--antd-color-text);
  270. }
  271. .ctrl-cabinet-mode {
  272. width: 86px;
  273. height: 24px;
  274. font-size: 14px;
  275. font-weight: 500;
  276. line-height: 22px;
  277. color: var(--antd-color-primary);
  278. text-align: center;
  279. background: var(--antd-color-primary-opacity-10);
  280. border: 1px solid var(--antd-color-primary);
  281. border-radius: 4px;
  282. }
  283. .device-cop-value {
  284. font-family: DINAlternate;
  285. font-size: 24px;
  286. font-weight: bold;
  287. line-height: 32px;
  288. color: #e6a23c;
  289. }
  290. .device-cop-level {
  291. width: 16px;
  292. height: 16px;
  293. margin-left: 8px;
  294. font-size: 12px;
  295. font-weight: 600;
  296. line-height: 16px;
  297. color: #e6a23c;
  298. text-align: center;
  299. background: rgb(234 178 94 / 40%);
  300. border-radius: 2px;
  301. }
  302. .device-card-header-time {
  303. flex: 1;
  304. font-size: 12px;
  305. font-weight: 500;
  306. line-height: 20px;
  307. color: #999;
  308. text-align: right;
  309. }
  310. .device-card-header-button {
  311. padding: 4px;
  312. margin-left: 16px;
  313. font-size: 16px;
  314. color: var(--antd-color-primary);
  315. cursor: pointer;
  316. background: var(--antd-color-primary-opacity-15);
  317. border-radius: 4px;
  318. }
  319. :deep(.device-card-label) {
  320. height: 20px;
  321. font-size: 12px;
  322. font-weight: 500;
  323. line-height: 20px;
  324. color: #999;
  325. + .progress-text-bar {
  326. margin-top: 4px;
  327. cursor: pointer;
  328. }
  329. }
  330. :deep(.device-card-value) {
  331. height: 24px;
  332. font-family: DINAlternate;
  333. font-size: 16px;
  334. font-weight: bold;
  335. line-height: 24px;
  336. color: #333;
  337. cursor: pointer;
  338. &.device-card-no-history {
  339. cursor: default;
  340. }
  341. }
  342. </style>