index.vue 17 KB

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