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