| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- // pages/Information/index.js
- import * as echarts from '../../ec-canvas/echarts';
- const api = require('../../api/index.js');
-
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- daydata:[],
- tabsindex:1,
- ech: {
- lazyLoad: true
- },
- ymdlist:[],
- chargeTotal:[],
- powerdata:[],
- powerindex:0,
- datestart:'',
- formatio:[]
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.ecline = this.selectComponent('#mychart_line2');
- // 获取当前日期对象
- const now = new Date();
-
- // 获取当前年份(4位数字)
- const year = now.getFullYear();
-
- // 获取当前月份(注意:月份从 0 开始,所以需要 +1)
- const month = now.getMonth() + 1;
-
- // 如需补全两位数字(如 3 月显示为 "03")
- const monthStr = month.toString().padStart(2, '0');
- this.setData({
- datestart:`${year}-${monthStr}`
- })
- this.getpowerdata()
- },
- // 选项卡
- onTabsChange(e){
- console.log(e.detail.value);
- this.setData({
- tabsindex:e.detail.value
- })
- if (e.detail.value==1) {
- this.setData({
- ymdlist:this.data.formatio.map(item => item.day),
- chargeTotal:this.data.formatio.map(item => item.averagespeed)
- })
- this.initChart_right()
-
- }else if(e.detail.value==2){
- this.setData({
- ymdlist:this.data.formatio.map(item => item.day),
- chargeTotal:this.data.formatio.map(item => item.dailydischarge)
- })
- this.initChart_right()
-
- }else if(e.detail.value==3){
- this.setData({
- ymdlist:this.data.formatio.map(item => item.day),
- chargeTotal:this.data.formatio.map(item => item.dailypowerlimit)
- })
- this.initChart_right()
-
- }else if(e.detail.value==4){
- this.setData({
- ymdlist:this.data.formatio.map(item => item.day),
- chargeTotal:this.data.formatio.map(item => item.dayfaultlosselectricity)
- })
- this.initChart_right()
-
- }
-
- },
- initChart_right: function () {
- var unitName = '';
- if (this.data.tabsindex==1) {
- unitName = '风速 m/s'
-
- }else if(this.data.tabsindex==2){
- unitName = '日发电量 万/kWh'
-
- }else if(this.data.tabsindex==3){
- unitName = '限电指令负荷不超过 MW'
-
- }else if(this.data.tabsindex==4){
- unitName = '当日故障损失电量 万/kWh'
-
- }
- let _this = this;
- this.ecline.init((canvas, width, height, dpr) => {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- canvas.setChart(chart);
- var option = {
- title: {
- subtext: unitName,
- textStyle: {
- color: 'rgba(0, 0, 0, 0)',
- }
- },
- grid: {
- left: '1%',
- top: '14%',
- right: '1%',
- bottom: '10%',
- containLabel: true
- },
-
- xAxis: {
- type: 'category',
- data: _this.data.ymdlist,
- axisTick: {
- show: false
- },
- barWidth: 20,
- axisLabel: {
- interval: 0 // 设置为0以显示所有坐标点
-
- },
-
-
- },
- yAxis: {
- // name: unitName,
- x: 'center',
- type: 'value',
- axisTick: {
- show: false
- },
- splitLine: {
- show: false
- }
- },
- dataZoom: {
- type: 'inside',
- start: 0,
- end: 50
- },
- // dataZoom: {
- // type: 'slider',
- // start: 0,
- // end: 50,
- // handleSize:0,
- // show:false
-
- // },
- series: [{
- type:"bar",
- barMaxWidth: 20,
- smooth: true,
- label: {
- show: true,
- position: 'top',
- color:'#222'
- },
- showSymbol: false,
- data: _this.data.chargeTotal,
- itemStyle: {
- color: 'rgba(60, 158, 250, 1)',
- barBorderRadius: [4, 4, 0, 0] // 设置柱状图的圆角半径为5
- },
- areaStyle: {
- color: 'rgba(60, 158, 250, 1)',
- }
- }
- // ,{
- // name: viewname[1],
- // type: _this.data.echartstype,
- // smooth: true,
- // showSymbol: false,
- // barMaxWidth: 20,
- // data: _this.data.dischargeTotal,
- // itemStyle: {
- // color: 'rgba(77, 240, 150, 1)',
- // barBorderRadius: [5, 5, 0, 0]
- // },
- // areaStyle: {
- // color: 'rgba(77, 240, 150, 1)',
- // }
- // }
- ]
- };
-
- chart.setOption(option);
- return chart;
- })
- },
- bindpowerChange(e){
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- powerindex: e.detail.value
- })
-
- },
- // 电站
- getpowerdata(){
-
- api.request(`/syspowerstation/selectpowestation`, 'POST')
- .then((res) => {
- console.log(res);
- this.setData({
- powerdata:res.data
- })
- this.getpowerformatio()
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- // 基本信息
- getpowerformatio(){
- let data ={
- powerstationId:this.data.powerdata[this.data.powerindex].powerstationId,
- month:this.data.datestart
- }
- api.request(`/syspowerstation/selectpowerstationinformation`, 'POST',data)
- .then((res) => {
- // 遍历数组,修改每个元素的 day 属性(截取最后两位)
- res.data = res.data.map(item => ({
- ...item, // 保留其他属性
- day: item.day.slice(-2) // 截取 day 的最后两位
- }));
- // this.setData({
- // res.data: res.data.map(item => item.day.slice(-2))
- // })
- this.setData({
- formatio:res.data
- })
-
- this.setData({
- ymdlist:res.data.map(item => item.day.slice(-2)),
- chargeTotal:res.data.map(item => item.averagespeed)
- })
- this.initChart_right()
-
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- // 选择时间
- bindstartChange: function(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- datestart: e.detail.value
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|