index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <template>
  2. <div class="sensor-container">
  3. <a-tabs class="tabs-box" type="card" v-model:activeKey="activeKey" @change="tabChange">
  4. <a-tab-pane key="1" tab="实时监测">
  5. <div class="box-bg table-box" style="margin-bottom: 10px">
  6. <label style="color: #fff">设备类型:</label>
  7. <Select
  8. @change="handleSensorChange"
  9. :options="deviceTypeOption"
  10. :fieldNames="{ label: 'itemText', value: 'itemValue' }"
  11. v-model:value="deviceKind"
  12. style="width: 200px; margin-bottom: 5px"
  13. placeholder="请选择设备类型"
  14. :allowClear="true"
  15. ></Select>
  16. <MonitorTable
  17. ref="SensorMonitorRef"
  18. :columnsType="deviceKind+'_monitor'"
  19. :dataSource="dataSource"
  20. design-scope="modelsensor_monitor"
  21. @select-row="getSelectRow"
  22. :deviceType="deviceKind"
  23. size="''"
  24. title="传感器监测"
  25. >
  26. <template #filterCell="{ column, record }">
  27. <a-tag v-if="column.dataIndex === 'warnFlag'" :color="record.warnFlag == 0 ? 'green' : 'red'">{{
  28. record.warnFlag == 0 ? '正常' : '报警'
  29. }}</a-tag>
  30. <a-tag v-if="column.dataIndex === 'netStatus'" :color="record.netStatus == 0 ? 'default' : 'green'">{{
  31. record.netStatus == 0 ? '断开' : '连接'
  32. }}</a-tag>
  33. </template>
  34. </MonitorTable>
  35. </div>
  36. <div class="charts-box box-bg">
  37. <BarAndLine
  38. v-if="chartsColumns.length > 0"
  39. :chartsColumnsType="selectData.deviceType"
  40. xAxisPropType="readTime"
  41. :dataSource="detailDataSource"
  42. height="100%"
  43. :chartsColumns="chartsColumns"
  44. chartsType="detail"
  45. :option="echartsOption"
  46. @refresh="refreshEchatrs"
  47. />
  48. </div>
  49. </a-tab-pane>
  50. <a-tab-pane key="2" tab="历史数据">
  51. <div class="tab-item table-box box-bg padding-0">
  52. <HistoryTable
  53. columns-type="modelsensor"
  54. device-type="modelsensor"
  55. :device-list-api="baseList"
  56. @change="historyDataSourceChange"
  57. designScope="modelsensor-history"
  58. />
  59. </div>
  60. <div class="charts-box box-bg">
  61. <BarAndLine
  62. v-if="chartsColumns.length > 0"
  63. :chartsColumnsType="selectData.deviceType"
  64. xAxisPropType="gcreatetime"
  65. :dataSource="historyDataSource"
  66. height="100%"
  67. :chartsColumns="chartsColumns"
  68. chartsType="history"
  69. :option="echartsOption1"
  70. @refresh="refreshEchatrs"
  71. />
  72. </div>
  73. </a-tab-pane>
  74. <a-tab-pane key="3" tab="报警历史">
  75. <div class="tab-item box-bg">
  76. <AlarmHistoryTable columns-type="alarm" device-type="modelsensor" :device-list-api="baseList" designScope="alarm-history" />
  77. </div>
  78. </a-tab-pane>
  79. <a-tab-pane key="4" tab="操作历史">
  80. <div class="tab-item box-bg">
  81. <HandlerHistoryTable columns-type="operatorhistory" device-type="modelsensor" :device-list-api="baseList" designScope="alarm-history" />
  82. </div>
  83. </a-tab-pane>
  84. </a-tabs>
  85. <div class="title-text">
  86. {{ selectData.strname }}
  87. </div>
  88. </div>
  89. </template>
  90. <script setup lang="ts">
  91. import BarAndLine from '/@/components/chart/BarAndLine.vue';
  92. import { Select } from 'ant-design-vue';
  93. import { onBeforeMount, ref, onMounted, onUnmounted, toRaw, reactive, nextTick } from 'vue';
  94. import MonitorTable from '../comment/MonitorTable.vue';
  95. import HistoryTable from '../comment/HistoryTable.vue';
  96. import AlarmHistoryTable from '../comment/AlarmHistoryTable.vue';
  97. import HandlerHistoryTable from '../comment/HandlerHistoryTable.vue';
  98. import { list, getTableList } from './sensor.api';
  99. import { list as baseList } from '../../deviceManager/sensorTabel/sensor.api';
  100. import { deviceList } from '../../deviceManager/comment/pointTabel/point.api';
  101. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  102. const SensorMonitorRef = ref();
  103. const deviceBaseList = ref([]);
  104. const activeKey = ref('1');
  105. const deviceKind = ref('');
  106. const deviceTypeOption = ref([]);
  107. // 默认初始是第一行
  108. const selectRowIndex = ref(0);
  109. const dataSource = ref([]);
  110. const detailDataSource = ref<any[]>([]);
  111. const historyDataSource = ref<any[]>([]);
  112. const chartsColumns = ref<any[]>([]);
  113. const echartsOption = {
  114. grid: {
  115. top: '20%',
  116. left: '10px',
  117. right: '5px',
  118. bottom: '5%',
  119. containLabel: true
  120. },
  121. toolbox: {
  122. feature: {
  123. }
  124. }
  125. }
  126. const echartsOption1 = {
  127. grid: {
  128. top: '20%',
  129. left: '10px',
  130. right: '5px',
  131. bottom: '10%',
  132. containLabel: true
  133. },
  134. toolbox: {
  135. feature: {
  136. }
  137. }
  138. }
  139. const selectData = reactive({
  140. strname: '',
  141. deviceType: '',
  142. deviceID: ''
  143. });
  144. const tabChange = (activeKeyVal) => {
  145. activeKey.value = activeKeyVal;
  146. detailDataSource.value = [];
  147. if (activeKeyVal == 1) {
  148. nextTick(() => {
  149. SensorMonitorRef.value.setSelectedRowKeys([selectData.deviceID])
  150. })
  151. }
  152. };
  153. // https获取监测数据
  154. let timer: null | NodeJS.Timeout = null;
  155. const getMonitor = (flag?) => {
  156. if (Object.prototype.toString.call(timer) === '[object Null]') {
  157. timer = setTimeout(async () => {
  158. await getDataSource(deviceKind.value);
  159. if (timer) {
  160. timer = null;
  161. }
  162. getMonitor();
  163. }, flag? 0 :1000);
  164. }
  165. };
  166. const getDataSource = async (devicetype) => {
  167. const type = devicetype ? devicetype : 'modelsensor';
  168. const res = await list({ devicetype: type, pagetype: 'normal' });
  169. dataSource.value = res.msgTxt[0].datalist || [];
  170. dataSource.value.map((data: any) => {
  171. const readData = data.readData;
  172. data = Object.assign(data, readData);
  173. return data;
  174. });
  175. const data: any = toRaw(dataSource.value[selectRowIndex.value]); //maxarea
  176. Object.assign(selectData, data);
  177. // if (chartsColumns.value.length <= 0 && selectData.deviceType) {
  178. // handleChange(selectData.deviceType);
  179. // }
  180. // 如果当前为监测tab
  181. if (activeKey.value === '1') {
  182. const isHas = detailDataSource.value.find((item) => item['readTime'] === selectData['readTime']);
  183. // 获取选中数据
  184. if (!isHas) {
  185. if (detailDataSource.value.length < 15) {
  186. detailDataSource.value.push({ ...selectData });
  187. } else {
  188. detailDataSource.value.shift();
  189. detailDataSource.value.push({ ...selectData });
  190. }
  191. }
  192. }
  193. return data;
  194. };
  195. const getSelectRow = (selectRow, index) => {
  196. if (!selectRow) return;
  197. selectRowIndex.value = index;
  198. const baseData: any = deviceBaseList.value.find((baseData: any) => baseData.id === selectRow.deviceID);
  199. Object.assign(selectData, selectRow, baseData);
  200. if (selectData.deviceType) {
  201. // if (timer) {
  202. // clearTimeout(timer);
  203. // timer = undefined;
  204. // }
  205. if (activeKey.value === '1') detailDataSource.value = [];
  206. if (activeKey.value === '2') historyDataSource.value = [];
  207. handleChange(selectData.deviceType);
  208. }
  209. };
  210. // 获取设备基本信息列表
  211. const getDeviceBaseList = () => {
  212. getTableList({ pageSize: 1000 }).then((res) => {
  213. deviceBaseList.value = res.records;
  214. });
  215. };
  216. function handleChange(type) {
  217. chartsColumns.value = getTableHeaderColumns(type+'_chart')
  218. console.log('[ type ] >', type, chartsColumns.value);
  219. }
  220. function handleSensorChange(type) {
  221. if (timer) {
  222. clearTimeout(timer);
  223. timer = undefined;
  224. }
  225. setTimeout(() => {
  226. handleChange(type);
  227. timer = null;
  228. dataSource.value = [];
  229. detailDataSource.value = [];
  230. getMonitor(true);
  231. }, 500);
  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>