index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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="false"
  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 ? 400 : 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="3" tab="报警历史">
  84. <div class="tab-item box-bg" v-if="activeKey == '3'">
  85. <AlarmHistoryTable columns-type="alarm" device-type="modelsensor" designScope="alarm-history" />
  86. </div>
  87. </a-tab-pane>
  88. <a-tab-pane key="4" tab="预警分析">
  89. <div class="tab-item box-bg" v-if="activeKey == '4'">
  90. <warnAnalysis></warnAnalysis>
  91. </div>
  92. </a-tab-pane>
  93. <!-- <a-tab-pane key="4" tab="操作历史">
  94. <div class="tab-item box-bg">
  95. <HandlerHistoryTable columns-type="operator_history" device-type="modelsensor" designScope="alarm-history" />
  96. </div>
  97. </a-tab-pane> -->
  98. </a-tabs>
  99. <div class="title-text">
  100. {{ selectData.strinstallpos || selectData.strname }}
  101. </div>
  102. </a-spin>
  103. </div>
  104. </template>
  105. <script setup lang="ts">
  106. import BarAndLine from '/@/components/chart/BarAndLine.vue';
  107. import { Select } from 'ant-design-vue';
  108. import { onBeforeMount, ref, onMounted, onUnmounted, toRaw, reactive, nextTick, unref } from 'vue';
  109. import MonitorTable from '../comment/MonitorTable.vue';
  110. import HistoryTable from '../comment/HistoryTable.vue';
  111. import AlarmHistoryTable from '../comment/AlarmHistoryTable.vue';
  112. import warnAnalysis from '../comment/warnAnalysis.vue'
  113. import { list, getTableList } from './sensor.api';
  114. import { deviceList } from '../../deviceManager/comment/pointTabel/point.api';
  115. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  116. import { cloneDeep } from 'lodash-es';
  117. import { useMethods } from '/@/hooks/system/useMethods';
  118. import { useGlobSetting } from '/@/hooks/setting';
  119. import { useRouter } from 'vue-router';
  120. import { getDictItemsByCode } from '/@/utils/dict';
  121. const router = useRouter();
  122. const { sysOrgCode } = useGlobSetting();
  123. const { exportXlsPostBlob } = useMethods();
  124. const SensorMonitorRef = ref();
  125. const deviceBaseList = ref([]);
  126. const activeKey = ref('1');
  127. const deviceKind = ref('');
  128. const deviceTypeOption = ref([]);
  129. // 默认初始是第一行
  130. const selectRowIndex = ref(0);
  131. const dataSource = ref([]);
  132. const detailDataSource = ref<any[]>([]);
  133. const historyDataSource = ref<any[]>([]);
  134. const chartsColumns = ref<any[]>([]);
  135. const loading = ref(true);
  136. const echartsOption = {
  137. grid: {
  138. top: '20%',
  139. left: '10px',
  140. right: '5px',
  141. bottom: '5%',
  142. containLabel: true,
  143. },
  144. toolbox: {
  145. feature: {},
  146. },
  147. };
  148. const echartsOption1 = {
  149. grid: {
  150. top: '20%',
  151. left: '10px',
  152. right: '5px',
  153. bottom: '10%',
  154. containLabel: true,
  155. },
  156. toolbox: {
  157. feature: {},
  158. },
  159. };
  160. const selectData = reactive({
  161. strname: '',
  162. deviceType: '',
  163. deviceID: '',
  164. });
  165. const tabChange = (activeKeyVal) => {
  166. activeKey.value = activeKeyVal;
  167. detailDataSource.value = [];
  168. if (activeKeyVal == 1) {
  169. nextTick(() => {
  170. SensorMonitorRef.value.setSelectedRowKeys([selectData.deviceID]);
  171. });
  172. }
  173. };
  174. // https获取监测数据
  175. let timer: null | NodeJS.Timeout = null;
  176. const getMonitor = (flag?) => {
  177. if (Object.prototype.toString.call(timer) === '[object Null]') {
  178. timer = setTimeout(
  179. async () => {
  180. await getDataSource(deviceKind.value);
  181. if (timer) {
  182. timer = null;
  183. }
  184. getMonitor();
  185. },
  186. flag ? 0 : 1000
  187. );
  188. }
  189. };
  190. const getDataSource = async (devicetype) => {
  191. const type = devicetype ? devicetype : 'modelsensor';
  192. const res = await list({ devicetype: type, pagetype: 'normal' });
  193. dataSource.value = res.msgTxt[0].datalist || [];
  194. dataSource.value.map((data: any) => {
  195. const readData = data.readData;
  196. data = Object.assign(data, readData);
  197. return data;
  198. });
  199. const data: any = toRaw(dataSource.value[selectRowIndex.value]); //maxarea
  200. Object.assign(selectData, data);
  201. // if (chartsColumns.value.length <= 0 && selectData.deviceType) {
  202. // handleChange(selectData.deviceType);
  203. // }
  204. // 如果当前为监测tab
  205. if (activeKey.value === '1') {
  206. // const isHas = detailDataSource.value.find((item) => item['readTime'] === selectData['readTime']);
  207. // // 获取选中数据
  208. // if (!isHas) {
  209. // if (detailDataSource.value.length < 15) {
  210. // detailDataSource.value.push({ ...selectData });
  211. // } else {
  212. // detailDataSource.value.shift();
  213. // detailDataSource.value.push({ ...selectData });
  214. // }
  215. // }
  216. const dataList = cloneDeep(detailDataSource.value);
  217. if (dataList.length < 15) {
  218. dataList.push({ ...selectData });
  219. } else {
  220. dataList.shift();
  221. dataList.push({ ...selectData });
  222. }
  223. detailDataSource.value = dataList;
  224. }
  225. if (loading.value) {
  226. loading.value = false;
  227. }
  228. return data;
  229. };
  230. const getSelectRow = (selectRow, index) => {
  231. if (!selectRow) return;
  232. selectRowIndex.value = index;
  233. const baseData: any = deviceBaseList.value.find((baseData: any) => baseData.id === selectRow.deviceID);
  234. Object.assign(selectData, selectRow, baseData);
  235. if (selectData.deviceType) {
  236. // if (timer) {
  237. // clearTimeout(timer);
  238. // timer = undefined;
  239. // }
  240. if (activeKey.value === '1') detailDataSource.value = [];
  241. if (activeKey.value === '2') historyDataSource.value = [];
  242. handleChange(selectData.deviceType);
  243. }
  244. };
  245. // 获取设备基本信息列表
  246. const getDeviceBaseList = () => {
  247. getTableList({ pageSize: 1000 }).then((res) => {
  248. deviceBaseList.value = res.records;
  249. });
  250. };
  251. function handleChange(type) {
  252. chartsColumns.value = getTableHeaderColumns(type + '_chart');
  253. console.log('[ type ] >', type, chartsColumns.value);
  254. }
  255. function handleSensorChange(type) {
  256. loading.value = true;
  257. handleChange(type);
  258. timer = null;
  259. dataSource.value = [];
  260. detailDataSource.value = [];
  261. }
  262. function refreshEchatrs() {
  263. timer = null;
  264. // getMonitor(true);
  265. console.log('echarts 刷新');
  266. }
  267. function historyDataSourceChange(dataSource) {
  268. historyDataSource.value = dataSource;
  269. if (historyDataSource.value.length > 0) handleChange(historyDataSource.value[0].gdevicetype);
  270. }
  271. function onExportXlsFn() {
  272. // 判断时间间隔和查询时间区间,数据量下载大时进行提示
  273. const url = '/ventanaly-device/safety/reportInfo/expComReportByParam';
  274. return exportXlsPostBlob('多参数报表', url, {
  275. deviceKind: deviceKind.value.split('_')[0],
  276. deviceType: deviceKind.value,
  277. tempName: 'dcsbb',
  278. });
  279. }
  280. onBeforeMount(() => {
  281. getDeviceBaseList();
  282. });
  283. onMounted(async () => {
  284. let dictName = 'modelsensorkind';
  285. const route = unref(router.currentRoute);
  286. if (route.name) {
  287. const nameStrList = route.name.split('-');
  288. if (nameStrList.length > 0 && nameStrList[nameStrList.length - 1] !== 'sensorMonitor') {
  289. dictName = nameStrList[nameStrList.length - 1];
  290. }
  291. }
  292. const res = getDictItemsByCode(dictName);
  293. deviceTypeOption.value = res;
  294. deviceKind.value = deviceTypeOption.value[0]['value'];
  295. handleChange(deviceKind.value);
  296. await getMonitor(true);
  297. });
  298. onUnmounted(() => {
  299. if (timer) {
  300. clearTimeout(timer);
  301. timer = undefined;
  302. }
  303. });
  304. </script>
  305. <style lang="less" scoped>
  306. @import '/@/design/theme.less';
  307. @import '/@/design/vent/modal.less';
  308. .padding-0 {
  309. padding: 10px 0 !important;
  310. }
  311. .sensor-container {
  312. height: 100%;
  313. position: relative;
  314. top: 65px;
  315. padding: 10px;
  316. z-index: 999;
  317. // max-height: calc(100vh - 150px);
  318. .@{ventSpace}-tabs {
  319. max-height: calc(100% - 100px);
  320. .tab-item {
  321. max-height: calc(100% - 170px);
  322. overflow-y: auto;
  323. }
  324. }
  325. .title-text {
  326. position: absolute;
  327. top: -24px;
  328. left: 0;
  329. width: 100%;
  330. text-align: center;
  331. color: var(--vent-font-color);
  332. }
  333. .table-box {
  334. // height: calc(60% - 150px);
  335. height: 780px;
  336. padding: 20px 10px;
  337. overflow-y: auto;
  338. }
  339. .box-bg {
  340. // border: 1px solid #4d7ad855;
  341. // border-radius: 2px;
  342. // // background-color: #001d3055;
  343. // -webkit-backdrop-filter: blur(8px);
  344. // backdrop-filter: blur(8px);
  345. // box-shadow: 0 0 10px #5984e055 inset;
  346. // background-color: #00b3ff12;
  347. padding-bottom: 10px;
  348. border: 1px solid #44d3ff70;
  349. border-radius: 2px;
  350. -webkit-backdrop-filter: blur(8px);
  351. box-shadow: 0 0 20px #44b4ff33 inset;
  352. background-color: #ffffff11;
  353. overflow-y: auto;
  354. }
  355. .charts-box {
  356. height: calc(40% - 80px);
  357. padding: 5px 10px;
  358. margin-top: 10px;
  359. }
  360. }
  361. :deep(.@{ventSpace}-tabs-tabpane-active) {
  362. height: 100%;
  363. }
  364. :deep(.@{ventSpace}-tabs-card) {
  365. .@{ventSpace}-tabs-tab {
  366. background: var(--vent-device-manager-control-btn-hover);
  367. border-color: #74e9fe;
  368. border-radius: 0%;
  369. &:hover {
  370. color: #64d5ff;
  371. }
  372. }
  373. .@{ventSpace}-tabs-tab.@{ventSpace}-tabs-tab-active .@{ventSpace}-tabs-tab-btn {
  374. color: aqua;
  375. }
  376. .@{ventSpace}-tabs-nav::before {
  377. border-color: #74e9fe;
  378. }
  379. .@{ventSpace}-picker,
  380. .@{ventSpace}-select-selector {
  381. width: 100% !important;
  382. background: #00000017 !important;
  383. border: 1px solid @vent-form-item-border !important;
  384. input,
  385. .@{ventSpace}-select-selection-item,
  386. .@{ventSpace}-picker-suffix {
  387. color: #fff !important;
  388. }
  389. .@{ventSpace}-select-selection-placeholder {
  390. color: #b7b7b7 !important;
  391. }
  392. }
  393. .@{ventSpace}-pagination-next,
  394. .action,
  395. .@{ventSpace}-select-arrow,
  396. .@{ventSpace}-picker-separator {
  397. color: var(--vent-font-color) !important;
  398. }
  399. .@{ventSpace}-table-cell-row-hover {
  400. background: #264d8833 !important;
  401. }
  402. .@{ventSpace}-table-row-selected {
  403. background: #00c0a311 !important;
  404. td {
  405. background-color: #00000000 !important;
  406. }
  407. }
  408. .@{ventSpace}-table-thead {
  409. // background: linear-gradient(#004a8655 0%, #004a86aa 10%) !important;
  410. background: #3d9dd45d !important;
  411. & > tr > th,
  412. .@{ventSpace}-table-column-title {
  413. // color: #70f9fc !important;
  414. border-color: var(--vent-base-border) !important;
  415. border-left: none !important;
  416. border-right: none !important;
  417. padding: 7px;
  418. }
  419. }
  420. .@{ventSpace}-table-tbody {
  421. tr > td {
  422. padding: 12px;
  423. }
  424. }
  425. .@{ventSpace}-table-tbody > tr:hover.@{ventSpace}-table-row > td {
  426. background-color: #26648855 !important;
  427. }
  428. .jeecg-basic-table-row__striped {
  429. // background: #97efff11 !important;
  430. td {
  431. background-color: #97efff11 !important;
  432. }
  433. }
  434. :deep(.vent-form) {
  435. .@{ventSpace}-select-dropdown {
  436. color: #000000 !important;
  437. }
  438. }
  439. }
  440. </style>