储能智慧云小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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.com/wx_images/bj.png')
  74. this.setData({
  75. img_path:'https://esos-iot.com/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. console.log(initialData);
  215. this.updateChartData(initialData)
  216. // 重新初始化图表
  217. // 在这里处理返回的数据
  218. this.timer1 = setTimeout(() => {
  219. // 这里是延时执行的代码
  220. this.getsuperStations()
  221. }, 10000);
  222. }else{
  223. }
  224. })
  225. .catch((err) => {
  226. console.error('请求失败:', err);
  227. // 在这里处理请求失败的情况
  228. });
  229. },
  230. // 卸载图表,清理资源
  231. unloadCharts: function () {
  232. if (this.charts) {
  233. this.charts.dispose(); // 销毁图表实例
  234. this.charts = null; // 置空图表实例
  235. }
  236. },
  237. // 电容量
  238. initChartright: function () {
  239. let _this = this;
  240. // 初始化图表
  241. this.ecline.init((canvas, width, height, dpr) => {
  242. const chart = echarts.init(canvas, null, {
  243. width: width,
  244. height: height,
  245. devicePixelRatio: dpr
  246. });
  247. // 初始数据
  248. let initialData = {
  249. accumulatedchargetime: _this.data.characteristic.chargeEnergyDaily,
  250. accumulateddischargetime: _this.data.characteristic.disChargeEnergyDaily
  251. };
  252. console.log(_this.data.ectricdata);
  253. // this.updateChartData(initialData)
  254. // 设置初始选项
  255. let option = _this.getChartOption(initialData);
  256. chart.setOption(option);
  257. _this.chartInstance2 = chart;
  258. return chart;
  259. });
  260. },
  261. // 定义更新数据函数
  262. updateChartData(newData) {
  263. let updatedOption = this.getChartOption(newData);
  264. this.chartInstance2.setOption(updatedOption);
  265. },
  266. // 辅助函数,用于生成图表选项
  267. getChartOption: function (data) {
  268. let _this = this;
  269. return {
  270. backgroundColor: "#ffffff",
  271. legend: [{
  272. left: '0',
  273. bottom: 20,
  274. itemHeight: 8,
  275. itemWidth: 8,
  276. icon: "circle",
  277. textStyle: {
  278. color: '#999999', // 设置文字颜色为灰色
  279. fontSize: 10 // 设置字号为20px
  280. },
  281. formatter: function (name) {
  282. return name + ` ${(data.accumulatedchargetime*1).toFixed(2)} kWh`;
  283. },
  284. rich:{
  285. a: {
  286. color: '#222222',
  287. fontSize: 12 // 设置字号为20px
  288. }
  289. },
  290. data: [{ name: '今日充电' }]
  291. }, {
  292. left: '0',
  293. bottom: 0,
  294. itemHeight: 8,
  295. itemWidth: 8,
  296. icon: "circle",
  297. textStyle: {
  298. color: '#999999', // 设置文字颜色为灰色
  299. fontSize: 10 // 设置字号为20px
  300. },
  301. formatter: function (name) {
  302. return name + ` ${(data.accumulateddischargetime*1).toFixed(2)} kWh`;
  303. },
  304. data: [{ name: '今日放电' }]
  305. }],
  306. tooltip: {
  307. trigger: 'item'
  308. },
  309. series: [{
  310. type: 'pie',
  311. radius: ['40%', '60%'],
  312. center: ['50%', '40%'],
  313. avoidLabelOverlap: false,
  314. label: {
  315. show: false,
  316. position: 'center'
  317. },
  318. emphasis: {
  319. label: {
  320. show: true,
  321. fontSize: 0,
  322. fontWeight: 'bold'
  323. }
  324. },
  325. labelLine: {
  326. show: false
  327. },
  328. data: [{
  329. value: (data.accumulatedchargetime*1).toFixed(2),
  330. name: '今日充电',
  331. itemStyle: { color: '#4DF096' }
  332. }, {
  333. value: (data.accumulateddischargetime*1).toFixed(2),
  334. name: '今日放电',
  335. itemStyle: { color: '#3C9EFA' }
  336. }]
  337. }]
  338. };
  339. },
  340. // 设备详情
  341. onIconTap(){
  342. let _this =this
  343. wx.navigateTo({
  344. url: `/pages/details/index`,
  345. })
  346. },
  347. // 设备健康
  348. onhealthy(){
  349. wx.navigateTo({
  350. url: '/pages/healthy/index',
  351. })
  352. },
  353. // 设备信息
  354. ondetails(){
  355. wx.navigateTo({
  356. url: '/pages/monitor/index',
  357. })
  358. },
  359. // 水波图
  360. initCharts(value) {
  361. let _this = this;
  362. this.ecComponent.init((canvas, width, height, dpr) => {
  363. const charts = echarts.init(canvas, null, {
  364. width: width,
  365. height: height,
  366. devicePixelRatio: dpr
  367. });
  368. // 将初始的数值转换为数据
  369. let data = [value, value, value];
  370. // 初始化图表选项
  371. let option = _this.getChartOption1(value, data);
  372. charts.setOption(option);
  373. // 存储图表实例
  374. _this.chartInstance3 = charts;
  375. // 启动定时器更新数据
  376. _this.getsuperStations();
  377. // 返回图表实例
  378. return charts;
  379. });
  380. },
  381. // 更新图表数据函数
  382. updateChartData1(value, data) {
  383. let updatedOption = this.getChartOption1(value, data);
  384. this.chartInstance3.setOption(updatedOption);
  385. },
  386. // 启动定时器更新数据
  387. // startDataUpdate() {
  388. // let _this =this
  389. // _this.timer3 = setInterval(() => {
  390. // // 获取新数据
  391. // api.request(`/station/ectric/${wx.getStorageSync('station').id}`, 'POST')
  392. // .then((res) => {
  393. // // 更新数据
  394. // let data = [res.data.quantity / 100, res.data.quantity / 100, res.data.quantity / 100];
  395. // _this.updateChartData1(res.data.quantity / 100, data);
  396. // // console.log('请求成功:', res);
  397. // })
  398. // .catch((err) => {
  399. // console.error('请求失败:', err);
  400. // // 处理请求失败情况
  401. // });
  402. // }, 10000);
  403. // },
  404. // Vue.js 生命周期钩子
  405. beforeDestroy() {
  406. // 清除定时器
  407. // 销毁图表实例
  408. if (this.chartInstance3) {
  409. this.chartInstance3.dispose(); // 销毁图表
  410. this.chartInstance3 = null;
  411. }
  412. },
  413. beforeDestroys() {
  414. // 清除定时器
  415. // 销毁图表实例
  416. if (this.chartInstance2) {
  417. this.chartInstance2.dispose(); // 销毁图表
  418. this.chartInstance2 = null;
  419. }
  420. },
  421. // 辅助函数,用于生成图表选项
  422. getChartOption1: function (value, data) {
  423. let color = (value * 100).toFixed(2) < 70 ? '#004403' : '#fff';
  424. return {
  425. title: {
  426. text: (value * 100).toFixed(2) + '%',
  427. textStyle: {
  428. fontFamily: 'Microsoft Yahei',
  429. fontWeight: 'normal',
  430. color: color,
  431. rich: {
  432. a: {
  433. fontSize: 18,
  434. }
  435. }
  436. },
  437. x: 'center',
  438. y: '40%'
  439. },
  440. series: [
  441. {
  442. type: 'liquidFill',
  443. radius: '80%',
  444. center: ['50%', '50%'],
  445. // shape: 'roundRect',
  446. data: data,
  447. color: {
  448. type: 'linear',
  449. x: 0,
  450. y: 0,
  451. x2: 0,
  452. y2: 1,
  453. colorStops: [{
  454. offset: 0,
  455. color: 'rgba(0, 117, 68,0)'
  456. },{
  457. offset: 0.5,
  458. color: 'rgba(0, 117, 68, .5)'
  459. }, {
  460. offset: 1,
  461. color: 'rgba(0, 117, 68,1)'
  462. }],
  463. globalCoord: false
  464. },
  465. // 边框
  466. outline: {
  467. borderDistance: 2,
  468. itemStyle: {
  469. borderWidth: 5,
  470. borderColor: {
  471. type: 'linear',
  472. x: 0,
  473. y: 0,
  474. x2: 0,
  475. y2: 1,
  476. colorStops: [{
  477. offset: 0,
  478. color: 'rgba(0, 117, 68, .25)'
  479. },{
  480. offset: 0.5,
  481. color: 'rgba(0, 117, 68, .25)'
  482. }, {
  483. offset: 1,
  484. color: 'rgba(0, 117, 68, .25)'
  485. }],
  486. globalCoord: false
  487. },
  488. shadowBlur: 0,
  489. shadowColor: '#ffffff',
  490. }
  491. },
  492. backgroundStyle: {
  493. borderWidth: 0,
  494. color: {
  495. type: 'linear',
  496. x: 0,
  497. y: 0,
  498. x2: 0,
  499. y2: 1,
  500. colorStops: [{
  501. offset: 1,
  502. color: 'rgba(255, 255, 255, 1)'
  503. }, {
  504. offset: 0.5,
  505. color: 'rgba(255, 255, 255, .25)'
  506. }, {
  507. offset: 0,
  508. color: 'rgba(255, 255, 255, 1)'
  509. }],
  510. globalCoord: false
  511. },
  512. },
  513. label: {
  514. normal: {
  515. formatter: '',
  516. }
  517. }
  518. }]
  519. };
  520. },
  521. onPullDownRefresh(){
  522. let _this =this
  523. _this.getlist()
  524. wx.stopPullDownRefresh();
  525. },
  526. /**
  527. * 生命周期函数--监听页面卸载
  528. */
  529. onShow(){
  530. let _this =this
  531. // 电站列表stationindex
  532. let data ={
  533. page:1,
  534. rows:1000
  535. }
  536. api.request('/api/va/superStationsA', 'get',data)
  537. .then((res) => {
  538. console.log(res);
  539. _this.setData({
  540. objectArray:res.data.list
  541. })
  542. if (wx.getStorageSync('station').id) {
  543. for (let index = 0; index < _this.data.objectArray.length; index++) {
  544. if (_this.data.objectArray[index].id==wx.getStorageSync('station').id) {
  545. _this.setData({
  546. stationindex:index
  547. })
  548. }
  549. }
  550. _this.getlist()
  551. }else{
  552. wx.setStorage({
  553. key: 'station', // 本地缓存中指定的 key
  554. data: res.data.list[0],
  555. success: function () {
  556. _this.getlist()
  557. }
  558. });
  559. }
  560. })
  561. .catch((err) => {
  562. console.error('请求失败:', err);
  563. // 在这里处理请求失败的情况
  564. });
  565. },
  566. onHide() {
  567. clearInterval(this.timer1);
  568. this.beforeDestroy()
  569. this.beforeDestroys()
  570. },
  571. });
  572. //