储能智慧云小程序
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. // pages/setup/index.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. const api = require('../../api/index.js');
  4. var fitness=''
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. // 状态栏高度
  11. statusBarHeight: wx.getStorageSync('statusBarHeight'),
  12. // 导航栏高度
  13. navBarHeight: wx.getStorageSync('navBarHeight'),
  14. // 导航栏和状态栏高度
  15. navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
  16. // 胶囊
  17. menu:wx.getStorageSync('menu'),
  18. fitness:{},
  19. ec: {
  20. onInit: initChart
  21. }
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad(options) {
  27. this.getuser()
  28. },
  29. getuser(){
  30. api.request(`/station/fitness/${wx.getStorageSync('station').id}`, 'POST')
  31. .then((res) => {
  32. // console.log(res);
  33. fitness = res.data
  34. this.setData({
  35. fitness:res.data
  36. })
  37. // console.log(this.data.fitness.temperature);
  38. })
  39. .catch((err) => {
  40. console.error('请求失败:', err);
  41. // 在这里处理请求失败的情况
  42. });
  43. },
  44. // 返回上一级
  45. onIconTap(){
  46. wx.navigateBack({
  47. delta: 1
  48. });
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady() {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow() {
  59. },
  60. /**
  61. * 生命周期函数--监听页面隐藏
  62. */
  63. onHide() {
  64. },
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload() {
  69. },
  70. /**
  71. * 页面相关事件处理函数--监听用户下拉动作
  72. */
  73. onPullDownRefresh() {
  74. },
  75. /**
  76. * 页面上拉触底事件的处理函数
  77. */
  78. onReachBottom() {
  79. },
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage() {
  84. }
  85. })
  86. function initChart(canvas, width, height) {
  87. const chart = echarts.init(canvas, null, {
  88. width: width,
  89. height: height
  90. });
  91. canvas.setChart(chart);
  92. let colors = ['#35d964', '#d9bc39', '#da5660'],
  93. color;
  94. let subtext = ''
  95. if (fitness.alarmStatus==0) {
  96. subtext = '状态:' + '{a|离线}'
  97. } else if(fitness.alarmStatus==1) {
  98. subtext = '状态:' + '{b|在线}'
  99. }else{
  100. subtext = '状态:' + '{c|故障}'
  101. }
  102. let data = fitness.temperature; //数值大小
  103. let max = 75; //满刻度大小
  104. let title = {
  105. text: data + ' ' + '℃',
  106. subtext: subtext,
  107. x: 'center',
  108. y: 'center',
  109. textStyle: {
  110. color: '#222',
  111. fontSize: 30,
  112. },
  113. subtextStyle: {
  114. fontSize: 18,
  115. rich: {
  116. a: {
  117. color: '#FFA500', // 设置 '正常' 的文本颜色为橙色
  118. fontSize: 18
  119. },
  120. b: {
  121. color: '#15DB9B', //设置 '离线' 的文本颜色为绿色
  122. fontSize: 18
  123. },
  124. c: {
  125. color: '#FF6347', // 设置 '故障' 的文本颜色为红色
  126. fontSize: 18
  127. }
  128. }
  129. }
  130. };
  131. if (data < 150) {
  132. color = colors[0];
  133. } else if (data > 150 && data < 250) {
  134. color = colors[1];
  135. } else if (data > 250 || data == 250) {
  136. color = colors[2];
  137. }
  138. var option = {
  139. title: title,
  140. series: [
  141. {
  142. name: "",
  143. type: 'gauge',
  144. splitNumber: 40, //刻度数量
  145. min: 0,
  146. max: 100,
  147. radius: '80%', //图表尺寸
  148. center: ['50%', '50%'],
  149. startAngle: 90,
  150. endAngle: -269.9999,
  151. axisLine: {
  152. show: false,
  153. lineStyle: {
  154. width: 0,
  155. shadowBlur: 0,
  156. color: [
  157. [1, '#0dc2fe']
  158. ]
  159. }
  160. },
  161. axisTick: {
  162. show: false,
  163. lineStyle: {
  164. color: 'auto',
  165. width: 2
  166. },
  167. length: 20,
  168. splitNumber: 5
  169. },
  170. splitLine: {
  171. show: true,
  172. length: 10,
  173. lineStyle: {
  174. color: 'auto',
  175. }
  176. },
  177. axisLabel: {
  178. show: false
  179. },
  180. pointer: { //仪表盘指针
  181. show: 0,
  182. },
  183. detail: {
  184. show: 0,
  185. },
  186. },
  187. {
  188. type: "pie",
  189. center: ["50%", "50%"],
  190. radius: ["75%", "80%"],
  191. hoverAnimation: false,
  192. data: [
  193. {
  194. name: "",
  195. value: data * 0.8,
  196. itemStyle: {
  197. borderColor: color,
  198. borderRadius: 10,
  199. borderWidth: 5,
  200. color: color,
  201. },
  202. labelLine: {
  203. show: false,
  204. lineStyle: {
  205. color: 'rgba(0,0,0,0)',
  206. width: 2
  207. }
  208. }
  209. },
  210. { //画中间的图标
  211. name: "",
  212. value: 0,
  213. label: {
  214. position: 'inside',
  215. backgroundColor: color,
  216. borderRadius: 100,
  217. borderWidth: 10,
  218. borderColor: '#ffffff',
  219. padding: 20,
  220. },
  221. },
  222. {
  223. name: "",
  224. value: data * 0.2,
  225. itemStyle: {
  226. borderColor: color,
  227. borderWidth: 5,
  228. color: color,
  229. },
  230. labelLine: {
  231. show: false,
  232. lineStyle: {
  233. color: 'rgba(0,0,0,0)',
  234. width: 2
  235. }
  236. }
  237. },
  238. { //画剩余的刻度圆环
  239. name: "",
  240. value: max - data,
  241. label: {
  242. show: false
  243. },
  244. itemStyle: {
  245. borderType: 'dashed',
  246. borderRadius: 10,
  247. borderColor: '#919192',
  248. borderWidth: 0,
  249. color: 'rgba(0,0,0,0)',
  250. },
  251. labelLine: {
  252. show: true,
  253. lineStyle: {
  254. color: 'rgba(0,0,0,0)',
  255. width: 2
  256. }
  257. },
  258. }
  259. ]
  260. },
  261. ]
  262. };
  263. chart.setOption(option, true);
  264. return chart;
  265. }