index.vue 14 KB

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