index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <template>
  2. <div class="safetyList">
  3. <customHeader>设备监测</customHeader>
  4. <div class="content">
  5. <a-tabs class="tab-box" v-model:activeKey="activeKey" @change="onChangeTab">
  6. <a-tab-pane tab="设备监测" key="device" />
  7. <a-tab-pane tab="历史数据" key="history" />
  8. </a-tabs>
  9. <div class="box-content">
  10. <!-- 分站监测 -->
  11. <div class="now-content">
  12. <div class="left-box">
  13. <div class="device-select">
  14. <div class="device-select-box">
  15. <a-tree
  16. v-if="treeData && treeData.length > 0"
  17. :show-line="true"
  18. :tree-data="treeData"
  19. v-model:selectedKeys="selectedKeys"
  20. v-model:expandedKeys="expandedKeys"
  21. :defaultExpandAll="true"
  22. @select="onSelect"
  23. >
  24. </a-tree>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="right-box" v-if="activeKey == 'device'">
  29. <div class="right-title">实时监测:</div>
  30. <a-table
  31. size="small"
  32. :scroll="{ y: 650 }"
  33. :columns="outerColumns"
  34. :data-source="deviceList"
  35. :pagination="false"
  36. :row-key="(record) => record.id"
  37. :expand-row-by-click="true"
  38. :expanded-row-keys="expandedRowKeys"
  39. @expand="onExpand"
  40. >
  41. <!-- 自定义展开图标 -->
  42. <template #expandIcon="{ expanded, onExpand, record }">
  43. <a-button
  44. type="text"
  45. size="small"
  46. @click="
  47. (e) => {
  48. e.stopPropagation();
  49. toggleExpand(record.id);
  50. }
  51. "
  52. >
  53. <DownCircleTwoTone v-if="expandedRowKeys.includes(record.id)" />
  54. <RightCircleTwoTone v-else />
  55. </a-button>
  56. </template>
  57. <!-- 嵌套表格 -->
  58. <template #expandedRowRender="{ record }">
  59. <a-table
  60. size="small"
  61. :columns="innerColumns"
  62. :data-source="monitorList[record.id] || []"
  63. :pagination="false"
  64. :loading="loadingMap[record.id]"
  65. bordered
  66. :scroll="{ y: 410 }"
  67. >
  68. <template #bodyCell="{ column, record: innerRecord }">
  69. <template v-if="column.dataIndex === 'value'">
  70. <span>
  71. {{ innerRecord.value }}
  72. </span>
  73. </template>
  74. </template>
  75. </a-table>
  76. </template>
  77. <template #bodyCell="{ column, record }">
  78. <template v-if="column.key === 'netStatus'">
  79. <span
  80. :style="{
  81. color: record.netStatus ? '#52c41a' : '#ddd',
  82. fontWeight: '500',
  83. }"
  84. >
  85. {{ record.netStatus ? '在线' : '断开' }}
  86. </span>
  87. </template>
  88. <template v-else>
  89. {{ record[column.dataIndex] }}
  90. </template>
  91. </template>
  92. </a-table>
  93. </div>
  94. <div class="right-box" v-else-if="activeKey == 'history'">
  95. <template v-if="deviceType.startsWith('fanmain')">
  96. <HistoryTableFan class="w-100% h-100%" :device-code="`${deviceType}`" :scroll="scroll" dict-code="fan_dict" />
  97. </template>
  98. <template v-else-if="deviceType.startsWith('fanlocal')">
  99. <HistoryTableFan class="w-100% h-100%" :device-code="`${deviceType}`" :scroll="scroll" dict-code="fanlocal_dict" />s
  100. </template>
  101. <template v-else>
  102. <HistoryTable
  103. ref="historyTable"
  104. :sysId="systemID"
  105. :columns-type="`${deviceType}`"
  106. :device-type="deviceType"
  107. designScope="device-history"
  108. :scroll="scroll"
  109. />
  110. </template>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. </template>
  117. <script setup lang="ts">
  118. import { ref, nextTick, reactive, onMounted, onUnmounted, watch, shallowRef, computed } from 'vue';
  119. import { usePermission } from '/@/hooks/web/usePermission';
  120. import customHeader from '/@/components/vent/customHeader.vue';
  121. import { message, TreeProps } from 'ant-design-vue';
  122. import { getDeviceTypeList, getDeviceListByType, getDevMonitorListById } from './device.api';
  123. import HistoryTableFan from './history/HistoryTableFan.vue';
  124. import HistoryTable from './history/HistoryTable.vue';
  125. import { RightCircleTwoTone, DownCircleTwoTone } from '@ant-design/icons-vue';
  126. import { useRoute } from 'vue-router';
  127. import { useListPage } from '/@/hooks/system/useListPage';
  128. import { BasicTable } from '/@/components/Table';
  129. import { FormSchema } from '/@/components/Form/index';
  130. let route = useRoute();
  131. const { hasPermission } = usePermission();
  132. let activeKey = ref('device');
  133. const treeData = ref<TreeProps['treeData']>([]);
  134. const selectedKeys = ref<string[]>([]);
  135. const expandedKeys = ref<string[]>([]);
  136. const AllNodeKeys = ref<string[]>([]);
  137. const deviceType = ref(''); // 监测设备类型
  138. const systemType = ref('');
  139. const systemID = ref(''); // 系统监测时,系统id
  140. const dataSource = shallowRef([]); // 实时监测数据
  141. let startMonitorTimer = 0;
  142. const monitorTable = ref();
  143. const isRefresh = ref(true);
  144. const treeNodeTitle = ref(''); // 选中的树形标题
  145. const deviceList = ref<any[]>([]); // 设备列表
  146. const monitorList = ref<Record<string, any[]>>({}); // 监测数据列表
  147. // 当前展开的行key数组
  148. const expandedRowKeys = ref([]);
  149. const scroll = reactive({
  150. y: 680,
  151. });
  152. // 加载状态映射
  153. const loadingMap = reactive({});
  154. // 切换tab页面
  155. async function onChangeTab(tab) {
  156. activeKey.value = tab;
  157. if (activeKey.value == 'device') {
  158. // 获取监测接口
  159. } else if (activeKey.value == 'history') {
  160. // 获取历史数据
  161. }
  162. }
  163. //树形菜单选择事件
  164. const onSelect: TreeProps['onSelect'] = (keys, e) => {
  165. deviceType.value = '';
  166. systemID.value = '';
  167. deviceList.value = [];
  168. const title = e.node.title;
  169. if (e.node.parent && e.node.parent.node.type.toString().startsWith('sys')) {
  170. systemType.value = e.node.parent.node.type;
  171. if (deviceType.value != e.node.parent.node.type) deviceType.value = e.node.parent.node.type;
  172. systemID.value = e.node.type;
  173. } else {
  174. systemType.value = e.node.type;
  175. if (deviceType.value != e.node.type) deviceType.value = e.node.type;
  176. }
  177. getDeviceList(deviceType.value);
  178. };
  179. // 获取所有节点key的函数
  180. const getAllNodeKeys = (nodes, type) => {
  181. const keys = [];
  182. const traverse = (nodeList) => {
  183. nodeList.forEach((node) => {
  184. if (node.type === type) {
  185. selectedKeys.value.push(node.key);
  186. }
  187. keys.push(node.key);
  188. if (node.children && node.children.length > 0) {
  189. traverse(node.children);
  190. }
  191. });
  192. };
  193. traverse(nodes);
  194. return keys;
  195. };
  196. // 获取树形菜单数据
  197. async function getDeviceType(type?) {
  198. const result = await getDeviceTypeList({});
  199. if (result.length > 0) {
  200. const dataSource = [];
  201. let key = '0';
  202. const getData = (resultList, dataSourceList, keyVal) => {
  203. resultList.forEach((item, index) => {
  204. const children = item.children ? getData(item.children, [], `${keyVal}-${index}`) : [];
  205. dataSourceList.push({
  206. children: children,
  207. title: item.itemText,
  208. key: `${keyVal}-${index}`,
  209. type: item.itemValue,
  210. parentKey: `${keyVal}`,
  211. });
  212. });
  213. return dataSourceList;
  214. };
  215. treeData.value = getData(result, dataSource, key);
  216. // 数据就绪后设置展开key数组
  217. expandedKeys.value = getAllNodeKeys(treeData.value, type);
  218. }
  219. }
  220. // 获取当前选择节点
  221. // 根据选择设备获取设备列表
  222. async function getDeviceList(deviceTypeVal?: any) {
  223. // 1. 如果没有设备类型值,停止定时器并返回(不再重复请求)
  224. if (!deviceTypeVal) {
  225. if (timer) {
  226. clearInterval(timer);
  227. timer = undefined;
  228. }
  229. return;
  230. }
  231. if (timer) {
  232. clearInterval(timer);
  233. timer = undefined;
  234. }
  235. const fetchDeviceData = async () => {
  236. const params: any = {
  237. devKind: deviceTypeVal,
  238. };
  239. try {
  240. const result = await getDeviceListByType(params);
  241. deviceList.value = result.records; // 更新设备列表
  242. } catch (error) {
  243. console.error('定时请求设备列表失败:', error);
  244. }
  245. };
  246. await fetchDeviceData();
  247. timer = setInterval(fetchDeviceData, 2000); // 2000ms = 2秒
  248. }
  249. // 外层表格列配置
  250. const outerColumns = [
  251. {
  252. title: '设备ID',
  253. dataIndex: 'id',
  254. key: 'id',
  255. align: 'center',
  256. },
  257. {
  258. title: '安装位置',
  259. dataIndex: 'strinstallpos',
  260. key: 'strinstallpos',
  261. align: 'center',
  262. },
  263. {
  264. title: '设备类型',
  265. dataIndex: 'devicekind_dictText',
  266. key: 'devicekind_dictText',
  267. align: 'center',
  268. },
  269. {
  270. title: '状态',
  271. dataIndex: 'netStatus',
  272. key: 'netStatus',
  273. align: 'center',
  274. },
  275. ];
  276. // 内层表格列配置
  277. const innerColumns = [
  278. {
  279. title: '地址',
  280. dataIndex: 'plcAddr',
  281. key: 'plcAddr',
  282. align: 'center',
  283. },
  284. {
  285. title: '数据code',
  286. dataIndex: 'valueCode',
  287. align: 'center',
  288. key: 'valueCode',
  289. },
  290. {
  291. title: '数据名称',
  292. dataIndex: 'valueName',
  293. align: 'center',
  294. key: 'valueName',
  295. },
  296. {
  297. title: '数据值',
  298. dataIndex: 'value',
  299. align: 'center',
  300. key: 'value',
  301. },
  302. {
  303. title: '时间',
  304. dataIndex: 'time',
  305. align: 'center',
  306. key: 'time',
  307. },
  308. ];
  309. // 切换展开状态
  310. const toggleExpand = (deviceId) => {
  311. const index = expandedRowKeys.value.indexOf(deviceId);
  312. if (index > -1) {
  313. // 如果已经展开,则关闭
  314. expandedRowKeys.value.splice(index, 1);
  315. if (timer) {
  316. clearInterval(timer);
  317. timer = undefined;
  318. }
  319. } else {
  320. // 如果未展开,则打开
  321. expandedRowKeys.value.push(deviceId);
  322. loadMonitoringData(deviceId);
  323. }
  324. };
  325. // 加载监测数据
  326. let timer: null | NodeJS.Timeout = null;
  327. async function loadMonitoringData(deviceId: string) {
  328. // 先清除之前的定时器
  329. if (timer) {
  330. clearInterval(timer);
  331. timer = null;
  332. }
  333. // 定时器会在1秒后开始,所以先手动加载一次
  334. refreshData(deviceId);
  335. // 设置新的定时器
  336. timer = setInterval(() => {
  337. refreshData(deviceId);
  338. }, 1000);
  339. }
  340. async function refreshData(deviceId: string) {
  341. // 这里实现具体的请求逻辑
  342. const device = deviceList.value.find((d) => d.id === deviceId);
  343. const result = await getDevMonitorListById({ devId: deviceId.toString() });
  344. monitorList.value[deviceId] = Object.values(result.readData);
  345. console.log(monitorList.value[deviceId], '123123');
  346. }
  347. onMounted(() => {
  348. const path = route.query.deviceType;
  349. if (path) {
  350. getDeviceType(path);
  351. getDeviceList(path);
  352. } else {
  353. getDeviceType();
  354. }
  355. });
  356. onUnmounted(() => {
  357. if (timer) {
  358. clearInterval(timer);
  359. timer = undefined;
  360. }
  361. });
  362. // 监听分页变化
  363. </script>
  364. <style lang="less" scoped>
  365. .safetyList {
  366. width: calc(100% - 20px);
  367. height: calc(100% - 80px);
  368. position: relative;
  369. margin: 70px 10px 10px 10px;
  370. .content {
  371. position: relative;
  372. width: 100%;
  373. height: 100%;
  374. .tab-box {
  375. display: flex;
  376. color: #fff;
  377. position: relative;
  378. background: linear-gradient(#001325, #012e4f);
  379. :deep(.zxm-tabs-nav) {
  380. margin: 0 !important;
  381. .zxm-tabs-tab {
  382. width: 180px;
  383. height: 45px;
  384. background: url('/@/assets/images/top-btn.png') center no-repeat;
  385. background-size: cover;
  386. display: flex;
  387. justify-content: center;
  388. font-size: 16px;
  389. }
  390. .zxm-tabs-tab-active {
  391. width: 180px;
  392. position: relative;
  393. background: url('/@/assets/images/top-btn-select.png') center no-repeat;
  394. background-size: cover;
  395. .zxm-tabs-tab-btn {
  396. color: #fff !important;
  397. }
  398. }
  399. .zxm-tabs-ink-bar {
  400. width: 0 !important;
  401. }
  402. .zxm-tabs-tab + .zxm-tabs-tab {
  403. margin: 0 !important;
  404. }
  405. }
  406. }
  407. .box-content {
  408. height: calc(100% - 50px);
  409. padding-top: 10px;
  410. box-sizing: border-box;
  411. .now-content {
  412. position: relative;
  413. width: 100%;
  414. height: 100%;
  415. display: flex;
  416. justify-content: space-between;
  417. align-items: center;
  418. .left-box {
  419. width: 20%;
  420. height: 100%;
  421. margin-right: 15px;
  422. padding: 10px;
  423. box-sizing: border-box;
  424. background: url('/@/assets/images/fire/bj1.png') no-repeat center;
  425. background-size: 100% 100%;
  426. border: 3px, solid, #0b69b6;
  427. border-radius: 5px;
  428. }
  429. .right-box {
  430. width: calc(80% - 15px);
  431. height: 100%;
  432. padding: 10px;
  433. box-sizing: border-box;
  434. background: url('/@/assets/images/fire/bj1.png') no-repeat center;
  435. background-size: 100% 100%;
  436. border: 3px, solid, #0b69b6;
  437. border-radius: 5px;
  438. .right-title {
  439. display: flex;
  440. height: 30px;
  441. align-items: center;
  442. font-size: 14px;
  443. color: #fff;
  444. margin-bottom: 10px;
  445. }
  446. }
  447. }
  448. }
  449. }
  450. }
  451. .down-btn {
  452. line-height: 15px;
  453. height: 20px;
  454. padding: 0px 17px;
  455. font-size: 12px;
  456. }
  457. .zxm-form {
  458. width: 50%;
  459. height: 100%;
  460. padding-top: 20px !important;
  461. box-sizing: border-box;
  462. }
  463. .zxm-picker,
  464. .zxm-input {
  465. border: 1px solid #3ad8ff77 !important;
  466. background-color: #ffffff !important;
  467. color: #fff !important;
  468. }
  469. .card-item.selected {
  470. border: 2px solid #3ad8ff77;
  471. /* 选中时的边框颜色 */
  472. }
  473. ::v-deep(.zxm-radio-wrapper) {
  474. font-size: 12px;
  475. }
  476. ::v-deep(.zxm-input) {
  477. font-size: 12px;
  478. }
  479. ::v-deep(.zxm-select:not(.zxm-select-customize-input) .zxm-select-selector) {
  480. border: 1px solid #3ad8ff77 !important;
  481. }
  482. // ::v-deep(.zxm-select-selection-item) {
  483. // color: #fff ;
  484. // }
  485. // ::v-deep(.zxm-form-item-label > label) {
  486. // color: #fff !important;
  487. // }
  488. /* 值样式 */
  489. .high-value {
  490. color: #f5222d;
  491. font-weight: bold;
  492. }
  493. .low-value {
  494. color: #1890ff;
  495. font-weight: bold;
  496. }
  497. .normal-value {
  498. color: #52c41a;
  499. }
  500. /* 嵌套表格样式 */
  501. :deep(.ant-table-expanded-row) > td {
  502. background-color: #f9f9f9 !important;
  503. padding: 0 !important;
  504. }
  505. :deep(.ant-table-expanded-row .ant-table) {
  506. margin: -10px -8px;
  507. background: #f9f9f9;
  508. }
  509. /* 自定义展开按钮 */
  510. :deep(.ant-table-row-expand-icon) {
  511. margin-right: 8px;
  512. }
  513. .device-select-box {
  514. margin-top: 30px;
  515. width: 300px;
  516. height: calc(100% - 70px);
  517. overflow-y: auto;
  518. color: #fff;
  519. :deep(.zxm-tree) {
  520. background: transparent !important;
  521. color: #fff !important;
  522. .zxm-tree-switcher {
  523. background: transparent !important;
  524. }
  525. .zxm-tree-node-content-wrapper.zxm-tree-node-selected {
  526. background-color: #00b1c8;
  527. }
  528. .zxm-tree-node-content-wrapper:hover {
  529. background-color: #00b1c8;
  530. }
  531. input {
  532. height: 0px !important;
  533. }
  534. }
  535. &::-webkit-scrollbar-track {
  536. -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  537. border-radius: 10px;
  538. background: #ededed22;
  539. height: 100px;
  540. }
  541. &::-webkit-scrollbar-thumb {
  542. -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  543. background: #4288a444;
  544. }
  545. }
  546. .device-select {
  547. width: 280px !important;
  548. height: calc(100% - 70px);
  549. background: var(--image-tree-bg) no-repeat;
  550. position: fixed;
  551. top: 100px;
  552. left: 55px;
  553. background-size: contain;
  554. pointer-events: auto;
  555. padding: 20px 10px 30px 10px;
  556. }
  557. /* 在线状态 - 绿色 */
  558. .status-online {
  559. color: #36d399; /* 可替换为其他绿色,如 #00C48C */
  560. font-weight: 500;
  561. }
  562. /* 断开状态 - 灰色(可选调整为红色) */
  563. .status-offline {
  564. color: #999;
  565. /* 若想断开显示红色:color: #F5222D; */
  566. }
  567. </style>
  568. <style>
  569. div[aria-hidden='true'] {
  570. display: none !important;
  571. }
  572. </style>