index.vue 13 KB

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