index1.vue 11 KB

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