sliderData.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import React, { useEffect, useRef } from 'react';
  2. import * as datav from '@jiaminghi/data-view-react';
  3. import styles from './sliderData.less';
  4. import * as echarts from 'echarts';
  5. import { connect } from '@@/plugin-dva/exports';
  6. interface propsData {
  7. data: any;
  8. MQTTMessage: any;
  9. }
  10. /**
  11. * 底部轮播
  12. * @constructor
  13. */
  14. const SliderData: React.FC<propsData> = (props) => {
  15. const { MQTTMessage, data } = props;
  16. const chartRef: any = useRef();
  17. useEffect(() => {
  18. if (MQTTMessage.message?.DeviceCode === data.electric_id) {
  19. console.log();
  20. }
  21. const myChart = echarts.init(chartRef.current);
  22. const options = {
  23. tooltip: {
  24. trigger: 'axis',
  25. axisPointer: {
  26. lineStyle: {
  27. color: '#57617B',
  28. },
  29. },
  30. },
  31. grid: {
  32. top: '10%',
  33. left: '0',
  34. right: '5%',
  35. bottom: '3%',
  36. containLabel: true,
  37. },
  38. xAxis: [
  39. {
  40. type: 'category',
  41. boundaryGap: false,
  42. axisLine: {
  43. show: false,
  44. },
  45. data: ['13:00', '13:05', '13:10', '13:15', '13:20', '13:25', '13:30', '13:35'],
  46. },
  47. ],
  48. yAxis: [
  49. {
  50. type: 'value',
  51. name: '单位(%)',
  52. axisTick: {
  53. show: false,
  54. },
  55. axisLine: {
  56. show: false,
  57. },
  58. axisLabel: {
  59. margin: 10,
  60. textStyle: {
  61. fontSize: 14,
  62. },
  63. },
  64. splitLine: { show: false },
  65. },
  66. ],
  67. series: [
  68. {
  69. name: '移动',
  70. type: 'line',
  71. smooth: true,
  72. symbol: 'circle',
  73. symbolSize: 5,
  74. showSymbol: false,
  75. lineStyle: {
  76. normal: {
  77. width: 3,
  78. },
  79. },
  80. areaStyle: {
  81. normal: {
  82. color: new echarts.graphic.LinearGradient(
  83. 0,
  84. 0,
  85. 1,
  86. 0,
  87. [
  88. {
  89. offset: 0,
  90. color: 'rgba(16,97,204, 0.3)',
  91. },
  92. {
  93. offset: 0.8,
  94. color: 'rgba(17,235,210, 0)',
  95. },
  96. ],
  97. false,
  98. ),
  99. shadowColor: 'rgba(0, 0, 0, 0.1)',
  100. shadowBlur: 10,
  101. },
  102. },
  103. itemStyle: {
  104. normal: {
  105. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  106. {
  107. offset: 0,
  108. color: 'rgba(16,97,204,1)',
  109. },
  110. {
  111. offset: 1,
  112. color: 'rgba(17,235,210,1)',
  113. },
  114. ]),
  115. },
  116. emphasis: {
  117. color: 'rgb(0,196,132)',
  118. borderColor: 'rgba(0,196,132,0.2)',
  119. extraCssText: 'box-shadow: 8px 8px 8px rgba(0, 0, 0, 1);',
  120. borderWidth: 10,
  121. },
  122. },
  123. data: [220, 182, 191, 134, 150, 120, 110, 125],
  124. },
  125. ],
  126. };
  127. myChart.setOption(options, true);
  128. // 组件卸载
  129. return () => {
  130. myChart.dispose();
  131. };
  132. }, []);
  133. return (
  134. <div>
  135. <datav.BorderBox12
  136. className={styles.decoration_bottom_border}
  137. style={{ width: '40vw', height: '26vh' }}
  138. >
  139. <div className={styles.home_detail}>
  140. <div className={styles.detail_left}>
  141. <div className={styles.detail_left_left}>
  142. {/*<img src={home} alt="家图标" className={styles.home_icon}/>*/}
  143. <div className={styles.decoration_on} />
  144. <div className={styles.home_name}>{data?.home_name ? data?.home_name : '我的家'}</div>
  145. </div>
  146. <div className={styles.detail_left_right}>
  147. <table className={styles.detail_item}>
  148. <tr>
  149. <td className={styles.detail_item_title}>管理员</td>
  150. <td className={styles.detail_item_value}>{data?.admin}</td>
  151. </tr>
  152. <tr>
  153. <td className={styles.detail_item_title}>是否在线</td>
  154. <td className={styles.detail_item_value}>{data?.is_online ? '在线' : '离线'}</td>
  155. </tr>
  156. <tr>
  157. <td className={styles.detail_item_title}>运行状态</td>
  158. <td className={styles.detail_item_value}>{{ 0: '关', 1: '开' }[data?.power]}</td>
  159. </tr>
  160. <tr>
  161. <td className={styles.detail_item_title}>模式</td>
  162. <td className={styles.detail_item_value}></td>
  163. </tr>
  164. </table>
  165. </div>
  166. </div>
  167. <div className={styles.detail_right}>
  168. <div className={styles.detail_right_top}>
  169. <div className={styles.detail_right_top_content}>
  170. <div className={styles.content_title}>电压</div>
  171. <div className={styles.content_value}></div>
  172. </div>
  173. <div className={styles.detail_right_top_content}>
  174. <div className={styles.content_title}>设定温度</div>
  175. <div className={styles.content_value}>{data?.set_temp}</div>
  176. </div>
  177. <div className={styles.detail_right_top_content}>
  178. <div className={styles.content_title}>室内温度</div>
  179. <div className={styles.content_value}>{data?.temperature}</div>
  180. </div>
  181. <div className={styles.detail_right_top_content}>
  182. <div className={styles.content_title}>湿度</div>
  183. <div className={styles.content_value}>{data?.humidity}</div>
  184. </div>
  185. <div className={styles.detail_right_top_content}>
  186. <div className={styles.content_title}>PM25</div>
  187. <div className={styles.content_value}>{data?.air_quality}</div>
  188. </div>
  189. <div className={styles.detail_right_top_content}>
  190. <div className={styles.content_title}>CO2</div>
  191. <div className={styles.content_value}>{data?.co2}</div>
  192. </div>
  193. </div>
  194. <div style={{ color: '#fff', marginTop: '10px' }}>用电量</div>
  195. <div ref={chartRef} style={{ width: '23w', height: '13vh' }} />
  196. </div>
  197. </div>
  198. </datav.BorderBox12>
  199. </div>
  200. );
  201. };
  202. export default connect(({ MQTTMessage }: any) => ({
  203. MQTTMessage,
  204. }))(SliderData);