运维小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. // pages/Information/index.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. const api = require('../../api/index.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. daydata:[],
  10. tabsindex:1,
  11. ech: {
  12. lazyLoad: true
  13. },
  14. ymdlist:[],
  15. chargeTotal:[],
  16. powerdata:[],
  17. powerindex:0,
  18. datestart:'',
  19. formatio:[]
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad(options) {
  25. this.ecline = this.selectComponent('#mychart_line2');
  26. // 获取当前日期对象
  27. const now = new Date();
  28. // 获取当前年份(4位数字)
  29. const year = now.getFullYear();
  30. // 获取当前月份(注意:月份从 0 开始,所以需要 +1)
  31. const month = now.getMonth() + 1;
  32. // 如需补全两位数字(如 3 月显示为 "03")
  33. const monthStr = month.toString().padStart(2, '0');
  34. this.setData({
  35. datestart:`${year}-${monthStr}`
  36. })
  37. this.getpowerdata()
  38. },
  39. // 选项卡
  40. onTabsChange(e){
  41. console.log(e.detail.value);
  42. this.setData({
  43. tabsindex:e.detail.value
  44. })
  45. if (e.detail.value==1) {
  46. this.setData({
  47. ymdlist:this.data.formatio.map(item => item.day),
  48. chargeTotal:this.data.formatio.map(item => item.averagespeed)
  49. })
  50. this.initChart_right()
  51. }else if(e.detail.value==2){
  52. this.setData({
  53. ymdlist:this.data.formatio.map(item => item.day),
  54. chargeTotal:this.data.formatio.map(item => item.dailydischarge)
  55. })
  56. this.initChart_right()
  57. }else if(e.detail.value==3){
  58. this.setData({
  59. ymdlist:this.data.formatio.map(item => item.day),
  60. chargeTotal:this.data.formatio.map(item => item.dailypowerlimit)
  61. })
  62. this.initChart_right()
  63. }else if(e.detail.value==4){
  64. this.setData({
  65. ymdlist:this.data.formatio.map(item => item.day),
  66. chargeTotal:this.data.formatio.map(item => item.dayfaultlosselectricity)
  67. })
  68. this.initChart_right()
  69. }
  70. },
  71. initChart_right: function () {
  72. var unitName = '';
  73. if (this.data.tabsindex==1) {
  74. unitName = '风速 m/s'
  75. }else if(this.data.tabsindex==2){
  76. unitName = '日发电量 万/kWh'
  77. }else if(this.data.tabsindex==3){
  78. unitName = '限电指令负荷不超过 MW'
  79. }else if(this.data.tabsindex==4){
  80. unitName = '当日故障损失电量 万/kWh'
  81. }
  82. let _this = this;
  83. this.ecline.init((canvas, width, height, dpr) => {
  84. const chart = echarts.init(canvas, null, {
  85. width: width,
  86. height: height,
  87. devicePixelRatio: dpr
  88. });
  89. canvas.setChart(chart);
  90. var option = {
  91. title: {
  92. subtext: unitName,
  93. textStyle: {
  94. color: 'rgba(0, 0, 0, 0)',
  95. }
  96. },
  97. grid: {
  98. left: '1%',
  99. top: '14%',
  100. right: '1%',
  101. bottom: '10%',
  102. containLabel: true
  103. },
  104. xAxis: {
  105. type: 'category',
  106. data: _this.data.ymdlist,
  107. axisTick: {
  108. show: false
  109. },
  110. barWidth: 20,
  111. axisLabel: {
  112. interval: 0 // 设置为0以显示所有坐标点
  113. },
  114. },
  115. yAxis: {
  116. // name: unitName,
  117. x: 'center',
  118. type: 'value',
  119. axisTick: {
  120. show: false
  121. },
  122. splitLine: {
  123. show: false
  124. }
  125. },
  126. dataZoom: {
  127. type: 'inside',
  128. start: 0,
  129. end: 50
  130. },
  131. // dataZoom: {
  132. // type: 'slider',
  133. // start: 0,
  134. // end: 50,
  135. // handleSize:0,
  136. // show:false
  137. // },
  138. series: [{
  139. type:"bar",
  140. barMaxWidth: 20,
  141. smooth: true,
  142. label: {
  143. show: true,
  144. position: 'top',
  145. color:'#222'
  146. },
  147. showSymbol: false,
  148. data: _this.data.chargeTotal,
  149. itemStyle: {
  150. color: 'rgba(60, 158, 250, 1)',
  151. barBorderRadius: [4, 4, 0, 0] // 设置柱状图的圆角半径为5
  152. },
  153. areaStyle: {
  154. color: 'rgba(60, 158, 250, 1)',
  155. }
  156. }
  157. // ,{
  158. // name: viewname[1],
  159. // type: _this.data.echartstype,
  160. // smooth: true,
  161. // showSymbol: false,
  162. // barMaxWidth: 20,
  163. // data: _this.data.dischargeTotal,
  164. // itemStyle: {
  165. // color: 'rgba(77, 240, 150, 1)',
  166. // barBorderRadius: [5, 5, 0, 0]
  167. // },
  168. // areaStyle: {
  169. // color: 'rgba(77, 240, 150, 1)',
  170. // }
  171. // }
  172. ]
  173. };
  174. chart.setOption(option);
  175. return chart;
  176. })
  177. },
  178. bindpowerChange(e){
  179. console.log('picker发送选择改变,携带值为', e.detail.value)
  180. this.setData({
  181. powerindex: e.detail.value
  182. })
  183. },
  184. // 电站
  185. getpowerdata(){
  186. api.request(`/syspowerstation/selectpowestation`, 'POST')
  187. .then((res) => {
  188. console.log(res);
  189. this.setData({
  190. powerdata:res.data
  191. })
  192. this.getpowerformatio()
  193. })
  194. .catch((err) => {
  195. console.error('请求失败:', err);
  196. // 在这里处理请求失败的情况
  197. });
  198. },
  199. // 基本信息
  200. getpowerformatio(){
  201. let data ={
  202. powerstationId:this.data.powerdata[this.data.powerindex].powerstationId,
  203. month:this.data.datestart
  204. }
  205. api.request(`/syspowerstation/selectpowerstationinformation`, 'POST',data)
  206. .then((res) => {
  207. // 遍历数组,修改每个元素的 day 属性(截取最后两位)
  208. res.data = res.data.map(item => ({
  209. ...item, // 保留其他属性
  210. day: item.day.slice(-2) // 截取 day 的最后两位
  211. }));
  212. // this.setData({
  213. // res.data: res.data.map(item => item.day.slice(-2))
  214. // })
  215. this.setData({
  216. formatio:res.data
  217. })
  218. this.setData({
  219. ymdlist:res.data.map(item => item.day.slice(-2)),
  220. chargeTotal:res.data.map(item => item.averagespeed)
  221. })
  222. this.initChart_right()
  223. })
  224. .catch((err) => {
  225. console.error('请求失败:', err);
  226. // 在这里处理请求失败的情况
  227. });
  228. },
  229. // 选择时间
  230. bindstartChange: function(e) {
  231. console.log('picker发送选择改变,携带值为', e.detail.value)
  232. this.setData({
  233. datestart: e.detail.value
  234. })
  235. },
  236. /**
  237. * 生命周期函数--监听页面初次渲染完成
  238. */
  239. onReady() {
  240. },
  241. /**
  242. * 生命周期函数--监听页面显示
  243. */
  244. onShow() {
  245. },
  246. /**
  247. * 生命周期函数--监听页面隐藏
  248. */
  249. onHide() {
  250. },
  251. /**
  252. * 生命周期函数--监听页面卸载
  253. */
  254. onUnload() {
  255. },
  256. /**
  257. * 页面相关事件处理函数--监听用户下拉动作
  258. */
  259. onPullDownRefresh() {
  260. },
  261. /**
  262. * 页面上拉触底事件的处理函数
  263. */
  264. onReachBottom() {
  265. },
  266. /**
  267. * 用户点击右上角分享
  268. */
  269. onShareAppMessage() {
  270. }
  271. })