consume.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="10">
  4. <el-col :span="4" :xs="24">
  5. <div class="head-container">
  6. <el-input v-model="areaName" placeholder="请输入区域名称" clearable size="small" prefix-icon="el-icon-search"
  7. style="margin-bottom: 20px" />
  8. </div>
  9. <div class="head-container" style="height: 100vh; overflow: hidden; position: relative;">
  10. <el-tree :data="areaOptions" :props="defaultProps" :expand-on-click-node="false"
  11. :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current
  12. @node-click="handleNodeClick" style="height: calc(100vh - 50px); overflow-y: auto;" />
  13. </div>
  14. </el-col>
  15. <el-col :span="20" :xs="24">
  16. <div class="container-block">
  17. <el-card>
  18. <div style="display: flex;justify-content: space-between;">
  19. <SubTitle :title="`平均功率-15分钟【${selectedLabel}】`" />
  20. <el-button-group>
  21. <el-button v-for="item in btnGroup" :key="item.name" size="mini"
  22. :type="item.name === activeBtn ? 'primary' : ''" :icon="item.icon" @click="btnChange(item)" />
  23. </el-button-group>
  24. </div>
  25. <div class="ctl-container">
  26. <el-date-picker v-model="dateRange" type="datetimerange" @change="getPowerChart"
  27. :picker-options="pickerOptions" value-format="yyyy-MM-dd hh:mm:ss" range-separator="至"
  28. start-placeholder="开始日期" end-placeholder="结束日期" align="right" :clearable="false">
  29. </el-date-picker>
  30. </div>
  31. <el-table v-if="activeBtn == 'table'" :data="powerChartData" max-height="400px">
  32. <el-table-column label="日期" align="center" prop="date" width="100" fixed="left">
  33. </el-table-column>
  34. <el-table-column label="时间" align="center" prop="time" width="100" fixed="left">
  35. </el-table-column>
  36. <el-table-column label="电流(A)" align="center" show-overflow-tooltip width="200">
  37. <template slot-scope="scope">
  38. <span>A相:{{ scope.row.la }}A;</span>
  39. <span>B相:{{ scope.row.lb }}A;</span>
  40. <span>C相:{{ scope.row.lc }}A</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="电压(V)" align="center" show-overflow-tooltip width="200">
  44. <template slot-scope="scope">
  45. <span>A相:{{ scope.row.ua }}V;</span>
  46. <span>B相:{{ scope.row.ub }}V;</span>
  47. <span>C相:{{ scope.row.uc }}V</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="有功功率(kW)" align="center" show-overflow-tooltip width="250" >
  51. <template slot-scope="scope">
  52. <span>A相:{{ scope.row.pa }}kW;</span>
  53. <span>B相:{{ scope.row.pb }}kW;</span>
  54. <span>C相:{{ scope.row.pc }}kW</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="无功功率(kW)" align="center" show-overflow-tooltip width="250" >
  58. <template slot-scope="scope">
  59. <span>A相:{{ scope.row.qa }}kW;</span>
  60. <span>B相:{{ scope.row.qb }}kW;</span>
  61. <span>C相:{{ scope.row.qc }}kW</span>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="功率因素" align="center" prop="pf" width="100" />
  65. </el-table>
  66. <BaseChart v-else width="100%" height="400px" :option="powerLineOptions" />
  67. </el-card>
  68. <el-card style="margin-top: 10px;">
  69. <div style="display: flex;justify-content: space-between;">
  70. <SubTitle :title="`峰值功率-日【${selectedLabel}】`" />
  71. <el-date-picker v-model="maxPowerDate" type="daterange" @change="getDayMaxLoad"
  72. :picker-options="pickerOptions" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期"
  73. end-placeholder="结束日期" align="right" :clearable="false">
  74. </el-date-picker>
  75. </div>
  76. <BaseChart width="100%" height="400px" :option="maxLoadLineOptions" />
  77. </el-card>
  78. </div>
  79. </el-col>
  80. </el-row>
  81. </div>
  82. </template>
  83. <script>
  84. import {getPowerData, getPowerMaxLoad, getPowerDayMaxLoad} from '@/api/mgr/elecUseH'
  85. import {areaWithFacsCategoryAsTree} from '@/api/basecfg/area'
  86. import BaseChart from '@/components/BaseChart'
  87. import SubTitle from '@/components/SubTitle'
  88. import Treeselect from "@riophae/vue-treeselect";
  89. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  90. import {dateFormat, getDayAgoDate} from '@/utils'
  91. export default {
  92. name: 'Comsume',
  93. components: {
  94. Treeselect,
  95. BaseChart,
  96. SubTitle
  97. },
  98. data () {
  99. const lastWeek = dateFormat(getDayAgoDate(7), 'yyyy-MM-dd')
  100. const nowDay = dateFormat(new Date(), 'yyyy-MM-dd')
  101. return {
  102. // 遮罩层
  103. facsCategory: 'Z',
  104. facsSubCategory: '',
  105. areaName: undefined,
  106. defaultProps: {
  107. children: "children",
  108. label: "label"
  109. },
  110. selectedLabel: '',
  111. // 查询参数
  112. queryParams: {
  113. areaCode: ''
  114. },
  115. pickerOptions: {
  116. shortcuts: [
  117. {
  118. text: '最近一周',
  119. onClick (picker) {
  120. const end = new Date()
  121. const start = new Date()
  122. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  123. picker.$emit('pick', [start, end])
  124. }
  125. }, {
  126. text: '最近一个月',
  127. onClick (picker) {
  128. const end = new Date()
  129. const start = new Date()
  130. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  131. picker.$emit('pick', [start, end])
  132. }
  133. }, {
  134. text: '最近三个月',
  135. onClick (picker) {
  136. const end = new Date()
  137. const start = new Date()
  138. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  139. picker.$emit('pick', [start, end])
  140. }
  141. }
  142. ]
  143. },
  144. // 表单参数
  145. areaOptions: [],
  146. dateRange: [`${lastWeek} 00:00:00`, `${nowDay} 23:59:59`],
  147. activeBtn: 'chart', //--chart图表 --table表格
  148. btnGroup: [
  149. {
  150. name: 'chart',
  151. icon: 'el-icon-s-data'
  152. },
  153. {
  154. name: 'table',
  155. icon: 'el-icon-menu'
  156. }],
  157. powerChartData: [],
  158. powerMaxLoad: '',
  159. maxPowerDate: [`${lastWeek} 00:00:00`, `${nowDay} 23:59:59`],
  160. maxLoadData: []
  161. }
  162. },
  163. computed: {
  164. powerLineOptions () {
  165. const xAxisData = this.powerChartData.map(item => `${item.date.substr(5)} ${item.time.substr(0, 5)} `);
  166. const yData1 = this.powerChartData.map(item => parseFloat(item.s).toFixed(2));
  167. const yData2 = this.powerChartData.map(item => item.p);
  168. const yData3 = this.powerChartData.map(item => item.q);
  169. return {
  170. toolbox: {
  171. itemGap: 10,
  172. itemSize: 16,
  173. right: 10,
  174. top: 0,
  175. show: true,
  176. feature: {
  177. magicType: {
  178. show: true,
  179. type: ['bar', 'line']
  180. },
  181. saveAsImage: {
  182. show: true
  183. }
  184. }
  185. },
  186. tooltip: {
  187. trigger: 'axis',
  188. axisPointer: {
  189. type: 'shadow'
  190. },
  191. formatter: (params) => {
  192. var relVal = params[0].name
  193. for (var i = 0, l = params.length; i < l; i++) {
  194. relVal =
  195. relVal +
  196. '<br/>' +
  197. params[i].marker +
  198. params[i].seriesName +
  199. '&nbsp;&nbsp;&nbsp;' +
  200. params[i].value +
  201. 'kW'
  202. }
  203. return relVal
  204. }
  205. },
  206. legend: {
  207. },
  208. xAxis: {
  209. type: 'category',
  210. data: xAxisData
  211. },
  212. yAxis: {
  213. name: 'kW(千瓦)',
  214. type: 'value',
  215. },
  216. dataZoom: [
  217. {
  218. type: "slider",
  219. start: 0,
  220. end: 100,
  221. height: 10,
  222. bottom: '5%',
  223. showDetail: false,
  224. showDataShadow: false,
  225. borderColor: "transparent"
  226. },
  227. {
  228. type: "inside",
  229. start: 0,
  230. end: 100,
  231. },
  232. ],
  233. series: [{
  234. name: '视在功率',
  235. type: 'line',
  236. data: yData1,
  237. markLine: {
  238. symbol: 'none',
  239. silent: true,
  240. lineStyle: {normal: {type: 'dashed'}},
  241. label: {position: 'end'},
  242. data: [
  243. {
  244. yAxis: this.powerMaxLoad,
  245. lineStyle: {width: 1.656, color: '#ff6367'},
  246. label: {
  247. show: true,
  248. textStyle: {
  249. color: '#ff6367'
  250. }
  251. }
  252. },
  253. ]
  254. },
  255. markPoint: {
  256. silent: true,
  257. data: [
  258. {
  259. yAxis: this.powerMaxLoad,
  260. x: '100%',
  261. symbolSize: 0.1,
  262. symbolOffset: [0, 0],
  263. label: {
  264. textStyle: {color: '#ff6367'},
  265. fontSize: 12,
  266. position: 'left',
  267. formatter: '最高负荷'
  268. }
  269. },
  270. ]
  271. },
  272. },
  273. {
  274. name: '有功功率',
  275. type: 'line',
  276. data: yData2,
  277. },
  278. {
  279. name: '无功功率',
  280. type: 'line',
  281. data: yData3,
  282. },]
  283. };
  284. },
  285. maxLoadLineOptions () {
  286. const xAxisData = this.maxLoadData.map(item => item.date);
  287. const yData1 = this.maxLoadData.map(item => parseFloat(item.s).toFixed(2));
  288. const yData2 = this.maxLoadData.map(item => item.p);
  289. const yData3 = this.maxLoadData.map(item => item.q);
  290. return {
  291. toolbox: {
  292. itemGap: 10,
  293. itemSize: 16,
  294. right: 10,
  295. top: 0,
  296. show: true,
  297. feature: {
  298. magicType: {
  299. show: true,
  300. type: ['bar', 'line']
  301. },
  302. saveAsImage: {
  303. show: true
  304. }
  305. }
  306. },
  307. tooltip: {
  308. trigger: 'axis',
  309. axisPointer: {
  310. type: 'shadow'
  311. }
  312. },
  313. legend: {
  314. },
  315. xAxis: {
  316. type: 'category',
  317. data: xAxisData
  318. },
  319. yAxis: {
  320. name: 'kW(千瓦)',
  321. type: 'value',
  322. },
  323. dataZoom: [
  324. {
  325. type: "slider",
  326. start: 0,
  327. end: 100,
  328. height: 10,
  329. bottom: '5%',
  330. showDetail: false,
  331. showDataShadow: false,
  332. borderColor: "transparent"
  333. },
  334. {
  335. type: "inside",
  336. start: 0,
  337. end: 100,
  338. },
  339. ],
  340. series: [{
  341. name: '视在功率',
  342. type: 'line',
  343. data: yData1,
  344. },
  345. {
  346. name: '有功功率',
  347. type: 'line',
  348. data: yData2,
  349. },
  350. {
  351. name: '无功功率',
  352. type: 'line',
  353. data: yData3,
  354. },]
  355. };
  356. },
  357. },
  358. watch: {
  359. // 根据名称筛选区域树
  360. areaName (val) {
  361. this.$refs.tree.filter(val)
  362. }
  363. },
  364. async created () {
  365. await this.getAreaList()
  366. this.getPowerChart()
  367. this.getDayMaxLoad()
  368. },
  369. methods: {
  370. btnChange (item) {
  371. this.activeBtn = item.name
  372. },
  373. getPowerChart () {
  374. this.powerMaxLoad = ''
  375. this.powerChartData = []
  376. const [startTime, endTime] = this.dateRange
  377. const params = {
  378. startTime,
  379. endTime,
  380. areaCode: this.queryParams.areaCode,
  381. objType: '1',
  382. }
  383. getPowerData({
  384. ...params,
  385. pageNum: 1,
  386. pageSize: 999
  387. }).then(({code, rows}) => {
  388. if (code === 200) {
  389. this.powerChartData = rows
  390. }
  391. })
  392. getPowerMaxLoad(params).then(({code, data}) => {
  393. if (code === 200) {
  394. this.powerMaxLoad = parseFloat(data.s).toFixed(2)
  395. }
  396. })
  397. },
  398. getDayMaxLoad () {
  399. const [startTime, endTime] = this.maxPowerDate
  400. getPowerDayMaxLoad({
  401. startTime,
  402. endTime,
  403. areaCode: this.queryParams.areaCode,
  404. objType: '1',
  405. }).then(({code, rows}) => {
  406. if (code === 200) {
  407. this.maxLoadData = rows || []
  408. }
  409. })
  410. },
  411. // 查询区域列表
  412. async getAreaList () {
  413. await areaWithFacsCategoryAsTree(this.facsCategory, this.facsSubCategory).then(response => {
  414. this.areaOptions = [{
  415. id: '-1',
  416. label: '全部',
  417. children: []
  418. }].concat(response.data)
  419. this.selectedLabel = '全部'
  420. this.queryParams.areaCode = '-1'
  421. })
  422. },
  423. // 筛选节点
  424. filterNode (value, data) {
  425. if (!value) return true
  426. return data.label.indexOf(value) !== -1
  427. },
  428. // 节点单击事件
  429. handleNodeClick (data) {
  430. this.queryParams.areaCode = data.id
  431. this.selectedLabel = data.label
  432. this.getPowerChart()
  433. this.getDayMaxLoad()
  434. },
  435. }
  436. }
  437. </script>
  438. <style lang="scss" scoped>
  439. @import './index.scss';
  440. .app-container {
  441. ::v-deep .el-tabs__content {
  442. overflow: initial;
  443. }
  444. }
  445. .ctl-container {
  446. display: flex;
  447. justify-content: flex-end;
  448. margin: 10px 0;
  449. }
  450. </style>