index.vue 16 KB

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