index.vue 13 KB

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