index.vue 13 KB

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