realtime.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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="8" :lg="7" :md="8" :sm="24">
  7. <a-form-item label="设备名称">
  8. <a-select
  9. v-model="queryParams.equipmentid"
  10. placeholder="请输入设备名称或设备编号"
  11. show-search
  12. :filterOption="filterOptions"
  13. @change="clearOptions"
  14. @search="searchDevice"
  15. allowClear>
  16. <a-select-option v-for="(item, index) in deviceOptions" :key="index" :value="item.id" :label="item.equipmentname">
  17. <span>{{item.equipmentname}}</span>
  18. <span style="position: absolute;right: 2%;">{{ item.equipmentcode }}</span>
  19. </a-select-option>
  20. </a-select>
  21. </a-form-item>
  22. </a-col>
  23. <a-col :xl="4" :lg="11" :md="12" :sm="24">
  24. <a-form-item label="查询日期">
  25. <a-date-picker v-model="queryParams.date" placeholder="选择日期" style="width:100%;" @change="handleSearch" />
  26. </a-form-item>
  27. </a-col>
  28. <a-col :xl="6" :lg="7" :md="8" :sm="24">
  29. <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
  30. <a-button type="primary" @click="handleSearch" icon="search">查询</a-button>
  31. </span>
  32. </a-col>
  33. </a-row>
  34. </a-form>
  35. </div>
  36. <div class="trend-charts" ref="trendCharts" :style="{ height: echartsHeight + 'px', }"></div>
  37. </div>
  38. </template>
  39. <script>
  40. import * as echarts from 'echarts'
  41. import { mixinDevice } from '@/utils/mixin'
  42. import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  43. import { httpAction, getAction } from '@/api/manage'
  44. import { emsdata } from '@/views/module_ems/energyAnalyse/emsdata'
  45. import { pvdata } from '../../module_ems/photovoltaic/pvdata'
  46. export default {
  47. name: 'realtime',
  48. mixins: [JeecgListMixin, mixinDevice],
  49. data() {
  50. return {
  51. loading: false,
  52. dataSource: [],
  53. times: [],
  54. myChart: null,
  55. echartsHeight: window.innerHeight - 330,
  56. // 查询参数
  57. queryParams: {
  58. equipmentid: '',
  59. date: '',
  60. },
  61. url: {
  62. list: '/equipmentOnoff/equipmentOnoff/getEquipmentHistoryDataDefault',
  63. listparams: '/tpmParams/tpmParams/queryByEquipId',
  64. },
  65. deviceOptions: [],
  66. deviceOptionsAll: [],
  67. // 时间
  68. timeList: [],
  69. // 表头
  70. columns: [],
  71. equipmentparams: [{"tagname": "电流", "symbol": "CURR"},{"tagname": "电压", "symbol": "VOLT"}],
  72. mongodbdata: [{"logtime":"2024-02-05 07:02:00","CURR":0.3,"VOLT":230},
  73. {"logtime":"2024-02-05 07:03:00","CURR":0.3,"VOLT":380},
  74. {"logtime":"2024-02-05 07:04:00","CURR":0.3,"VOLT":340},
  75. {"logtime":"2024-02-05 07:05:00","CURR":0.3,"VOLT":340},
  76. {"logtime":"2024-02-05 07:06:00","CURR":0.2,"VOLT":380},
  77. {"logtime":"2024-02-05 07:07:00","CURR":0.2,"VOLT":400},
  78. {"logtime":"2024-02-05 07:08:00","CURR":0.2,"VOLT":390},
  79. {"logtime":"2024-02-05 07:09:00","CURR":0.2,"VOLT":430},
  80. {"logtime":"2024-02-05 07:10:00","CURR":0.2,"VOLT":480},
  81. {"logtime":"2024-02-05 07:11:00","CURR":0.3,"VOLT":360},
  82. {"logtime":"2024-02-05 07:12:00","CURR":0.3,"VOLT":340},
  83. {"logtime":"2024-02-05 07:13:00","CURR":0.2,"VOLT":390},
  84. {"logtime":"2024-02-05 07:14:00","CURR":0.3,"VOLT":360},
  85. {"logtime":"2024-02-05 07:15:00","CURR":0.2,"VOLT":340},
  86. {"logtime":"2024-02-05 07:16:00","CURR":0.2,"VOLT":370},
  87. {"logtime":"2024-02-05 07:17:00","CURR":0.3,"VOLT":390},
  88. {"logtime":"2024-02-05 07:18:00","CURR":0.3,"VOLT":340},
  89. {"logtime":"2024-02-05 07:19:00","CURR":0.2,"VOLT":330},
  90. {"logtime":"2024-02-05 07:20:00","CURR":0.3,"VOLT":320},
  91. {"logtime":"2024-02-05 07:21:00","CURR":0.4,"VOLT":310},
  92. {"logtime":"2024-02-05 07:22:00","CURR":0.2,"VOLT":351},
  93. {"logtime":"2024-02-05 07:23:00","CURR":0.4,"VOLT":350},
  94. {"logtime":"2024-02-05 07:24:00","CURR":0.4,"VOLT":330},
  95. {"logtime":"2024-02-05 07:25:00","CURR":0.2,"VOLT":280},
  96. {"logtime":"2024-02-05 07:26:00","CURR":0.4,"VOLT":290},
  97. {"logtime":"2024-02-05 07:27:00","CURR":0.4,"VOLT":290},
  98. {"logtime":"2024-02-05 07:28:00","CURR":0.4,"VOLT":290},
  99. {"logtime":"2024-02-05 07:29:00","CURR":0.5,"VOLT":280},
  100. {"logtime":"2024-02-05 07:30:00","CURR":0.4,"VOLT":270},
  101. {"logtime":"2024-02-05 07:31:00","CURR":0.2,"VOLT":270},
  102. {"logtime":"2024-02-05 07:32:00","CURR":0.4,"VOLT":270},
  103. {"logtime":"2024-02-05 07:33:00","CURR":0.4,"VOLT":280},
  104. {"logtime":"2024-02-05 07:34:00","CURR":0.3,"VOLT":310},
  105. {"logtime":"2024-02-05 07:35:00","CURR":0.2,"VOLT":280},
  106. {"logtime":"2024-02-05 07:36:00","CURR":0.3,"VOLT":250},
  107. {"logtime":"2024-02-05 07:37:00","CURR":0.2,"VOLT":265},
  108. {"logtime":"2024-02-05 07:38:00","CURR":0.3,"VOLT":270},
  109. {"logtime":"2024-02-05 07:39:00","CURR":0.2,"VOLT":280},
  110. {"logtime":"2024-02-05 07:40:00","CURR":0.4,"VOLT":280},
  111. {"logtime":"2024-02-05 07:41:00","CURR":0.3,"VOLT":300},
  112. {"logtime":"2024-02-05 07:42:00","CURR":0.4,"VOLT":300},
  113. {"logtime":"2024-02-05 07:43:00","CURR":0.3,"VOLT":290},
  114. {"logtime":"2024-02-05 07:44:00","CURR":0.3,"VOLT":290},
  115. {"logtime":"2024-02-05 07:45:00","CURR":0.4,"VOLT":300},
  116. {"logtime":"2024-02-05 07:46:00","CURR":0.5,"VOLT":300},
  117. {"logtime":"2024-02-05 07:47:00","CURR":0.4,"VOLT":320},
  118. {"logtime":"2024-02-05 07:48:00","CURR":0.3,"VOLT":340},
  119. {"logtime":"2024-02-05 07:49:00","CURR":0.4,"VOLT":340},
  120. {"logtime":"2024-02-05 07:50:00","CURR":0.4,"VOLT":360},
  121. {"logtime":"2024-02-05 07:51:00","CURR":0.4,"VOLT":380},
  122. {"logtime":"2024-02-05 07:52:00","CURR":0.4,"VOLT":400},
  123. {"logtime":"2024-02-05 07:53:00","CURR":0.4,"VOLT":430},
  124. {"logtime":"2024-02-05 07:54:00","CURR":0.3,"VOLT":430},
  125. {"logtime":"2024-02-05 07:55:00","CURR":0.4,"VOLT":380},
  126. {"logtime":"2024-02-05 07:56:00","CURR":0.4,"VOLT":350},
  127. {"logtime":"2024-02-05 07:57:00","CURR":0.5,"VOLT":340},
  128. {"logtime":"2024-02-05 07:58:00","CURR":0.5,"VOLT":360},
  129. {"logtime":"2024-02-05 07:59:00","CURR":0.5,"VOLT":340},
  130. {"logtime":"2024-02-05 08:00:00","CURR":0.5,"VOLT":340}],
  131. }
  132. },
  133. created() {
  134. this.getDeviceOption();
  135. },
  136. mounted() {
  137. var now = this.dateformat(new Date()).substring(0, 10)
  138. this.queryParams.date = now
  139. this.$nextTick(() => {
  140. })
  141. },
  142. methods: {
  143. // 获取设备下拉列表
  144. getDeviceOption(){
  145. getAction(`/tpmEquipment/tpmEquipment/selectEquipmentList`).then(res=>{
  146. this.deviceOptions = res.result.map((res) => {
  147. return {
  148. id: res.id,
  149. equipmentname: res.equipmentname,
  150. equipmentcode: res.equipmentcode,
  151. }
  152. })
  153. // 存一个完整的设备表
  154. this.deviceOptionsAll = this.deviceOptions
  155. })
  156. },
  157. // 筛选设备
  158. searchDevice(value) {
  159. // 若输入的值删除,则重新赋完整的设备列表
  160. if (value.trim().length === 0) {
  161. this.deviceOptions = this.deviceOptionsAll
  162. }
  163. // 通过判断字符串中是数字还是文字进而判断是通过设备名筛选还是设备编号筛选
  164. let panDuan = isNaN(parseFloat(value))
  165. if (!panDuan) {
  166. let filteredArray = this.deviceOptionsAll.filter(item => item.equipmentcode.includes(value));
  167. this.deviceOptions = filteredArray
  168. } else {
  169. let filteredArray = this.deviceOptionsAll.filter(item => item.equipmentname.includes(value));
  170. this.deviceOptions = filteredArray
  171. }
  172. },
  173. // 解决筛选后option不回显问题
  174. filterOptions(input, option) {
  175. return this.deviceOptions
  176. },
  177. // 解决筛选后删除option不回显问题
  178. clearOptions() {
  179. this.deviceOptions = this.deviceOptionsAll
  180. },
  181. dateformat(date) {
  182. var year = date.getFullYear()
  183. var month = date.getMonth() + 1
  184. month = month < 10 ? '0' + month : month
  185. var strDate = date.getDate()
  186. strDate = strDate < 10 ? '0' + strDate : strDate
  187. var hour = date.getHours()
  188. hour = hour < 10 ? '0' + hour : hour
  189. var minute = date.getMinutes()
  190. minute = minute < 10 ? '0' + minute : minute
  191. var second = date.getSeconds()
  192. second = second < 10 ? '0' + second : second
  193. return year + '-' + month + '-' + strDate + ' ' + hour + ':' + minute + ':' + second
  194. },
  195. /** 查询设备运行状态时间段列表 */
  196. loadData(arg) {
  197. },
  198. getList(){
  199. console.log("this.queryParams", this.queryParams)
  200. var _this = this;
  201. if (!this.url.list) {
  202. this.$message.error('请设置url.list属性!')
  203. return
  204. }
  205. if (!this.queryParams.equipmentid) {
  206. this.$message.error('请选择设备!')
  207. return
  208. }
  209. if (!this.queryParams.date) {
  210. this.$message.error('请选择查询日期!')
  211. return
  212. }
  213. // 获取图表信息
  214. getAction(_this.url.listparams, _this.queryParams).then((res) => {
  215. if (res.success) {
  216. console.log("listparams")
  217. _this.equipmentparams = res.result.records || res.result;
  218. getAction(_this.url.list, _this.queryParams).then((res) => {
  219. console.log("list")
  220. if (res.success) {
  221. _this.mongodbdata = [];
  222. _this.mongodbdata = res.result.records || res.result;
  223. _this.initEcharts();
  224. } else {
  225. this.$message.warning(res.message)
  226. }
  227. });
  228. } else {
  229. this.$message.warning(res.message)
  230. }
  231. });
  232. // this.getTest();
  233. },
  234. // 后端好了需要删掉
  235. getTest() {
  236. var _this = this
  237. _this.times = []
  238. this.initEcharts()
  239. },
  240. initEcharts() {
  241. var _this = this
  242. var chartDom = this.$refs.trendCharts
  243. if (_this.myChart != null && _this.myChart.dispose) {
  244. _this.myChart.dispose(); // 销毁实例
  245. }
  246. _this.myChart = echarts.init(chartDom)
  247. // _this.echartsHeight = 4 * 300;
  248. _this.echartsHeight = _this.equipmentparams.length > 1 ? _this.equipmentparams.length * 180 : window.innerHeight - 330;
  249. // 获取time
  250. _this.times = [];
  251. _this.mongodbdata.forEach((i) => {
  252. _this.times.push(i.logtime.substring(11, 16))
  253. });
  254. var leftValue = '5%';
  255. // Grid配置
  256. var grid = [];
  257. // xAxis配置
  258. var xAxis = [];
  259. // yAxis配置
  260. var yAxis = [];
  261. // series配置
  262. var series1 = [];
  263. var paramscount = 0;
  264. var paramslength = _this.equipmentparams.length;
  265. _this.equipmentparams.forEach((item) => {
  266. if(paramslength === 1){
  267. // 只有一个时,占满屏
  268. grid.push({left: leftValue, top: "15%", bottom: "8%"});
  269. }
  270. if(paramslength === 2){
  271. // 当两个时
  272. grid.push({left: leftValue,top: '15%', bottom: "56%"}, {left: leftValue, top: "58%", bottom: '8%'});
  273. }
  274. // 加判断是为了最上和最下有点间距好看,也可以不判断直接用注释那句
  275. var firstTop = 3 // 最上面一个距离顶部占比2%
  276. var lastBottom = 2 // 最上面一个距离顶部占比2%
  277. var itemPadding = 3 // 图形之间间隔占比1%
  278. var itemHP = (100 - firstTop - lastBottom - itemPadding * (paramslength - 1)) / paramslength // 每一个图形占比
  279. if(paramscount === 0){
  280. grid.push({left: leftValue, top: firstTop + "%", bottom: (lastBottom + ((itemHP + itemPadding) * (paramslength - (paramscount + 1)))) + "%"});
  281. } else if (paramscount === (paramslength - 1)){
  282. grid.push({left: leftValue, top: (firstTop + (itemHP + itemPadding) * paramscount) + "%", bottom: lastBottom + "%"});
  283. } else {
  284. grid.push({left: leftValue, top: (firstTop + (itemHP + itemPadding) * paramscount) + "%", bottom: (lastBottom + (itemHP + itemPadding) * (paramslength - (paramscount + 1))) + "%"});
  285. }
  286. // grid.push({left: leftValue, top: (0.02 + paramscount / paramslength) * 100 + "%", bottom: (1.01 - (paramscount + 1) / paramslength) * 100 + "%"});;
  287. console.log(grid)
  288. xAxis.push({
  289. type: 'category',
  290. gridIndex: paramscount,
  291. boundaryGap: false,
  292. name: item.symbol,
  293. data: _this.times,
  294. });
  295. yAxis.push({ type: 'value', gridIndex: paramscount });
  296. // 获取数据
  297. var realtimedata = [];
  298. _this.mongodbdata.forEach((i) => {
  299. realtimedata.push(i[item.symbol])
  300. });
  301. series1.push({
  302. name: item.symbol,
  303. type: 'line',
  304. symbol: 'none',
  305. sampling: 'lttb',
  306. xAxisIndex: paramscount,
  307. yAxisIndex: paramscount,
  308. itemStyle: {
  309. color: '#91CC75',
  310. },
  311. data: realtimedata
  312. });
  313. paramscount++;
  314. })
  315. var option = {
  316. title: {
  317. left: 'left',
  318. text: '设备运行数据趋势预测',
  319. },
  320. legend: {
  321. data: ['实际值'],
  322. },
  323. grid: grid,
  324. xAxis: xAxis,
  325. yAxis: yAxis,
  326. series: series1
  327. };
  328. option && _this.myChart.setOption(option)
  329. setTimeout(() => {
  330. _this.myChart.resize()
  331. }, 1000)
  332. window.addEventListener('resize', function () {
  333. _this.myChart.resize()
  334. })
  335. },
  336. /** 搜索按钮操作 */
  337. handleSearch(arg) {
  338. console.log(1)
  339. this.getList(arg)
  340. },
  341. },
  342. }
  343. </script>
  344. <style lang="less" scoped>
  345. @import '~@/assets/less/uStyle.less';
  346. </style>
  347. <style lang="less">
  348. .trend-charts {
  349. padding: 12px;
  350. margin-top: 10px;
  351. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  352. }
  353. </style>