储能智慧云小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. import * as echarts from '../../ec-canvas/echarts';
  2. import * as liquidFill from '../../ec-canvas/echarts-liquidfill.min';
  3. const util = require('../../utils/util.js')
  4. const api = require('../../api/index.js');
  5. const moment = require('moment');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. // 状态栏高度
  12. statusBarHeight: wx.getStorageSync('statusBarHeight'),
  13. // 导航栏高度
  14. navBarHeight: wx.getStorageSync('navBarHeight'),
  15. // 导航栏和状态栏高度
  16. navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
  17. // 胶囊
  18. menu:wx.getStorageSync('menu'),
  19. mode: '',
  20. datetimeVisible: false,
  21. datetime: new Date('2021-12-23').getTime(),
  22. datetimeText: '',
  23. img_path:'',
  24. tapindex:0,
  25. labelindex:1,
  26. visible: false,
  27. ec: {
  28. lazyLoad: true
  29. },
  30. ech: {
  31. lazyLoad: true
  32. },
  33. value:[],
  34. valueitem:'',
  35. minDate: new Date(2022, 1, 1).getTime(),
  36. maxDate: new Date(util.getdataTime('当日')).getTime(),
  37. format(day) {
  38. const { date } = day;
  39. const year = date.getFullYear();
  40. const month = date.getMonth() + 1;
  41. const curDate = date.getDate();
  42. if (year== moment().format('YYYY')) {
  43. if(month== moment().format('MM')){
  44. if(curDate== moment().format('DD')){
  45. day.suffix = '今日';
  46. }
  47. }
  48. }
  49. return day;
  50. },
  51. Electricitylevel:[],
  52. chargeTotal:[],
  53. dischargeTotal:[],
  54. ymdlist:[],
  55. echartstype:'bar',
  56. unm:0,
  57. current:0,
  58. rangetype:''
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad(options) {
  64. // let base64imgages =util.Background_base64('https://esos-iot.bjdexn.cn/wx_images/bj.png')
  65. this.setData({
  66. img_path:'https://esos-iot.bjdexn.cn/wx_images/bj.png',
  67. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  68. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  69. })
  70. this.ecComponent = this.selectComponent('#mychart_line1');
  71. this.ecline = this.selectComponent('#mychart_line2');
  72. this.getlineMonth()
  73. },
  74. // 返回上一级
  75. onIconTap(){
  76. wx.navigateBack({
  77. delta: 1
  78. });
  79. },
  80. // 切换标签
  81. ontop(e){
  82. // console.log(e);
  83. this.setData({
  84. tapindex:e.detail.current
  85. })
  86. console.log(this.data.tapindex);
  87. if (this.data.tapindex==0) {
  88. this.ecComponent = this.selectComponent('#mychart_line1');
  89. this.ecline = this.selectComponent('#mychart_line2');
  90. this.setData({
  91. labelindex:1,
  92. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  93. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  94. echartstype:'bar'
  95. })
  96. this.getlineMonth();
  97. }else if(this.data.tapindex==1){
  98. this.ecline = this.selectComponent('#mychart_line2');
  99. this.setData({
  100. valueitem:util.getdataTime('当日'),
  101. value:new Date(util.getdataTime('当日')).getTime(),
  102. echartstype:'line'
  103. })
  104. this.Powertrend();
  105. }else if(this.data.tapindex==2){
  106. this.ecline = this.selectComponent('#mychart_line2');
  107. this.setData({
  108. labelindex:1,
  109. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  110. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  111. echartstype:'bar'
  112. })
  113. this.electrictime()
  114. }
  115. },
  116. onlabel(e){
  117. this.setData({
  118. labelindex:e.target.dataset.index
  119. })
  120. if (this.data.tapindex==0) {
  121. if (this.data.labelindex==1) {
  122. this.setData({
  123. echartstype:'bar',
  124. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  125. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  126. })
  127. }else if(this.data.labelindex==2){
  128. this.setData({
  129. echartstype:'line',
  130. value:[new Date(util.getdataTime(31)).getTime(),new Date(util.getdataTime('当日')).getTime()],
  131. valueitem:`${util.getdataTime(31)} - ${util.getdataTime('当日')}`,
  132. })
  133. }else{
  134. this.setData({
  135. echartstype:'line',
  136. value:[new Date(util.getdataTime(365)).getTime(),new Date(util.getdataTime('当日')).getTime()],
  137. valueitem:`${util.getdataTime(365)} - ${util.getdataTime('当日')}`,
  138. })
  139. }
  140. this.getlineMonth();
  141. }else if(this.data.tapindex==1){
  142. this.ecline = this.selectComponent('#mychart_line2');
  143. this.setData({
  144. valueitem:util.getdataTime('当日'),
  145. echartstype:'line'
  146. })
  147. this.Powertrend();
  148. }else if(this.data.tapindex==2){
  149. if (this.data.labelindex==1) {
  150. this.setData({
  151. echartstype:'bar',
  152. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  153. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  154. })
  155. }else if(this.data.labelindex==2){
  156. this.setData({
  157. echartstype:'line',
  158. value:[new Date(util.getdataTime(31)).getTime(),new Date(util.getdataTime('当日')).getTime()],
  159. valueitem:`${util.getdataTime(31)} - ${util.getdataTime('当日')}`,
  160. })
  161. }else{
  162. this.setData({
  163. echartstype:'line',
  164. value:[new Date(util.getdataTime(365)).getTime(),new Date(util.getdataTime('当日')).getTime()],
  165. valueitem:`${util.getdataTime(365)} - ${util.getdataTime('当日')}`,
  166. })
  167. }
  168. this.electrictime();
  169. }
  170. },
  171. // 上一天
  172. Lastday(){
  173. this.data.unm++
  174. this.setData({
  175. unm:this.data.unm
  176. })
  177. this.ecline = this.selectComponent('#mychart_line2');
  178. this.setData({
  179. valueitem:util.CumulativeTime(this.data.unm),
  180. echartstype:'line'
  181. })
  182. this.Powertrend();
  183. },
  184. handleCalendar() {
  185. if (this.data.tapindex==1) {
  186. this.setData({
  187. visible: true,
  188. rangetype:'single'
  189. })
  190. }else{
  191. this.setData({
  192. visible: true,
  193. rangetype:'range'
  194. })
  195. }
  196. },
  197. // 下一天
  198. dayfollowing(){
  199. if (this.data.unm==0) {
  200. return wx.showToast({
  201. title: '不可超出当前时间',
  202. icon: 'none',
  203. });
  204. }
  205. this.data.unm--
  206. this.setData({
  207. unm:this.data.unm
  208. })
  209. this.ecline = this.selectComponent('#mychart_line2');
  210. this.setData({
  211. valueitem:util.CumulativeTime(this.data.unm),
  212. echartstype:'line'
  213. })
  214. this.Powertrend();
  215. },
  216. // 时间区间范围
  217. bindclose(){
  218. this.setData({
  219. visible: false
  220. })
  221. },
  222. handleConfirm(e) {
  223. console.log(e);
  224. let formattedTime =[]
  225. if (this.data.tapindex==1) {
  226. formattedTime.push(moment(e.detail.value).format('YYYY-MM-DD'));
  227. this.setData({
  228. visible: false,
  229. valueitem:`${formattedTime[0]}`,
  230. value:e.detail.value
  231. });
  232. this.Powertrend();
  233. }else{
  234. if (e.detail.value.length==0) {
  235. e.detail.value.forEach(ts => {
  236. formattedTime.push(moment(ts).format('YYYY-MM-DD'));
  237. });
  238. this.setData({
  239. visible: false,
  240. valueitem:`${formattedTime[0]} - ${util.getdataTime('当日')}`,
  241. value:e.detail.value
  242. });
  243. }else{
  244. e.detail.value.forEach(ts => {
  245. formattedTime.push(moment(ts).format('YYYY-MM-DD'));
  246. });
  247. this.setData({
  248. visible: false,
  249. valueitem:`${formattedTime[0]} - ${formattedTime[1]}`,
  250. value:e.detail.value
  251. });
  252. }
  253. if (this.data.tapindex==1) {
  254. this.getlineMonth()
  255. }else{
  256. this.electrictime()
  257. }
  258. }
  259. },
  260. // 电量
  261. getlineMonth(){
  262. let data={
  263. startDate:moment(this.data.value[0]).format('YYYY-MM-DD'),
  264. endDate:moment(this.data.value[1]).format('YYYY-MM-DD')
  265. }
  266. api.request(`/stats/singleStation/${wx.getStorageSync('station').id}/betweenhe`, 'POST',data )
  267. .then((res) => {
  268. let { list } = res.data;
  269. let chargeTotal = list.map(item => item.chargeTotal);
  270. let dischargeTotal = list.map(item => item.dischargeTotal);
  271. let ymdlist = list.map(item => item.ymd.slice(5, 11));
  272. this.setData({
  273. Electricitylevel: res.data,
  274. chargeTotal: chargeTotal,
  275. dischargeTotal: dischargeTotal,
  276. ymdlist: ymdlist,
  277. });
  278. this.initChartright()
  279. this.initChart_right()
  280. })
  281. .catch((err) => {
  282. console.error('请求失败:', err);
  283. // 在这里处理请求失败的情况
  284. });
  285. },
  286. Powertrend(){
  287. // 充放电功率
  288. api.request(`/station/${wx.getStorageSync('station').id}/system/power/trend`, 'POST',{data:this.data.valueitem} )
  289. .then((res) => {
  290. let list = res.data;
  291. console.log(list);
  292. let chargeTotal = list.gridPower.map(item => item.totalActivePower);
  293. let dischargeTotal = list.storedPower.map(item => item.totalActivePower);
  294. let ymdlist = list.gridPower.map(item => item.ts.slice(12, 16));
  295. this.setData({
  296. Electricitylevel: res.data,
  297. chargeTotal: chargeTotal,
  298. dischargeTotal: dischargeTotal,
  299. ymdlist: ymdlist,
  300. });
  301. this.initChart_right()
  302. })
  303. .catch((err) => {
  304. console.error('请求失败:', err);
  305. // 在这里处理请求失败的情况
  306. });
  307. },
  308. // 充放电时间
  309. electrictime(){
  310. let data={
  311. startDate:moment(this.data.value[0]).format('YYYY-MM-DD'),
  312. endDate:moment(this.data.value[1]).format('YYYY-MM-DD')
  313. }
  314. // 充放电时间
  315. api.request(`/stats/singleStation/${wx.getStorageSync('station').id}/between/time`, 'POST',data )
  316. .then((res) => {
  317. let { list } = res.data;
  318. console.log(list);
  319. let chargeTotal = list.map(item => item.chargetime);
  320. let dischargeTotal = list.map(item => item.dischargetime);
  321. let ymdlist = list.map(item => item.ym.slice(5, 11));
  322. this.setData({
  323. Electricitylevel: res.data,
  324. chargeTotal: chargeTotal,
  325. dischargeTotal: dischargeTotal,
  326. ymdlist: ymdlist,
  327. });
  328. this.initChart_right()
  329. })
  330. .catch((err) => {
  331. console.error('请求失败:', err);
  332. // 在这里处理请求失败的情况
  333. });
  334. },
  335. onTabsChange(event) {
  336. this.setData({
  337. tapindex:event.detail.value
  338. })
  339. },
  340. onStickyScroll(event) {
  341. console.log(event.detail);
  342. },
  343. /**
  344. * 生命周期函数--监听页面初次渲染完成
  345. */
  346. onReady() {
  347. },
  348. /**
  349. * 生命周期函数--监听页面显示
  350. */
  351. onShow() {
  352. },
  353. /**
  354. * 生命周期函数--监听页面隐藏
  355. */
  356. onHide() {
  357. },
  358. /**
  359. * 生命周期函数--监听页面卸载
  360. */
  361. onUnload() {
  362. },
  363. /**
  364. * 页面相关事件处理函数--监听用户下拉动作
  365. */
  366. onPullDownRefresh() {
  367. },
  368. /**
  369. * 页面上拉触底事件的处理函数
  370. */
  371. onReachBottom() {
  372. },
  373. /**
  374. * 用户点击右上角分享
  375. */
  376. onShareAppMessage() {
  377. },
  378. initChartright: function(){
  379. let _this = this
  380. this.ecComponent.init((canvas, width, height, dpr)=> {
  381. const chart = echarts.init(canvas, null, {
  382. width: width,
  383. height: height,
  384. devicePixelRatio: dpr // new
  385. });
  386. canvas.setChart(chart);
  387. var option = {
  388. legend:[ {
  389. right: '0', // 图例水平居中
  390. bottom: '35%',
  391. itemHeight:8,
  392. itemWidth:8,
  393. icon:"circle",
  394. formatter: function (name) {
  395. return name + _this.data.Electricitylevel.total.sumdischargeTotal+' kwh'; // 在名称和单位之间添加空格间距
  396. },
  397. data:[
  398. {name: '累计充电'},
  399. ]
  400. },{
  401. right: '0', // 图例水平居中
  402. bottom: '50%',
  403. itemHeight:8,
  404. itemWidth:8,
  405. icon:"circle",
  406. formatter: function (name) {
  407. return name + _this.data.Electricitylevel.total.sumchargeTotal + ' kwh'; // 在名称和单位之间添加空格间距
  408. },
  409. data:[
  410. {name: '累计放电'},
  411. ]
  412. }],
  413. tooltip: {
  414. trigger: 'item'
  415. },
  416. series: [{
  417. type: 'pie',
  418. radius: ['40%', '60%'],
  419. center: ['20%', '50%'],
  420. avoidLabelOverlap: false,
  421. label: {
  422. show: false,
  423. position: 'center'
  424. },
  425. emphasis: {
  426. label: {
  427. show: true,
  428. fontSize: 0,
  429. fontWeight: 'bold'
  430. }
  431. },
  432. labelLine: {
  433. show: false
  434. },
  435. data: [{
  436. value: _this.data.Electricitylevel.total.sumchargeTotal,
  437. name: '累计充电',
  438. itemStyle: { color: '#4DF096' }
  439. }, {
  440. value: _this.data.Electricitylevel.total.sumdischargeTotal,
  441. name: '累计放电',
  442. itemStyle: { color: '#3C9EFA' }
  443. }
  444. ]
  445. }]
  446. };
  447. chart.setOption(option);
  448. return chart;
  449. })},
  450. initChart_right: function () {
  451. var unitName = 'kWh';
  452. var viewname = ['充电量','放电量'];
  453. if (this.data.tapindex==0) {
  454. unitName = 'kWh';
  455. viewname = ['充电量','放电量'];
  456. }else if(this.data.tapindex==1){
  457. unitName = 'kW';
  458. viewname = ['峰值充电功率','峰值放电功率'];
  459. }else if(this.data.tapindex==2){
  460. unitName = 'h';
  461. viewname = ['充电时长','放电时长'];
  462. }
  463. let _this = this
  464. this.ecline.init((canvas, width, height, dpr)=> {
  465. const chart = echarts.init(canvas, null, {
  466. width: width,
  467. height: height,
  468. devicePixelRatio: dpr // new
  469. });
  470. canvas.setChart(chart);
  471. var option = {
  472. legend: { bottom: '0%'},
  473. grid: {
  474. left:'1%',
  475. top:'20%',
  476. right:'1%',
  477. bottom:'20%',
  478. containLabel: true
  479. },
  480. tooltip: {
  481. show: true,
  482. trigger: 'axis'
  483. },
  484. xAxis: {
  485. type: 'category',
  486. data:_this.data.ymdlist,
  487. // show: false,
  488. axisTick: {
  489. show: false // 这里设置x轴的刻度线不显示
  490. },
  491. barWidth: 10 // 设置柱状图的宽度
  492. },
  493. yAxis: {
  494. name:'单位:'+unitName,
  495. x: 'center',
  496. type: 'value',
  497. axisTick: {
  498. show: false // 这里设置x轴的刻度线不显示
  499. },
  500. splitLine: {
  501. show: false // 这里设置x轴的刻度线不显示
  502. },
  503. // show: false
  504. },
  505. series: [{
  506. name: viewname[0],
  507. type: _this.data.echartstype,
  508. barMaxWidth: 20,// 设置柱状图的宽度
  509. smooth: true,
  510. showSymbol: false,
  511. data:_this.data.chargeTotal,
  512. itemStyle: {
  513. color: 'rgba(60, 158, 250, 0.5)' // 设置数据点颜色为蓝色(使用十六进制表示法)
  514. },
  515. areaStyle: {
  516. color: 'rgba(60, 158, 250, 0.3)' // 设置区域填充颜色
  517. }
  518. },{
  519. name: viewname[1],
  520. type: _this.data.echartstype,
  521. smooth: true,
  522. showSymbol: false,
  523. barMaxWidth: 20,// 设置柱状图的宽度
  524. data: _this.data.dischargeTotal,
  525. itemStyle: {
  526. color: 'rgba(77, 240, 150, 0.5)' // 设置数据点颜色为绿色(使用十六进制表示法)
  527. },
  528. areaStyle: {
  529. color: 'rgba(77, 240, 150, 0.3)' // 设置区域填充颜色为半透明的绿色
  530. }
  531. } ]
  532. };
  533. chart.setOption(option);
  534. return chart;
  535. })}
  536. })