index.vue 18 KB

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