index.vue 14 KB

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