index.vue 13 KB

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