index.vue 17 KB

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