index1.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <div class="sensor-container">
  3. <a-tabs class="tabs-box" type="card" v-model:activeKey="activeKey" @change="tabChange">
  4. <a-tab-pane key="1" tab="实时预警">
  5. <div class="box-bg table-box" style="margin-bottom: 10px">
  6. <label style="color: #fff">设备类型:</label>
  7. <MonitorTable
  8. ref="SensorMonitorRef"
  9. columnsType="alarm_history"
  10. :dataSource="dataSource"
  11. design-scope="alarm"
  12. @select-row="getSelectRow"
  13. :formConfi="formConfig"
  14. title="传感器监测"
  15. >
  16. <template #filterCell="{ column, record }">
  17. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == 0 ? 'green' : 'red'">{{
  18. record.warnFlag == 0 ? '正常' : '报警'
  19. }}</a-tag>
  20. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == '0' ? '#f00' : 'green'">{{
  21. record.netStatus == '0' ? '断开' : '连接'
  22. }}</a-tag>
  23. </template>
  24. </MonitorTable>
  25. </div>
  26. <div class="charts-box box-bg">
  27. <BarAndLine
  28. v-if="chartsColumns.length > 0"
  29. :chartsColumnsType="selectData.deviceType"
  30. xAxisPropType="readTime"
  31. :dataSource="detailDataSource"
  32. height="100%"
  33. :chartsColumns="chartsColumns"
  34. chartsType="detail"
  35. :option="echartsOption"
  36. @refresh="refreshEchatrs"
  37. />
  38. </div>
  39. </a-tab-pane>
  40. <a-tab-pane key="2" tab="实时报警">
  41. <div class="tab-item table-box box-bg padding-0">
  42. <HistoryTable
  43. columns-type="modelsensor"
  44. device-type="modelsensor"
  45. :device-list-api="baseList"
  46. @change="historyDataSourceChange"
  47. designScope="modelsensor-history"
  48. />
  49. </div>
  50. <div class="charts-box box-bg">
  51. <BarAndLine
  52. v-if="chartsColumns.length > 0"
  53. :chartsColumnsType="selectData.deviceType"
  54. xAxisPropType="gcreatetime"
  55. :dataSource="historyDataSource"
  56. height="100%"
  57. :chartsColumns="chartsColumns"
  58. chartsType="history"
  59. :option="echartsOption1"
  60. @refresh="refreshEchatrs"
  61. />
  62. </div>
  63. </a-tab-pane>
  64. <a-tab-pane key="3" tab="报警历史">
  65. <div class="tab-item box-bg">
  66. <AlarmHistoryTable columns-type="alarm" device-type="modelsensor" :device-list-api="baseList" designScope="alarm-history" />
  67. </div>
  68. </a-tab-pane>
  69. </a-tabs>
  70. <div class="title-text">
  71. {{ selectData.strname }}
  72. </div>
  73. </div>
  74. </template>
  75. <script setup lang="ts">
  76. import BarAndLine from '/@/components/chart/BarAndLine.vue';
  77. import { onBeforeMount, ref, onMounted, onUnmounted, toRaw, reactive, nextTick } from 'vue';
  78. import MonitorTable from '../comment/MonitorTable.vue';
  79. import HistoryTable from '../comment/HistoryTable.vue';
  80. import AlarmHistoryTable from '../comment/AlarmHistoryTable.vue';
  81. import { warningList } from './alarm.api';
  82. import { formConfig } from './alarm.data';
  83. import { deviceList } from '../../deviceManager/comment/pointTabel/point.api';
  84. const SensorMonitorRef = ref();
  85. const deviceBaseList = ref([]);
  86. const activeKey = ref('1');
  87. const deviceKind = ref('');
  88. const deviceTypeOption = ref([]);
  89. // 默认初始是第一行
  90. const selectRowIndex = ref(0);
  91. const dataSource = ref([]);
  92. const detailDataSource = ref<any[]>([]);
  93. const historyDataSource = ref<any[]>([]);
  94. const chartsColumns = ref<any[]>([]);
  95. const echartsOption = {
  96. grid: {
  97. top: '20%',
  98. left: '10px',
  99. right: '5px',
  100. bottom: '5%',
  101. containLabel: true,
  102. },
  103. toolbox: {
  104. feature: {},
  105. },
  106. };
  107. const selectData = reactive({
  108. strname: '',
  109. deviceType: '',
  110. deviceID: '',
  111. });
  112. const tabChange = (activeKeyVal) => {
  113. activeKey.value = activeKeyVal;
  114. };
  115. // https获取监测数据
  116. let timer: null | NodeJS.Timeout = null;
  117. const getMonitor = (flag = false) => {
  118. if (Object.prototype.toString.call(timer) === '[object Null]') {
  119. timer = setTimeout(
  120. async () => {
  121. await getDataSource();
  122. if (timer) {
  123. timer = null;
  124. }
  125. getMonitor();
  126. },
  127. flag ? 0 : 1000
  128. );
  129. }
  130. };
  131. const getDataSource = async () => {
  132. const res = await warningList({});
  133. dataSource.value = res.list.records || [];
  134. // if(dataSource.value.length > 0){
  135. // dataSource.value.map((data: any) => {
  136. // const readData = data.readData;
  137. // data = Object.assign(data, readData);
  138. // return data;
  139. // });
  140. // }
  141. };
  142. const getSelectRow = (selectRow, index) => {
  143. if (!selectRow) return;
  144. selectRowIndex.value = index;
  145. const baseData: any = deviceBaseList.value.find((baseData: any) => baseData.id === selectRow.deviceID);
  146. Object.assign(selectData, selectRow, baseData);
  147. if (selectData.deviceType) {
  148. if (timer) {
  149. clearTimeout(timer);
  150. timer = undefined;
  151. }
  152. if (activeKey.value === '1') detailDataSource.value = [];
  153. if (activeKey.value === '2') historyDataSource.value = [];
  154. handleChange(selectData.deviceType);
  155. }
  156. };
  157. function handleChange(type) {
  158. if (type === 'modelsensor_multi') {
  159. chartsColumns.value = [
  160. {
  161. legend: '气压值',
  162. seriesName: '(Pa)',
  163. ymax: 50,
  164. yname: 'Pa',
  165. linetype: 'bar',
  166. yaxispos: 'left',
  167. color: '#37BCF2',
  168. sort: 1,
  169. xRotate: 0,
  170. dataIndex: 'pa',
  171. },
  172. {
  173. legend: '温度',
  174. seriesName: '(℃)',
  175. ymax: 50,
  176. yname: '℃',
  177. linetype: 'bar',
  178. yaxispos: 'right',
  179. color: '#FC4327',
  180. sort: 2,
  181. xRotate: 0,
  182. dataIndex: 'temperature',
  183. },
  184. ];
  185. } else if (type === 'modelsensor_smoke') {
  186. chartsColumns.value = [
  187. {
  188. legend: '烟雾浓度',
  189. seriesName: '(%)',
  190. ymax: 20,
  191. yname: '%',
  192. linetype: 'bar',
  193. yaxispos: 'left',
  194. color: '#37BCF2',
  195. sort: 1,
  196. xRotate: 0,
  197. dataIndex: 'windSpeed',
  198. },
  199. ];
  200. } else if (type === 'modelsensor_speed') {
  201. chartsColumns.value = [
  202. {
  203. legend: '风速',
  204. seriesName: '(m/s)',
  205. ymax: 20,
  206. yname: 'm/s',
  207. linetype: 'bar',
  208. yaxispos: 'left',
  209. color: '#37BCF2',
  210. sort: 1,
  211. xRotate: 0,
  212. dataIndex: 'windSpeed',
  213. },
  214. ];
  215. } else if (type === 'modelsensor_gas') {
  216. chartsColumns.value = [
  217. {
  218. legend: '甲烷',
  219. seriesName: '(%)',
  220. ymax: 20,
  221. yname: '%',
  222. linetype: 'bar',
  223. yaxispos: 'left',
  224. color: '#37BCF2',
  225. sort: 1,
  226. xRotate: 0,
  227. dataIndex: 'windSpeed',
  228. },
  229. ];
  230. }
  231. console.log('[ type ] >', type, chartsColumns.value);
  232. }
  233. function refreshEchatrs() {
  234. timer = null;
  235. getMonitor();
  236. console.log('echarts 刷新');
  237. }
  238. function historyDataSourceChange(dataSource) {
  239. historyDataSource.value = dataSource;
  240. if (historyDataSource.value.length > 0) handleChange(historyDataSource.value[0].gdevicetype);
  241. }
  242. onMounted(async () => {
  243. getMonitor(true);
  244. });
  245. onUnmounted(() => {
  246. if (timer) {
  247. clearTimeout(timer);
  248. timer = undefined;
  249. }
  250. });
  251. </script>
  252. <style lang="less" scoped>
  253. @import '/@/design/vent/color.less';
  254. @import '/@/design/vent/modal.less';
  255. .padding-0 {
  256. padding: 10px 0 !important;
  257. }
  258. .sensor-container {
  259. position: relative;
  260. top: 65px;
  261. padding: 10px;
  262. z-index: 999;
  263. max-height: calc(100vh - 150px);
  264. .@{ventSpace}-tabs {
  265. max-height: calc(100vh - 100px);
  266. .tab-item {
  267. max-height: calc(100vh - 170px);
  268. overflow-y: auto;
  269. }
  270. }
  271. .title-text {
  272. position: absolute;
  273. top: -14px;
  274. left: 0;
  275. width: 100%;
  276. text-align: center;
  277. color: #fff;
  278. }
  279. .table-box {
  280. height: calc(60vh - 150px);
  281. padding: 20px 10px;
  282. overflow-y: auto;
  283. }
  284. .box-bg {
  285. border: 1px solid #4d7ad855;
  286. border-radius: 2px;
  287. // background-color: #001d3055;
  288. -webkit-backdrop-filter: blur(8px);
  289. backdrop-filter: blur(8px);
  290. box-shadow: 0 0 10px #5984e055 inset;
  291. background-color: #00b3ff12;
  292. }
  293. .charts-box {
  294. height: calc(40vh - 80px);
  295. padding: 5px 10px;
  296. margin-top: 10px;
  297. }
  298. }
  299. :deep(.@{ventSpace}-tabs-tabpane-active) {
  300. height: 100%;
  301. }
  302. :deep(.@{ventSpace}-tabs-card) {
  303. .@{ventSpace}-tabs-tab {
  304. background: linear-gradient(#2cd1ff55, #1eb0ff55);
  305. border-color: #74e9fe;
  306. border-radius: 0%;
  307. &:hover {
  308. color: #64d5ff;
  309. }
  310. }
  311. .@{ventSpace}-tabs-tab.@{ventSpace}-tabs-tab-active .@{ventSpace}-tabs-tab-btn {
  312. color: aqua;
  313. }
  314. .@{ventSpace}-tabs-nav::before {
  315. border-color: #74e9fe;
  316. }
  317. .@{ventSpace}-picker,
  318. .@{ventSpace}-select-selector {
  319. width: 100% !important;
  320. background: #00000017 !important;
  321. border: 1px solid @vent-form-item-boder !important;
  322. input,
  323. .@{ventSpace}-select-selection-item,
  324. .@{ventSpace}-picker-suffix {
  325. color: #fff !important;
  326. }
  327. .@{ventSpace}-select-selection-placeholder {
  328. color: #b7b7b7 !important;
  329. }
  330. }
  331. .@{ventSpace}-pagination-next,
  332. .action,
  333. .@{ventSpace}-select-arrow,
  334. .@{ventSpace}-picker-separator {
  335. color: #fff !important;
  336. }
  337. .@{ventSpace}-table-cell-row-hover {
  338. background: #264d8833 !important;
  339. }
  340. .@{ventSpace}-table-row-selected {
  341. background: #00c0a311 !important;
  342. td {
  343. background-color: #00000000 !important;
  344. }
  345. }
  346. .@{ventSpace}-table-thead {
  347. // background: linear-gradient(#004a8655 0%, #004a86aa 10%) !important;
  348. background: #3d9dd45d !important;
  349. & > tr > th,
  350. .@{ventSpace}-table-column-title {
  351. // color: #70f9fc !important;
  352. border-color: #84f2ff !important;
  353. border-left: none !important;
  354. border-right: none !important;
  355. padding: 7px;
  356. }
  357. }
  358. .@{ventSpace}-table-tbody {
  359. tr > td {
  360. padding: 12px;
  361. }
  362. }
  363. .@{ventSpace}-table-tbody > tr:hover.@{ventSpace}-table-row > td {
  364. background-color: #26648855 !important;
  365. }
  366. .jeecg-basic-table-row__striped {
  367. // background: #97efff11 !important;
  368. td {
  369. background-color: #97efff11 !important;
  370. }
  371. }
  372. }
  373. </style>