index.vue 16 KB

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