index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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. <label style="color: #fff">设备类型:</label>
  8. <Select
  9. @change="handleSensorChange"
  10. :options="deviceTypeOption"
  11. :fieldNames="{ label: 'itemText', value: 'itemValue' }"
  12. v-model:value="deviceKind"
  13. style="width: 200px; margin-bottom: 5px"
  14. placeholder="请选择设备类型"
  15. :allowClear="true"
  16. ></Select>
  17. <MonitorTable
  18. ref="SensorMonitorRef"
  19. :columnsType="deviceKind+'_monitor'"
  20. :dataSource="dataSource"
  21. design-scope="modelsensor_monitor"
  22. @select-row="getSelectRow"
  23. :deviceType="deviceKind"
  24. :scroll="{ y: 300 }"
  25. size="''"
  26. title="传感器监测"
  27. >
  28. <template #filterCell="{ column, record }">
  29. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == 0 ? 'green' : 'red'">{{
  30. record.warnFlag == 0 ? '正常' : '报警'
  31. }}</a-tag>
  32. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == 0 ? 'default' : 'green'">{{
  33. record.netStatus == 0 ? '断开' : '连接'
  34. }}</a-tag>
  35. </template>
  36. </MonitorTable>
  37. </div>
  38. <div class="charts-box box-bg">
  39. <BarAndLine
  40. v-if="chartsColumns.length > 0"
  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. </a-tab-pane>
  52. <a-tab-pane key="2" tab="历史数据">
  53. <div class="tab-item table-box box-bg padding-0">
  54. <HistoryTable
  55. columns-type="modelsensor"
  56. device-type="modelsensor"
  57. :device-list-api="baseList"
  58. @change="historyDataSourceChange"
  59. designScope="modelsensor-history"
  60. />
  61. </div>
  62. <div class="charts-box box-bg">
  63. <BarAndLine
  64. v-if="chartsColumns.length > 0"
  65. :chartsColumnsType="selectData.deviceType"
  66. xAxisPropType="gcreatetime"
  67. :dataSource="historyDataSource"
  68. height="100%"
  69. :chartsColumns="chartsColumns"
  70. chartsType="history"
  71. :option="echartsOption1"
  72. @refresh="refreshEchatrs"
  73. />
  74. </div>
  75. </a-tab-pane>
  76. <a-tab-pane key="3" tab="报警历史">
  77. <div class="tab-item box-bg">
  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. }
  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. }
  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(async () => {
  162. await getDataSource(deviceKind.value);
  163. if (timer) {
  164. timer = null;
  165. }
  166. getMonitor();
  167. }, flag? 0 :1000);
  168. }
  169. };
  170. const getDataSource = async (devicetype) => {
  171. const type = devicetype ? devicetype : 'modelsensor';
  172. const res = await list({ devicetype: type, pagetype: 'normal' });
  173. dataSource.value = res.msgTxt[0].datalist || [];
  174. dataSource.value.map((data: any) => {
  175. const readData = data.readData;
  176. data = Object.assign(data, readData);
  177. return data;
  178. });
  179. const data: any = toRaw(dataSource.value[selectRowIndex.value]); //maxarea
  180. Object.assign(selectData, data);
  181. // if (chartsColumns.value.length <= 0 && selectData.deviceType) {
  182. // handleChange(selectData.deviceType);
  183. // }
  184. // 如果当前为监测tab
  185. if (activeKey.value === '1') {
  186. const isHas = detailDataSource.value.find((item) => item['readTime'] === selectData['readTime']);
  187. // 获取选中数据
  188. if (!isHas) {
  189. if (detailDataSource.value.length < 15) {
  190. detailDataSource.value.push({ ...selectData });
  191. } else {
  192. detailDataSource.value.shift();
  193. detailDataSource.value.push({ ...selectData });
  194. }
  195. }
  196. }
  197. if(loading.value){
  198. loading.value = false
  199. }
  200. return data;
  201. };
  202. const getSelectRow = (selectRow, index) => {
  203. if (!selectRow) return;
  204. selectRowIndex.value = index;
  205. const baseData: any = deviceBaseList.value.find((baseData: any) => baseData.id === selectRow.deviceID);
  206. Object.assign(selectData, selectRow, baseData);
  207. if (selectData.deviceType) {
  208. // if (timer) {
  209. // clearTimeout(timer);
  210. // timer = undefined;
  211. // }
  212. if (activeKey.value === '1') detailDataSource.value = [];
  213. if (activeKey.value === '2') historyDataSource.value = [];
  214. handleChange(selectData.deviceType);
  215. }
  216. };
  217. // 获取设备基本信息列表
  218. const getDeviceBaseList = () => {
  219. getTableList({ pageSize: 1000 }).then((res) => {
  220. deviceBaseList.value = res.records;
  221. });
  222. };
  223. function handleChange(type) {
  224. chartsColumns.value = getTableHeaderColumns(type+'_chart')
  225. console.log('[ type ] >', type, chartsColumns.value);
  226. }
  227. function handleSensorChange(type) {
  228. loading.value = true
  229. handleChange(type);
  230. timer = null;
  231. dataSource.value = [];
  232. detailDataSource.value = [];
  233. }
  234. function refreshEchatrs() {
  235. timer = null;
  236. // getMonitor(true);
  237. console.log('echarts 刷新');
  238. }
  239. function historyDataSourceChange(dataSource) {
  240. historyDataSource.value = dataSource;
  241. if (historyDataSource.value.length > 0) handleChange(historyDataSource.value[0].gdevicetype);
  242. }
  243. onBeforeMount(() => {
  244. getDeviceBaseList();
  245. });
  246. onMounted(async () => {
  247. const res = await deviceList({ devicetype: 'modelsensor' });
  248. const obj = res.find((item) => item.itemValue === 'modelsensor');
  249. deviceTypeOption.value = obj ? obj.children : [];
  250. deviceKind.value = deviceTypeOption.value[0]['itemValue'] || 'modelsensor_monitor'
  251. handleChange(deviceKind.value)
  252. await getMonitor(true);
  253. });
  254. onUnmounted(() => {
  255. if (timer) {
  256. clearTimeout(timer);
  257. timer = undefined;
  258. }
  259. });
  260. </script>
  261. <style lang="less" scoped>
  262. @import '/@/design/vent/color.less';
  263. @import '/@/design/vent/modal.less';
  264. .padding-0 {
  265. padding: 10px 0 !important;
  266. }
  267. .sensor-container {
  268. height: 100%;
  269. position: relative;
  270. top: 65px;
  271. padding: 10px;
  272. z-index: 999;
  273. // max-height: calc(100vh - 150px);
  274. .@{ventSpace}-tabs {
  275. max-height: calc(100% - 100px);
  276. .tab-item {
  277. max-height: calc(100% - 170px);
  278. overflow-y: auto;
  279. }
  280. }
  281. .title-text {
  282. position: absolute;
  283. top: -24px;
  284. left: 0;
  285. width: 100%;
  286. text-align: center;
  287. color: #fff;
  288. }
  289. .table-box {
  290. height: calc(60% - 150px);
  291. padding: 20px 10px;
  292. overflow-y: auto;
  293. }
  294. .box-bg {
  295. // border: 1px solid #4d7ad855;
  296. // border-radius: 2px;
  297. // // background-color: #001d3055;
  298. // -webkit-backdrop-filter: blur(8px);
  299. // backdrop-filter: blur(8px);
  300. // box-shadow: 0 0 10px #5984e055 inset;
  301. // background-color: #00b3ff12;
  302. padding-bottom: 10px;
  303. border: 1px solid #44d3ff70;
  304. border-radius: 2px;
  305. -webkit-backdrop-filter: blur(8px);
  306. box-shadow: 0 0 20px #44b4ff33 inset;
  307. background-color: #ffffff11;
  308. overflow-y: auto;
  309. }
  310. .charts-box {
  311. height: calc(40% - 80px);
  312. padding: 5px 10px;
  313. margin-top: 10px;
  314. }
  315. }
  316. :deep(.@{ventSpace}-tabs-tabpane-active) {
  317. height: 100%;
  318. }
  319. :deep(.@{ventSpace}-tabs-card) {
  320. .@{ventSpace}-tabs-tab {
  321. background: linear-gradient(#2cd1ff55, #1eb0ff55);
  322. border-color: #74e9fe;
  323. border-radius: 0%;
  324. &:hover {
  325. color: #64d5ff;
  326. }
  327. }
  328. .@{ventSpace}-tabs-tab.@{ventSpace}-tabs-tab-active .@{ventSpace}-tabs-tab-btn {
  329. color: aqua;
  330. }
  331. .@{ventSpace}-tabs-nav::before {
  332. border-color: #74e9fe;
  333. }
  334. .@{ventSpace}-picker,
  335. .@{ventSpace}-select-selector {
  336. width: 100% !important;
  337. background: #00000017 !important;
  338. border: 1px solid @vent-form-item-boder !important;
  339. input,
  340. .@{ventSpace}-select-selection-item,
  341. .@{ventSpace}-picker-suffix {
  342. color: #fff !important;
  343. }
  344. .@{ventSpace}-select-selection-placeholder {
  345. color: #b7b7b7 !important;
  346. }
  347. }
  348. .@{ventSpace}-pagination-next,
  349. .action,
  350. .@{ventSpace}-select-arrow,
  351. .@{ventSpace}-picker-separator {
  352. color: #fff !important;
  353. }
  354. .@{ventSpace}-table-cell-row-hover {
  355. background: #264d8833 !important;
  356. }
  357. .@{ventSpace}-table-row-selected {
  358. background: #00c0a311 !important;
  359. td {
  360. background-color: #00000000 !important;
  361. }
  362. }
  363. .@{ventSpace}-table-thead {
  364. // background: linear-gradient(#004a8655 0%, #004a86aa 10%) !important;
  365. background: #3d9dd45d!important;
  366. & > tr > th,
  367. .@{ventSpace}-table-column-title {
  368. // color: #70f9fc !important;
  369. border-color: #84f2ff !important;
  370. border-left: none !important;
  371. border-right: none !important;
  372. padding: 7px;
  373. }
  374. }
  375. .@{ventSpace}-table-tbody {
  376. tr > td {
  377. padding: 12px;
  378. }
  379. }
  380. .@{ventSpace}-table-tbody > tr:hover.@{ventSpace}-table-row > td {
  381. background-color: #26648855 !important;
  382. }
  383. .jeecg-basic-table-row__striped {
  384. // background: #97efff11 !important;
  385. td {
  386. background-color: #97efff11 !important;
  387. }
  388. }
  389. }
  390. </style>