realtime.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div>
  3. <div class="table-page-search-wrapper">
  4. <a-form layout="inline" :model="queryParams" ref="queryForm">
  5. <a-row :gutter="24">
  6. <a-col :xl="6" :lg="7" :md="8" :sm="24">
  7. <a-form-item label="设备名称">
  8. <j-search-select-tag v-model="queryParams.equipmentid" dict="tpm_equipment,equipmentname,id" style="width: 100%"/>
  9. </a-form-item>
  10. </a-col>
  11. <a-col :xl="6" :lg="11" :md="12" :sm="24">
  12. <a-form-item label="查询日期">
  13. <a-date-picker v-model="queryParams.date" placeholder="选择日期" style="width:100%;" @change="handleSearch" />
  14. </a-form-item>
  15. </a-col>
  16. <a-col :xl="6" :lg="7" :md="8" :sm="24">
  17. <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
  18. <a-button type="primary" @click="loadData" icon="search">查询</a-button>
  19. </span>
  20. </a-col>
  21. </a-row>
  22. </a-form>
  23. </div>
  24. <div class="trend-charts" ref="trendCharts" :style="{ height: echartsHeight + 'px', }"></div>
  25. </div>
  26. </template>
  27. <script>
  28. import * as echarts from 'echarts'
  29. import { mixinDevice } from '@/utils/mixin'
  30. import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  31. import { httpAction, getAction } from '@/api/manage'
  32. import { emsdata } from '@/views/module_ems/energyAnalyse/emsdata'
  33. import { pvdata } from '../../module_ems/photovoltaic/pvdata'
  34. export default {
  35. name: 'realtime',
  36. mixins: [JeecgListMixin, mixinDevice],
  37. data() {
  38. return {
  39. loading: false,
  40. dataSource: [],
  41. times: [],
  42. myChart: null,
  43. echartsHeight: window.innerHeight - 450,
  44. // 查询参数
  45. queryParams: {
  46. equipmentid: '1780110297413861377',
  47. date: '',
  48. },
  49. url: {
  50. list: '/equipmentOnoff/equipmentOnoff/getEquipmentHistoryData',
  51. listparams: '/tpmParams/tpmParams/queryByEquipld',
  52. },
  53. // 时间
  54. timeList: [],
  55. // 表头
  56. columns: [],
  57. equipmentparams: [{"tagname": "电流", "symbol": "CURR"},{"tagname": "电压", "symbol": "VOLT"}],
  58. mongodbdata: [{"logtime":"2024-02-05 07:02:00","CURR":0.3,"VOLT":230},
  59. {"logtime":"2024-02-05 07:03:00","CURR":0.3,"VOLT":380},
  60. {"logtime":"2024-02-05 07:04:00","CURR":0.3,"VOLT":340},
  61. {"logtime":"2024-02-05 07:05:00","CURR":0.3,"VOLT":340},
  62. {"logtime":"2024-02-05 07:06:00","CURR":0.2,"VOLT":380},
  63. {"logtime":"2024-02-05 07:07:00","CURR":0.2,"VOLT":400},
  64. {"logtime":"2024-02-05 07:08:00","CURR":0.2,"VOLT":390},
  65. {"logtime":"2024-02-05 07:09:00","CURR":0.2,"VOLT":430},
  66. {"logtime":"2024-02-05 07:10:00","CURR":0.2,"VOLT":480},
  67. {"logtime":"2024-02-05 07:11:00","CURR":0.3,"VOLT":360},
  68. {"logtime":"2024-02-05 07:12:00","CURR":0.3,"VOLT":340},
  69. {"logtime":"2024-02-05 07:13:00","CURR":0.2,"VOLT":390},
  70. {"logtime":"2024-02-05 07:14:00","CURR":0.3,"VOLT":360},
  71. {"logtime":"2024-02-05 07:15:00","CURR":0.2,"VOLT":340},
  72. {"logtime":"2024-02-05 07:16:00","CURR":0.2,"VOLT":370},
  73. {"logtime":"2024-02-05 07:17:00","CURR":0.3,"VOLT":390},
  74. {"logtime":"2024-02-05 07:18:00","CURR":0.3,"VOLT":340},
  75. {"logtime":"2024-02-05 07:19:00","CURR":0.2,"VOLT":330},
  76. {"logtime":"2024-02-05 07:20:00","CURR":0.3,"VOLT":320},
  77. {"logtime":"2024-02-05 07:21:00","CURR":0.4,"VOLT":310},
  78. {"logtime":"2024-02-05 07:22:00","CURR":0.2,"VOLT":351},
  79. {"logtime":"2024-02-05 07:23:00","CURR":0.4,"VOLT":350},
  80. {"logtime":"2024-02-05 07:24:00","CURR":0.4,"VOLT":330},
  81. {"logtime":"2024-02-05 07:25:00","CURR":0.2,"VOLT":280},
  82. {"logtime":"2024-02-05 07:26:00","CURR":0.4,"VOLT":290},
  83. {"logtime":"2024-02-05 07:27:00","CURR":0.4,"VOLT":290},
  84. {"logtime":"2024-02-05 07:28:00","CURR":0.4,"VOLT":290},
  85. {"logtime":"2024-02-05 07:29:00","CURR":0.5,"VOLT":280},
  86. {"logtime":"2024-02-05 07:30:00","CURR":0.4,"VOLT":270},
  87. {"logtime":"2024-02-05 07:31:00","CURR":0.2,"VOLT":270},
  88. {"logtime":"2024-02-05 07:32:00","CURR":0.4,"VOLT":270},
  89. {"logtime":"2024-02-05 07:33:00","CURR":0.4,"VOLT":280},
  90. {"logtime":"2024-02-05 07:34:00","CURR":0.3,"VOLT":310},
  91. {"logtime":"2024-02-05 07:35:00","CURR":0.2,"VOLT":280},
  92. {"logtime":"2024-02-05 07:36:00","CURR":0.3,"VOLT":250},
  93. {"logtime":"2024-02-05 07:37:00","CURR":0.2,"VOLT":265},
  94. {"logtime":"2024-02-05 07:38:00","CURR":0.3,"VOLT":270},
  95. {"logtime":"2024-02-05 07:39:00","CURR":0.2,"VOLT":280},
  96. {"logtime":"2024-02-05 07:40:00","CURR":0.4,"VOLT":280},
  97. {"logtime":"2024-02-05 07:41:00","CURR":0.3,"VOLT":300},
  98. {"logtime":"2024-02-05 07:42:00","CURR":0.4,"VOLT":300},
  99. {"logtime":"2024-02-05 07:43:00","CURR":0.3,"VOLT":290},
  100. {"logtime":"2024-02-05 07:44:00","CURR":0.3,"VOLT":290},
  101. {"logtime":"2024-02-05 07:45:00","CURR":0.4,"VOLT":300},
  102. {"logtime":"2024-02-05 07:46:00","CURR":0.5,"VOLT":300},
  103. {"logtime":"2024-02-05 07:47:00","CURR":0.4,"VOLT":320},
  104. {"logtime":"2024-02-05 07:48:00","CURR":0.3,"VOLT":340},
  105. {"logtime":"2024-02-05 07:49:00","CURR":0.4,"VOLT":340},
  106. {"logtime":"2024-02-05 07:50:00","CURR":0.4,"VOLT":360},
  107. {"logtime":"2024-02-05 07:51:00","CURR":0.4,"VOLT":380},
  108. {"logtime":"2024-02-05 07:52:00","CURR":0.4,"VOLT":400},
  109. {"logtime":"2024-02-05 07:53:00","CURR":0.4,"VOLT":430},
  110. {"logtime":"2024-02-05 07:54:00","CURR":0.3,"VOLT":430},
  111. {"logtime":"2024-02-05 07:55:00","CURR":0.4,"VOLT":380},
  112. {"logtime":"2024-02-05 07:56:00","CURR":0.4,"VOLT":350},
  113. {"logtime":"2024-02-05 07:57:00","CURR":0.5,"VOLT":340},
  114. {"logtime":"2024-02-05 07:58:00","CURR":0.5,"VOLT":360},
  115. {"logtime":"2024-02-05 07:59:00","CURR":0.5,"VOLT":340},
  116. {"logtime":"2024-02-05 08:00:00","CURR":0.5,"VOLT":340}],
  117. }
  118. },
  119. created() {},
  120. mounted() {
  121. var now = this.dateformat(new Date()).substring(0, 10)
  122. this.queryParams.date = now
  123. this.$nextTick(() => {
  124. })
  125. },
  126. methods: {
  127. dateformat(date) {
  128. var year = date.getFullYear()
  129. var month = date.getMonth() + 1
  130. month = month < 10 ? '0' + month : month
  131. var strDate = date.getDate()
  132. strDate = strDate < 10 ? '0' + strDate : strDate
  133. var hour = date.getHours()
  134. hour = hour < 10 ? '0' + hour : hour
  135. var minute = date.getMinutes()
  136. minute = minute < 10 ? '0' + minute : minute
  137. var second = date.getSeconds()
  138. second = second < 10 ? '0' + second : second
  139. return year + '-' + month + '-' + strDate + ' ' + hour + ':' + minute + ':' + second
  140. },
  141. /** 查询设备运行状态时间段列表 */
  142. loadData(arg) {
  143. var _this = this
  144. setTimeout(function() {
  145. _this.getList();
  146. }, 1000);
  147. },
  148. getList(){
  149. var _this = this;
  150. if (!this.url.list) {
  151. this.$message.error('请设置url.list属性!')
  152. return
  153. }
  154. if (!this.queryParams.equipmentid) {
  155. this.$message.error('请选择设备!')
  156. return
  157. }
  158. if (!this.queryParams.date) {
  159. this.$message.error('请选择查询日期!')
  160. return
  161. }
  162. // 获取图表信息
  163. getAction(_this.url.listparams, _this.queryParams).then((res) => {
  164. if (res.success) {
  165. _this.equipmentparams = res.result.records || res.result;
  166. getAction(_this.url.list, _this.queryParams).then((res) => {
  167. if (res.success) {
  168. _this.mongodbdata = [];
  169. _this.mongodbdata = res.result.records || res.result;
  170. _this.initEcharts();
  171. } else {
  172. this.$message.warning(res.message)
  173. }
  174. });
  175. } else {
  176. this.$message.warning(res.message)
  177. }
  178. });
  179. // this.getTest();
  180. },
  181. // 后端好了需要删掉
  182. getTest() {
  183. var _this = this
  184. _this.times = []
  185. this.initEcharts()
  186. },
  187. initEcharts() {
  188. var _this = this
  189. var chartDom = this.$refs.trendCharts
  190. _this.myChart = echarts.init(chartDom)
  191. _this.echartsHeight = 4 * 300;
  192. // 获取time
  193. _this.times = [];
  194. _this.mongodbdata.forEach((i) => {
  195. _this.times.push(i.logtime.substring(11, 16))
  196. });
  197. var leftValue = '5%';
  198. // Grid配置
  199. var grid = [];
  200. // xAxis配置
  201. var xAxis = [];
  202. // yAxis配置
  203. var yAxis = [];
  204. // series配置
  205. var series1 = [];
  206. var paramscount = 0;
  207. var paramslength = _this.equipmentparams.length;
  208. _this.equipmentparams.forEach((item) => {
  209. grid.push({left: leftValue, top: (0.05 + (paramscount) / paramslength) * 100 + "%", bottom: (1.05 - (paramscount + 1) / paramslength) * 100 + "%"});
  210. xAxis.push({
  211. type: 'category',
  212. gridIndex: paramscount,
  213. boundaryGap: false,
  214. name: item.symbol,
  215. data: _this.times,
  216. });
  217. yAxis.push({ type: 'value', gridIndex: paramscount });
  218. // 获取数据
  219. var realtimedata = [];
  220. _this.mongodbdata.forEach((i) => {
  221. realtimedata.push(i[item.symbol])
  222. });
  223. series1.push({
  224. name: item.symbol,
  225. type: 'line',
  226. symbol: 'none',
  227. sampling: 'lttb',
  228. xAxisIndex: paramscount,
  229. yAxisIndex: paramscount,
  230. itemStyle: {
  231. color: '#91CC75',
  232. },
  233. data: realtimedata
  234. });
  235. paramscount++;
  236. })
  237. var option = {
  238. title: {
  239. left: 'left',
  240. text: '设备运行数据趋势预测',
  241. },
  242. legend: {
  243. data: ['实际值'],
  244. },
  245. grid: grid,
  246. xAxis: xAxis,
  247. yAxis: yAxis,
  248. series: series1
  249. };
  250. option && _this.myChart.setOption(option)
  251. setTimeout(() => {
  252. _this.myChart.resize()
  253. }, 1000)
  254. window.addEventListener('resize', function () {
  255. _this.myChart.resize()
  256. })
  257. },
  258. /** 搜索按钮操作 */
  259. handleSearch(arg) {
  260. this.loadData(arg)
  261. },
  262. },
  263. }
  264. </script>
  265. <style lang="less" scoped>
  266. @import '~@/assets/less/uStyle.less';
  267. </style>
  268. <style lang="less">
  269. .trend-charts {
  270. padding: 12px;
  271. margin-top: 10px;
  272. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  273. }
  274. </style>