储能智慧云小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 15KB

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