储能智慧云小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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 app = getApp()
  5. const api = require('../../api/index.js');
  6. Page({
  7. data: {
  8. // 状态栏高度
  9. statusBarHeight: wx.getStorageSync('statusBarHeight'),
  10. // 导航栏高度
  11. navBarHeight: wx.getStorageSync('navBarHeight'),
  12. // 导航栏和状态栏高度
  13. navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
  14. // 胶囊
  15. menu:wx.getStorageSync('menu'),
  16. mode: '',
  17. ec_dispace_charts: {
  18. lazyLoad: true
  19. },
  20. ec:{
  21. lazyLoad: true
  22. },
  23. img_path:'',
  24. ectricdata:[],
  25. between:{},
  26. currentDate:'',
  27. fitnessdata:[],
  28. rotation:0,
  29. objectArray: [],
  30. stationindex:0,
  31. stationName:wx.getStorageSync('station').name,
  32. timer1:'',
  33. timer2:'',
  34. timer3:'',
  35. chartInstance1:'',
  36. chartInstance2:'',
  37. chartInstance3:'',
  38. characteristic:{},
  39. comStateunm:0 // 设备在线数
  40. },
  41. onLoad: function () {
  42. let _this =this
  43. const updateManager = wx.getUpdateManager();
  44. // 获取手机系统信息
  45. updateManager.onCheckForUpdate(function (res) {
  46. if (res.hasUpdate) {
  47. // 提示用户更新
  48. wx.showModal({
  49. title: '更新提示',
  50. content: '发现新版本,是否下载新版本并重启应用?',
  51. success: function (res) {
  52. if (res.confirm) {
  53. // 用户确认下载新版本
  54. downloadAndUpdate();
  55. } else if (res.cancel) {
  56. // 用户取消,可以选择后续操作
  57. }
  58. }
  59. });
  60. }
  61. });
  62. // const now = new Date();
  63. // const year = now.getFullYear();
  64. // const month = now.getMonth() + 1;
  65. // const date = now.getDate();
  66. // const dateString = `${year}-${month}-${date}`;
  67. // 获取组件
  68. this.ecComponent = this.selectComponent('#dispace_charts');
  69. this.ecline = this.selectComponent('#mychart_line');
  70. // this.initChart()
  71. // let base64imgages =util.Background_base64('https://esos-iot.bjdexn.cn/wx_images/bj.png')
  72. this.setData({
  73. img_path:'https://esos-iot.bjdexn.cn/wx_images/bj.png'
  74. })
  75. // this.rotateImage()
  76. },
  77. downloadAndUpdate() {
  78. wx.downloadFile({
  79. url: 'https://example.com/path/to/new/version.zip', // 新版本小程序包的下载链接
  80. success: function (res) {
  81. if (res.statusCode === 200) {
  82. // 下载成功,保存临时文件路径
  83. const tempFilePath = res.tempFilePath;
  84. // 应用新版本
  85. applyUpdate(tempFilePath);
  86. } else {
  87. // 下载失败,处理异常
  88. }
  89. }
  90. });
  91. },
  92. applyUpdate(tempFilePath) {
  93. let _this = this
  94. wx.applyUpdate({
  95. filePath: tempFilePath,
  96. success: function () {
  97. // 新版本应用成功
  98. _this.getlist()
  99. // wx.navigateTo({
  100. // url: '/pages/login/index',
  101. // })
  102. }
  103. });
  104. },
  105. // 图片旋转
  106. rotateImage() {
  107. const currentRotation = this.data.rotation + 180; // 每次增加180度
  108. const animation = wx.createAnimation({
  109. duration: 300, // 动画时长
  110. timingFunction: 'ease', // 动画效果
  111. });
  112. animation.rotate(currentRotation).step();
  113. this.setData({
  114. animationData: animation.export(),
  115. rotation: currentRotation
  116. });
  117. },
  118. // 电站列表
  119. bindPickerChange (e) {
  120. console.log('选中项改变,携带值为', e.detail.value);
  121. let _this = this
  122. const station = this.data.objectArray[e.detail.value];
  123. wx.setStorage({
  124. key: 'station', // 本地缓存中指定的 key
  125. data: station,
  126. success: function () {
  127. _this.setData({
  128. stationName:wx.getStorageSync('station').name
  129. })
  130. clearInterval(_this.timer1);
  131. clearInterval(_this.timer2);
  132. clearInterval(_this.timer3);
  133. _this.getlist()
  134. }
  135. });
  136. },
  137. getlist(){
  138. // 电站信息
  139. let data={
  140. page:1,
  141. rows:1000
  142. }
  143. api.request(`/api/v1/stations/HDES/superStations/${wx.getStorageSync('station').id}`, 'get',data)
  144. .then((res) => {
  145. if (res.code==200) {
  146. let unm = 0
  147. for (let index = 0; index < res.data.list.length; index++) {
  148. if (res.data.list[index].comState=='在线') {
  149. unm++
  150. }
  151. }
  152. this.setData({
  153. stationName:wx.getStorageSync('station').name,
  154. ectricdata:res.data.list,
  155. comStateunm:unm,
  156. characteristic:res.data.characteristic,
  157. currentDate: util.CumulativeTimess(0) // 假设在小程序页面中使用了data属性绑定了currentDate
  158. })
  159. // console.log('请求成功:', res);
  160. // 先卸载旧图表
  161. this.beforeDestroy();
  162. this.beforeDestroys();
  163. this.initChartright()
  164. // 重新初始化图表
  165. this.initCharts(res.data.characteristic.soc/100);
  166. // 在这里处理返回的数据
  167. // 这里是延时执行的代码
  168. // this.getsuperStations()
  169. }else{
  170. }
  171. })
  172. .catch((err) => {
  173. console.error('请求失败:', err);
  174. // 在这里处理请求失败的情况
  175. });
  176. },
  177. getsuperStations(){
  178. let _this =this
  179. // 电站信息
  180. let data={
  181. page:1,
  182. rows:1000
  183. }
  184. api.request(`/api/v1/stations/HDES/superStations/${wx.getStorageSync('station').id}`, 'get',data)
  185. .then((res) => {
  186. if (res.code==200) {
  187. let unm = 0
  188. for (let index = 0; index < res.data.list.length; index++) {
  189. if (res.data.list[index].comState=='在线') {
  190. unm++
  191. }
  192. }
  193. this.setData({
  194. stationName:wx.getStorageSync('station').name,
  195. ectricdata:res.data.list,
  196. comStateunm:unm,
  197. characteristic:res.data.characteristic,
  198. currentDate: util.CumulativeTimess(0)
  199. })
  200. // console.log('请求成功:', res);
  201. // 先卸载旧图表
  202. let data = [res.data.characteristic.soc / 100, res.data.characteristic.soc / 100, res.data.characteristic.soc / 100];
  203. _this.updateChartData1(res.data.characteristic.soc / 100, data);
  204. let initialData = {
  205. accumulatedchargetime: _this.data.characteristic.chargeEnergyDaily,
  206. accumulateddischargetime: _this.data.characteristic.disChargeEnergyDaily
  207. };
  208. this.updateChartData(initialData)
  209. // 重新初始化图表
  210. // 在这里处理返回的数据
  211. this.timer1 = setTimeout(() => {
  212. // 这里是延时执行的代码
  213. this.getsuperStations()
  214. }, 10000);
  215. }else{
  216. }
  217. })
  218. .catch((err) => {
  219. console.error('请求失败:', err);
  220. // 在这里处理请求失败的情况
  221. });
  222. },
  223. // 卸载图表,清理资源
  224. unloadCharts: function () {
  225. if (this.charts) {
  226. this.charts.dispose(); // 销毁图表实例
  227. this.charts = null; // 置空图表实例
  228. }
  229. },
  230. // 电容量
  231. initChartright: function () {
  232. let _this = this;
  233. // 初始化图表
  234. this.ecline.init((canvas, width, height, dpr) => {
  235. const chart = echarts.init(canvas, null, {
  236. width: width,
  237. height: height,
  238. devicePixelRatio: dpr
  239. });
  240. // 初始数据
  241. let initialData = {
  242. accumulatedchargetime: _this.data.characteristic.chargeEnergyDaily,
  243. accumulateddischargetime: _this.data.characteristic.disChargeEnergyDaily
  244. };
  245. console.log(_this.data.ectricdata);
  246. // this.updateChartData(initialData)
  247. // 设置初始选项
  248. let option = _this.getChartOption(initialData);
  249. chart.setOption(option);
  250. _this.chartInstance2 = chart;
  251. return chart;
  252. });
  253. },
  254. // 定义更新数据函数
  255. updateChartData(newData) {
  256. let updatedOption = this.getChartOption(newData);
  257. this.chartInstance2.setOption(updatedOption);
  258. },
  259. // 辅助函数,用于生成图表选项
  260. getChartOption: function (data) {
  261. let _this = this;
  262. return {
  263. backgroundColor: "#ffffff",
  264. legend: [{
  265. left: '0',
  266. bottom: 20,
  267. itemHeight: 8,
  268. itemWidth: 8,
  269. icon: "circle",
  270. textStyle: {
  271. color: '#999999', // 设置文字颜色为灰色
  272. fontSize: 10 // 设置字号为20px
  273. },
  274. formatter: function (name) {
  275. return name + ` ${data.accumulatedchargetime} kwh`;
  276. },
  277. rich:{
  278. a: {
  279. color: '#222222',
  280. fontSize: 12 // 设置字号为20px
  281. }
  282. },
  283. data: [{ name: '今日充电' }]
  284. }, {
  285. left: '0',
  286. bottom: 0,
  287. itemHeight: 8,
  288. itemWidth: 8,
  289. icon: "circle",
  290. textStyle: {
  291. color: '#999999', // 设置文字颜色为灰色
  292. fontSize: 10 // 设置字号为20px
  293. },
  294. formatter: function (name) {
  295. return name + ` ${data.accumulateddischargetime} kwh`;
  296. },
  297. data: [{ name: '今日放电' }]
  298. }],
  299. tooltip: {
  300. trigger: 'item'
  301. },
  302. series: [{
  303. type: 'pie',
  304. radius: ['40%', '60%'],
  305. center: ['50%', '40%'],
  306. avoidLabelOverlap: false,
  307. label: {
  308. show: false,
  309. position: 'center'
  310. },
  311. emphasis: {
  312. label: {
  313. show: true,
  314. fontSize: 0,
  315. fontWeight: 'bold'
  316. }
  317. },
  318. labelLine: {
  319. show: false
  320. },
  321. data: [{
  322. value: data.accumulatedchargetime,
  323. name: '今日充电',
  324. itemStyle: { color: '#4DF096' }
  325. }, {
  326. value: data.accumulateddischargetime,
  327. name: '今日放电',
  328. itemStyle: { color: '#3C9EFA' }
  329. }]
  330. }]
  331. };
  332. },
  333. // 设备详情
  334. onIconTap(){
  335. let _this =this
  336. wx.navigateTo({
  337. url: `/pages/details/index?uuid=${_this.data.ectricdata[0].uuid}`,
  338. })
  339. },
  340. // 设备健康
  341. onhealthy(){
  342. wx.navigateTo({
  343. url: '/pages/healthy/index',
  344. })
  345. },
  346. // 设备信息
  347. ondetails(){
  348. wx.navigateTo({
  349. url: '/pages/monitor/index',
  350. })
  351. },
  352. // 水波图
  353. initCharts(value) {
  354. let _this = this;
  355. this.ecComponent.init((canvas, width, height, dpr) => {
  356. const charts = echarts.init(canvas, null, {
  357. width: width,
  358. height: height,
  359. devicePixelRatio: dpr
  360. });
  361. // 将初始的数值转换为数据
  362. let data = [value, value, value];
  363. // 初始化图表选项
  364. let option = _this.getChartOption1(value, data);
  365. charts.setOption(option);
  366. // 存储图表实例
  367. _this.chartInstance3 = charts;
  368. // 启动定时器更新数据
  369. _this.getsuperStations();
  370. // 返回图表实例
  371. return charts;
  372. });
  373. },
  374. // 更新图表数据函数
  375. updateChartData1(value, data) {
  376. let updatedOption = this.getChartOption1(value, data);
  377. this.chartInstance3.setOption(updatedOption);
  378. },
  379. // 启动定时器更新数据
  380. // startDataUpdate() {
  381. // let _this =this
  382. // _this.timer3 = setInterval(() => {
  383. // // 获取新数据
  384. // api.request(`/station/ectric/${wx.getStorageSync('station').id}`, 'POST')
  385. // .then((res) => {
  386. // // 更新数据
  387. // let data = [res.data.quantity / 100, res.data.quantity / 100, res.data.quantity / 100];
  388. // _this.updateChartData1(res.data.quantity / 100, data);
  389. // // console.log('请求成功:', res);
  390. // })
  391. // .catch((err) => {
  392. // console.error('请求失败:', err);
  393. // // 处理请求失败情况
  394. // });
  395. // }, 10000);
  396. // },
  397. // Vue.js 生命周期钩子
  398. beforeDestroy() {
  399. // 清除定时器
  400. // 销毁图表实例
  401. if (this.chartInstance3) {
  402. this.chartInstance3.dispose(); // 销毁图表
  403. this.chartInstance3 = null;
  404. }
  405. },
  406. beforeDestroys() {
  407. // 清除定时器
  408. // 销毁图表实例
  409. if (this.chartInstance2) {
  410. this.chartInstance2.dispose(); // 销毁图表
  411. this.chartInstance2 = null;
  412. }
  413. },
  414. // 辅助函数,用于生成图表选项
  415. getChartOption1: function (value, data) {
  416. let color = (value * 100).toFixed(2) < 70 ? '#004403' : '#fff';
  417. return {
  418. title: {
  419. text: (value * 100).toFixed(2) + '%',
  420. textStyle: {
  421. fontFamily: 'Microsoft Yahei',
  422. fontWeight: 'normal',
  423. color: color,
  424. rich: {
  425. a: {
  426. fontSize: 18,
  427. }
  428. }
  429. },
  430. x: 'center',
  431. y: '40%'
  432. },
  433. series: [
  434. {
  435. type: 'liquidFill',
  436. radius: '80%',
  437. center: ['50%', '50%'],
  438. // shape: 'roundRect',
  439. data: data,
  440. color: {
  441. type: 'linear',
  442. x: 0,
  443. y: 0,
  444. x2: 0,
  445. y2: 1,
  446. colorStops: [{
  447. offset: 0,
  448. color: 'rgba(0, 117, 68,0)'
  449. },{
  450. offset: 0.5,
  451. color: 'rgba(0, 117, 68, .5)'
  452. }, {
  453. offset: 1,
  454. color: 'rgba(0, 117, 68,1)'
  455. }],
  456. globalCoord: false
  457. },
  458. // 边框
  459. outline: {
  460. borderDistance: 2,
  461. itemStyle: {
  462. borderWidth: 5,
  463. borderColor: {
  464. type: 'linear',
  465. x: 0,
  466. y: 0,
  467. x2: 0,
  468. y2: 1,
  469. colorStops: [{
  470. offset: 0,
  471. color: 'rgba(0, 117, 68, .25)'
  472. },{
  473. offset: 0.5,
  474. color: 'rgba(0, 117, 68, .25)'
  475. }, {
  476. offset: 1,
  477. color: 'rgba(0, 117, 68, .25)'
  478. }],
  479. globalCoord: false
  480. },
  481. shadowBlur: 0,
  482. shadowColor: '#ffffff',
  483. }
  484. },
  485. backgroundStyle: {
  486. borderWidth: 0,
  487. color: {
  488. type: 'linear',
  489. x: 0,
  490. y: 0,
  491. x2: 0,
  492. y2: 1,
  493. colorStops: [{
  494. offset: 1,
  495. color: 'rgba(255, 255, 255, 1)'
  496. }, {
  497. offset: 0.5,
  498. color: 'rgba(255, 255, 255, .25)'
  499. }, {
  500. offset: 0,
  501. color: 'rgba(255, 255, 255, 1)'
  502. }],
  503. globalCoord: false
  504. },
  505. },
  506. label: {
  507. normal: {
  508. formatter: '',
  509. }
  510. }
  511. }]
  512. };
  513. },
  514. onPullDownRefresh(){
  515. let _this =this
  516. _this.getlist()
  517. wx.stopPullDownRefresh();
  518. },
  519. /**
  520. * 生命周期函数--监听页面卸载
  521. */
  522. onShow(){
  523. let _this =this
  524. // 电站列表stationindex
  525. let data ={
  526. page:1,
  527. rows:1000
  528. }
  529. api.request('/api/v1/superStations', 'get',data)
  530. .then((res) => {
  531. console.log(res);
  532. _this.setData({
  533. objectArray:res.data.list
  534. })
  535. if (wx.getStorageSync('station').id) {
  536. for (let index = 0; index < _this.data.objectArray.length; index++) {
  537. if (_this.data.objectArray[index].id==wx.getStorageSync('station').id) {
  538. _this.setData({
  539. stationindex:index
  540. })
  541. }
  542. }
  543. _this.getlist()
  544. }else{
  545. wx.setStorage({
  546. key: 'station', // 本地缓存中指定的 key
  547. data: res.data.list[0],
  548. success: function () {
  549. _this.getlist()
  550. }
  551. });
  552. }
  553. })
  554. .catch((err) => {
  555. console.error('请求失败:', err);
  556. // 在这里处理请求失败的情况
  557. });
  558. },
  559. onHide() {
  560. clearInterval(this.timer1);
  561. this.beforeDestroy()
  562. this.beforeDestroys()
  563. },
  564. });