index.vue 12 KB

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