index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <template>
  2. <div class="sensor-container">
  3. <a-spin :spinning="loading">
  4. <a-tabs class="tabs-box" type="card" v-model:activeKey="activeKey" @change="tabChange">
  5. <a-tab-pane key="1" tab="实时监测">
  6. <div class="box-bg table-box" style="margin-bottom: 10px">
  7. <div>
  8. <label style="color: var(--vent-font-color)">设备类型:</label>
  9. <Select
  10. @change="handleSensorChange"
  11. :options="deviceTypeOption"
  12. :fieldNames="{ label: 'label', value: 'value' }"
  13. v-model:value="deviceKind"
  14. style="width: 200px; margin-bottom: 5px; color: black"
  15. placeholder="请选择设备类型"
  16. :allowClear="true"
  17. />
  18. <template v-if="deviceKind === 'modelsensor_multi' && sysOrgCode != 'hnjmypmk'">
  19. <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXlsFns"> 导出</a-button>
  20. </template>
  21. <!--hnjmypmk 崖坪 特有 -->
  22. <template v-if="deviceKind === 'modelsensor_multi' && sysOrgCode === 'hnjmypmk'">
  23. <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXlsFn"> 导出</a-button>
  24. </template>
  25. <MonitorTable
  26. ref="SensorMonitorRef"
  27. :is-show-select="true"
  28. :columnsType="deviceKind + '_monitor'"
  29. :dataSource="dataSource"
  30. design-scope="modelsensor_monitor"
  31. @select-row="getSelectRow"
  32. :deviceType="deviceKind"
  33. :scroll="{ y: chartsColumns.length > 0 ? 600 : 600 }"
  34. size="''"
  35. title="传感器监测"
  36. >
  37. <template #filterCell="{ column, record }">
  38. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == '0' ? 'green' : 'red'">{{
  39. record.warnFlag == '0' ? '正常' : '报警'
  40. }}</a-tag>
  41. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == '0' ? 'default' : 'green'">{{
  42. record.netStatus == '0' ? '断开' : '连接'
  43. }}</a-tag>
  44. </template>
  45. </MonitorTable>
  46. </div>
  47. <!-- v-if="chartsColumns.length > 0" -->
  48. <div class="charts-box" v-if="false">
  49. <BarAndLine
  50. :chartsColumnsType="selectData.deviceType"
  51. xAxisPropType="readTime"
  52. :dataSource="detailDataSource"
  53. height="300px"
  54. :chartsColumns="chartsColumns"
  55. chartsType="detail"
  56. :option="echartsOption"
  57. @refresh="refreshEchatrs"
  58. />
  59. </div>
  60. </div>
  61. </a-tab-pane>
  62. <a-tab-pane key="2" tab="历史数据">
  63. <div class="tab-item table-box box-bg padding-0" v-if="activeKey == '2'">
  64. <HistoryTable
  65. :columns-type="deviceKind"
  66. :device-type="deviceKind"
  67. :device-list-api="list.bind(null, { devicetype: selectData.deviceType })"
  68. @change="historyDataSourceChange"
  69. designScope="modelsensor-history"
  70. :scroll="{ y: 600 }"
  71. />
  72. <!-- <div class="charts-box" v-if="chartsColumns.length > 0">
  73. <BarAndLine
  74. :chartsColumnsType="selectData.deviceType"
  75. xAxisPropType="ttime"
  76. :dataSource="historyDataSource"
  77. height="300px"
  78. :chartsColumns="chartsColumns"
  79. chartsType="history"
  80. :option="echartsOption1"
  81. @refresh="refreshEchatrs"
  82. />
  83. <DeviceHistoryChart
  84. :chartsColumnsType="selectData.deviceType"
  85. xAxisPropType="ttime"
  86. :dataSource="historyDataSource"
  87. height="300px"
  88. :chartsColumns="chartsColumns"
  89. chartsType="history"
  90. :option="echartsOption1"
  91. @refresh="refreshEchatrs"
  92. />
  93. </div> -->
  94. </div>
  95. </a-tab-pane>
  96. <a-tab-pane key="5" tab="近一月数据分析" v-if="hasPermission('ventanalyAlarmAnalysis:showMonth')">
  97. <div class="tab-item box-bg" style="margin-bottom: 10px">
  98. <div style="margin-top: 20px">
  99. <label style="color: var(--vent-font-color); margin-left: 20px">查询设备:</label>
  100. <Select
  101. :options="deviceTypeOption"
  102. :fieldNames="{ label: 'label', value: 'value' }"
  103. v-model:value="deviceKind"
  104. style="width: 200px; margin-bottom: 5px; color: black"
  105. placeholder="请选择传感器类型"
  106. :allowClear="true"
  107. />
  108. <Select
  109. @change="handleSensorChange1"
  110. :options="FxData"
  111. :fieldNames="{ label: 'strinstallpos', value: 'deviceID' }"
  112. v-model:value="strinstallpos"
  113. style="width: 200px; margin-bottom: 5px; margin-left: 5px; color: black"
  114. placeholder="请选择查询设备"
  115. :allowClear="true"
  116. />
  117. <a-button type="primary" style="margin-left: 5px" preIcon="ant-design:export-outlined" @click="onExportXlsFnFx">导出分析数据</a-button>
  118. </div>
  119. <div class="charts-box" v-if="chartsColumnsFx.length > 0">
  120. <BarAndLine
  121. :chartsColumnsType="selectData.deviceType"
  122. xAxisPropType="ttime"
  123. :dataSource="historyDataSource1"
  124. height="300px"
  125. :chartsColumns="chartsColumnsFx"
  126. chartsType="history"
  127. :option="echartsOption1"
  128. @refresh="refreshEchatrs"
  129. />
  130. </div>
  131. <div class="charts-box" v-else> <span style="color: aliceblue"> 暂无数据 </span> </div>
  132. </div>
  133. </a-tab-pane>
  134. <a-tab-pane key="6" tab="历史数据分析" v-if="hasPermission('ventanalyAlarmAnalysis:show')">
  135. <div class="history-echart-box" style="margin-bottom: 10px">
  136. <DeviceHistoryChart
  137. chartsColumnsType="modelsensor_chart"
  138. :dataSource="dataSource"
  139. height="100%"
  140. :chartsColumns="chartsColumns"
  141. device-type="modelsensor"
  142. :is-show-child-type="true"
  143. />
  144. </div>
  145. </a-tab-pane>
  146. <a-tab-pane key="3" tab="报警历史">
  147. <div class="tab-item box-bg" v-if="activeKey == '3'">
  148. <AlarmHistoryTable columns-type="alarm" device-type="modelsensor" designScope="alarm-history" />
  149. </div>
  150. </a-tab-pane>
  151. <a-tab-pane key="4" tab="报警分析">
  152. <div class="tab-item box-bg" v-if="activeKey == '4'">
  153. <warnAnalysis device-type="modelsensor" />
  154. </div>
  155. </a-tab-pane>
  156. <!-- <a-tab-pane key="4" tab="操作历史">
  157. <div class="tab-item box-bg">
  158. <HandlerHistoryTable columns-type="operator_history" device-type="modelsensor" designScope="alarm-history" />
  159. </div>
  160. </a-tab-pane> -->
  161. </a-tabs>
  162. <div class="title-text">
  163. {{ selectData.strinstallpos || selectData.strname }}
  164. </div>
  165. </a-spin>
  166. </div>
  167. </template>
  168. <script setup lang="ts">
  169. import BarAndLine from '/@/components/chart/BarAndLine.vue';
  170. import DeviceHistoryChart from '/@/views/vent/monitorManager/comment/DeviceHistoryEcharts.vue';
  171. import { Select } from 'ant-design-vue';
  172. import { onBeforeMount, computed, ref, onMounted, onUnmounted, toRaw, reactive, nextTick, unref } from 'vue';
  173. import MonitorTable from '../comment/MonitorTable.vue';
  174. import HistoryTable from '../comment/HistoryTable.vue';
  175. import AlarmHistoryTable from '../comment/AlarmHistoryTable.vue';
  176. import warnAnalysis from '../comment/warnAnalysis.vue';
  177. import { list, getTableList } from './sensor.api';
  178. import { deviceList } from '../../deviceManager/comment/pointTabel/point.api';
  179. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  180. import { cloneDeep } from 'lodash-es';
  181. import { useMethods } from '/@/hooks/system/useMethods';
  182. import { useGlobSetting } from '/@/hooks/setting';
  183. import { useRouter } from 'vue-router';
  184. import { getDictItemsByCode } from '/@/utils/dict';
  185. import { device } from '../../gas/gasPipeNet/gasPipeNet.api';
  186. import { defHttp } from '/@/utils/http/axios';
  187. import { usePermission } from '/@/hooks/web/usePermission';
  188. const router = useRouter();
  189. const { sysOrgCode } = useGlobSetting();
  190. const { exportXlsPostBlob, exportXlsGetBlob } = useMethods();
  191. const { hasPermission } = usePermission();
  192. const SensorMonitorRef = ref();
  193. const deviceBaseList = ref([]);
  194. const activeKey = ref('1');
  195. const deviceKind = ref('');
  196. const deviceId = ref('');
  197. const FxId = ref('');
  198. const IDvalue = ref('');
  199. const deviceTypeOption = ref([]);
  200. // 默认初始是第一行
  201. const selectRowIndex = ref(0);
  202. const dataSource = ref([]);
  203. interface DeviceItem {
  204. deviceID: string;
  205. strinstallpos: string;
  206. }
  207. const FxData = ref<any[]>([]);
  208. const detailDataSource = ref<any[]>([]);
  209. const historyDataSource = ref<any[]>([]);
  210. const historyDataSource1 = ref<any[]>([]);
  211. const chartsColumns = ref<any[]>([]);
  212. const chartsColumnsFx = ref<any[]>([]);
  213. const loading = ref(true);
  214. const echartsOption = {
  215. grid: {
  216. top: '20%',
  217. left: '10px',
  218. right: '5px',
  219. bottom: '5%',
  220. containLabel: true,
  221. },
  222. toolbox: {
  223. feature: {},
  224. },
  225. };
  226. const echartsOption1 = {
  227. grid: {
  228. top: '20%',
  229. left: '10px',
  230. right: '5px',
  231. bottom: '10%',
  232. containLabel: true,
  233. },
  234. toolbox: {
  235. feature: {},
  236. },
  237. };
  238. const selectData = reactive({
  239. strname: '',
  240. deviceType: '',
  241. deviceID: '',
  242. });
  243. const tabChange = (activeKeyVal) => {
  244. activeKey.value = activeKeyVal;
  245. detailDataSource.value = [];
  246. if (activeKeyVal == 1) {
  247. nextTick(() => {
  248. SensorMonitorRef.value.setSelectedRowKeys([selectData.deviceID]);
  249. });
  250. }
  251. };
  252. // https获取监测数据
  253. let timer: null | NodeJS.Timeout = null;
  254. const getMonitor = (flag?) => {
  255. if (Object.prototype.toString.call(timer) === '[object Null]') {
  256. timer = setTimeout(
  257. async () => {
  258. await getDataSource(deviceKind.value);
  259. if (timer) {
  260. timer = null;
  261. }
  262. getMonitor();
  263. },
  264. flag ? 0 : 1000
  265. );
  266. }
  267. };
  268. const getDataSource = async (devicetype) => {
  269. const type = devicetype ? devicetype : 'modelsensor';
  270. const res = await list({ devicetype: type, pagetype: 'normal' });
  271. dataSource.value = res.msgTxt[0].datalist || [];
  272. dataSource.value.map((data: any) => {
  273. const readData = data.readData;
  274. data = Object.assign(data, readData);
  275. return data;
  276. });
  277. FxData.value = [];
  278. dataSource.value.forEach((item: DeviceItem) => {
  279. FxData.value.push({
  280. strinstallpos: item.strinstallpos, // 无报错
  281. deviceID: item.deviceID, // 无报错
  282. });
  283. IDvalue.value = item.strinstallpos;
  284. });
  285. const data: any = toRaw(dataSource.value[selectRowIndex.value]); //maxarea
  286. Object.assign(selectData, data);
  287. // if (chartsColumns.value.length <= 0 && selectData.deviceType) {
  288. // handleChange(selectData.deviceType);
  289. // }a
  290. // 如果当前为监测tab
  291. if (activeKey.value === '1') {
  292. // const isHas = detailDataSource.value.find((item) => item['readTime'] === selectData['readTime']);
  293. // // 获取选中数据
  294. // if (!isHas) {
  295. // if (detailDataSource.value.length < 15) {
  296. // detailDataSource.value.push({ ...selectData });
  297. // } else {
  298. // detailDataSource.value.shift();
  299. // detailDataSource.value.push({ ...selectData });
  300. // }
  301. // }
  302. const dataList = cloneDeep(detailDataSource.value);
  303. if (dataList.length < 15) {
  304. dataList.push({ ...selectData });
  305. } else {
  306. dataList.shift();
  307. dataList.push({ ...selectData });
  308. }
  309. detailDataSource.value = dataList;
  310. }
  311. if (loading.value) {
  312. loading.value = false;
  313. }
  314. return data;
  315. };
  316. const getSelectRow = (selectRow, index) => {
  317. if (!selectRow) return;
  318. selectRowIndex.value = index;
  319. const baseData: any = deviceBaseList.value.find((baseData: any) => baseData.id === selectRow.deviceID);
  320. Object.assign(selectData, selectRow, baseData);
  321. if (selectData.deviceType) {
  322. // if (timer) {
  323. // clearTimeout(timer);
  324. // timer = undefined;
  325. // }
  326. if (activeKey.value === '1') detailDataSource.value = [];
  327. if (activeKey.value === '2') historyDataSource.value = [];
  328. handleChange(selectData.deviceType);
  329. }
  330. };
  331. // 获取设备基本信息列表
  332. const getDeviceBaseList = () => {
  333. getTableList({ pageSize: 1000 }).then((res) => {
  334. deviceBaseList.value = res.records;
  335. });
  336. };
  337. function handleChange(type) {
  338. chartsColumns.value = getTableHeaderColumns(type + '_chart');
  339. console.log('[ type ] >', type, chartsColumns.value);
  340. }
  341. function handleChangeFx(type) {
  342. chartsColumnsFx.value = getTableHeaderColumns(type + '_chart-Fx');
  343. console.log('[ type ] >', type, chartsColumnsFx.value);
  344. }
  345. function handleSensorChange(type) {
  346. loading.value = true;
  347. handleChange(type);
  348. FxData.value = [];
  349. timer = null;
  350. dataSource.value = [];
  351. detailDataSource.value = [];
  352. }
  353. async function handleSensorChange1(id) {
  354. FxId.value = id;
  355. const result = await defHttp.get({
  356. url: '/safety/ventanalyMonitorData/getDeviceAvgData',
  357. params: {
  358. deviceId: id,
  359. },
  360. });
  361. result.forEach((item) => {
  362. handleChangeFx(item.deviceKind);
  363. item.ttime = item.createTime;
  364. });
  365. historyDataSource1.value = result || [];
  366. }
  367. function refreshEchatrs() {
  368. timer = null;
  369. // getMonitor(true);
  370. console.log('echarts 刷新');
  371. }
  372. function historyDataSourceChange(dataSource) {
  373. historyDataSource.value = dataSource;
  374. if (historyDataSource.value.length > 0) handleChange(historyDataSource.value[0].gdevicetype);
  375. }
  376. //导出
  377. function onExportXlsFns() {
  378. // 判断时间间隔和查询时间区间,数据量下载大时进行提示
  379. const url = '/ventanaly-device/monitor/exportAllDeviceInfo';
  380. return exportXlsPostBlob('多参数报表', url, {
  381. devicetype: deviceKind.value,
  382. pagetype: 'normal',
  383. });
  384. }
  385. function onExportXlsFn() {
  386. // 判断时间间隔和查询时间区间,数据量下载大时进行提示
  387. const url = '/ventanaly-device/safety/reportInfo/expComReportByParam';
  388. return exportXlsPostBlob('多参数报表', url, {
  389. deviceKind: deviceKind.value.split('_')[0],
  390. deviceType: deviceKind.value,
  391. tempName: 'dcsbb',
  392. });
  393. }
  394. function onExportXlsFnFx() {
  395. // 判断时间间隔和查询时间区间,数据量下载大时进行提示
  396. const url = '/safety/ventanalyMonitorData/exportDeviceAvgData';
  397. return exportXlsGetBlob('分析数据报表', url, {
  398. deviceId: FxId.value,
  399. });
  400. }
  401. onBeforeMount(() => {
  402. getDeviceBaseList();
  403. });
  404. onMounted(async () => {
  405. let dictName = 'modelsensorkind';
  406. const route = unref(router.currentRoute);
  407. if (route.name) {
  408. const nameStrList = route.name.split('-');
  409. if (nameStrList.length > 0 && nameStrList[nameStrList.length - 1] !== 'sensorMonitor') {
  410. dictName = nameStrList[nameStrList.length - 1];
  411. }
  412. }
  413. const res = getDictItemsByCode(dictName);
  414. deviceTypeOption.value = res;
  415. deviceKind.value = deviceTypeOption.value[0]['value'];
  416. handleChange(deviceKind.value);
  417. await getMonitor(true);
  418. });
  419. onUnmounted(() => {
  420. if (timer) {
  421. clearTimeout(timer);
  422. timer = undefined;
  423. }
  424. });
  425. </script>
  426. <style lang="less" scoped>
  427. @import '/@/design/theme.less';
  428. @import '/@/design/vent/modal.less';
  429. .padding-0 {
  430. padding: 10px 0 !important;
  431. }
  432. .sensor-container {
  433. height: 100%;
  434. position: relative;
  435. top: 65px;
  436. padding: 10px;
  437. z-index: 999;
  438. // max-height: calc(100vh - 150px);
  439. .@{ventSpace}-tabs {
  440. max-height: calc(100% - 100px);
  441. .tab-item {
  442. max-height: calc(100% - 170px);
  443. overflow-y: auto;
  444. }
  445. }
  446. .title-text {
  447. position: absolute;
  448. top: -24px;
  449. left: 0;
  450. width: 100%;
  451. text-align: center;
  452. color: var(--vent-font-color);
  453. }
  454. .table-box {
  455. // height: calc(60% - 150px);
  456. height: 780px;
  457. padding: 20px 10px;
  458. overflow-y: auto;
  459. }
  460. .box-bg {
  461. // border: 1px solid #4d7ad855;
  462. // border-radius: 2px;
  463. // // background-color: #001d3055;
  464. // -webkit-backdrop-filter: blur(8px);
  465. // backdrop-filter: blur(8px);
  466. // box-shadow: 0 0 10px #5984e055 inset;
  467. // background-color: #00b3ff12;
  468. padding-bottom: 10px;
  469. border: 1px solid #44d3ff70;
  470. border-radius: 2px;
  471. -webkit-backdrop-filter: blur(8px);
  472. box-shadow: 0 0 20px #44b4ff33 inset;
  473. background-color: #ffffff11;
  474. overflow-y: auto;
  475. }
  476. .table-box-content {
  477. height: 430px;
  478. background-color: #ffffff03;
  479. border-bottom: 1px solid #44d3ff70;
  480. }
  481. .charts-box {
  482. height: 300px;
  483. padding: 5px 10px;
  484. margin-top: 10px;
  485. }
  486. .history-echart-box {
  487. height: 800px;
  488. margin-top: 20px;
  489. }
  490. }
  491. :deep(.@{ventSpace}-tabs-tabpane-active) {
  492. height: 100%;
  493. }
  494. :deep(.@{ventSpace}-tabs-card) {
  495. .@{ventSpace}-tabs-tab {
  496. background: var(--vent-device-manager-control-btn-hover);
  497. border-color: #74e9fe;
  498. border-radius: 0%;
  499. &:hover {
  500. color: #64d5ff;
  501. }
  502. }
  503. .@{ventSpace}-tabs-tab.@{ventSpace}-tabs-tab-active .@{ventSpace}-tabs-tab-btn {
  504. color: aqua;
  505. }
  506. .@{ventSpace}-tabs-nav::before {
  507. border-color: #74e9fe;
  508. }
  509. .@{ventSpace}-picker,
  510. .@{ventSpace}-select-selector {
  511. width: 100%;
  512. background: #00000017 !important;
  513. border: 1px solid @vent-form-item-border !important;
  514. input,
  515. .@{ventSpace}-select-selection-item,
  516. .@{ventSpace}-picker-suffix {
  517. color: #fff !important;
  518. }
  519. .@{ventSpace}-select-selection-placeholder {
  520. color: #b7b7b7 !important;
  521. }
  522. }
  523. .@{ventSpace}-pagination-next,
  524. .action,
  525. .@{ventSpace}-select-arrow,
  526. .@{ventSpace}-picker-separator {
  527. color: var(--vent-font-color) !important;
  528. }
  529. .@{ventSpace}-table-cell-row-hover {
  530. background: #264d8833 !important;
  531. }
  532. .@{ventSpace}-table-row-selected {
  533. background: #00c0a311 !important;
  534. td {
  535. background-color: #00000000 !important;
  536. }
  537. }
  538. .@{ventSpace}-table-thead {
  539. // background: linear-gradient(#004a8655 0%, #004a86aa 10%) !important;
  540. background: #3d9dd45d !important;
  541. & > tr > th,
  542. .@{ventSpace}-table-column-title {
  543. // color: #70f9fc !important;
  544. border-color: var(--vent-base-border) !important;
  545. border-left: none !important;
  546. border-right: none !important;
  547. padding: 7px;
  548. }
  549. }
  550. .@{ventSpace}-table-tbody {
  551. tr > td {
  552. padding: 12px;
  553. }
  554. }
  555. .@{ventSpace}-table-tbody > tr:hover.@{ventSpace}-table-row > td {
  556. background-color: #26648855 !important;
  557. }
  558. .jeecg-basic-table-row__striped {
  559. // background: #97efff11 !important;
  560. td {
  561. background-color: #97efff11 !important;
  562. }
  563. }
  564. :deep(.vent-form) {
  565. .@{ventSpace}-select-dropdown {
  566. color: #000000 !important;
  567. }
  568. }
  569. }
  570. </style>