1
0

index.vue 12 KB

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