p-i-fan.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view>
  3. <!-- top -->
  4. <view class="top">
  5. <image src="./icon/fan.png" mode=""></image>
  6. <view class="time">
  7. 2019-10-22 星期二 11:01:32
  8. </view>
  9. </view>
  10. <!-- 风机运行状况 -->
  11. <p-i-f-section-1 :blower="blower">
  12. <canvas style="width: 632upx; height:500upx;" canvas-id="canvasLineA" id="canvasLineA" class="charts" @touchstart="touchLineA"></canvas>
  13. </p-i-f-section-1>
  14. <!-- 风机参数 -->
  15. <p-i-f-section-2 :param1="param1" :param2="param2"></p-i-f-section-2>
  16. </view>
  17. </template>
  18. <script>
  19. import uCharts from '@/components/u-charts/u-charts.js';
  20. var _self;
  21. var canvaLineA=null;
  22. export default {
  23. data() {
  24. return {
  25. cWidth:'',
  26. cHeight:'',
  27. pixelRatio:1,
  28. // 风机运行状态
  29. blower:{},
  30. // 风机参数
  31. param1:[],
  32. param2:[]
  33. }
  34. },
  35. onLoad() {
  36. // 获取风机运行状态
  37. this.getBlower()
  38. // 获取风机参数
  39. this.getParam1()
  40. this.getParam2()
  41. _self = this;
  42. this.cWidth=uni.upx2px(632);
  43. this.cHeight=uni.upx2px(500);
  44. // this.getServerData();
  45. this.getChartHour()
  46. },
  47. methods: {
  48. // 获取风机运行状态
  49. async getBlower(){
  50. const res = await this.$myRequest({
  51. url: '/blower/status/now',
  52. })
  53. // console.log(res.data.data)
  54. this.blower = res.data.data
  55. console.log(this.blower)
  56. },
  57. // 获取风机运行参数
  58. async getParam1(){
  59. const res = await this.$myRequest({
  60. method:"POST",
  61. url: '/blower/param/now',
  62. header: {
  63. 'Content-Type': 'application/json',
  64. },
  65. data:{
  66. num:1,
  67. }
  68. })
  69. console.log(res.data.data)
  70. this.param1 = res.data.data
  71. },
  72. async getParam2(){
  73. const res = await this.$myRequest({
  74. method:"POST",
  75. url: '/blower/param/now',
  76. header: {
  77. 'Content-Type': 'application/json',
  78. },
  79. data:{
  80. num:2,
  81. }
  82. })
  83. console.log(res.data.data)
  84. this.param2 = res.data.data
  85. },
  86. // 获取风量趋势
  87. async getChartHour(){
  88. const res = await this.$myRequest({
  89. url: '/blower/chart/hour',
  90. })
  91. let LineA = {
  92. categories: [],
  93. data:[]
  94. }
  95. // 时间存入新数组
  96. const categories = res.data.data
  97. categories.map(function(item,index){
  98. //新数组的项,用来盛放每一项中的各个参数,每次清空,这样避免改变sevm的值
  99. var sevm = {};
  100. //给每一项中的参数初始化并赋值
  101. sevm = item.time;
  102. //将项放进新的数组
  103. LineA.categories[index] = sevm
  104. })
  105. // console.log(LineA)
  106. // 存入新的series
  107. const data = res.data.data
  108. data.map(function(item,index){
  109. //新数组的项,用来盛放每一项中的各个参数,每次清空,这样避免改变sevm的值
  110. var sevm = {};
  111. //给每一项中的参数初始化并赋值
  112. sevm = item.tem;
  113. //将项放进新的数组
  114. LineA.data[index] = sevm
  115. })
  116. console.log(LineA)
  117. _self.showLineA("canvasLineA",LineA);
  118. },
  119. // getServerData(){
  120. // getChartHour(){
  121. // let LineA = {
  122. // categories: ['20:04', '20:15', '20:26', '20:38', '20:49'],
  123. // series: [{
  124. // name: '',
  125. // data: [12184.25,12196.61,12196.61,12233.72,12147.13],
  126. // color: '#1790FF'
  127. // }]
  128. // }
  129. // // console.log(LineA)
  130. // _self.showLineA("canvasLineA",LineA);
  131. // },
  132. showLineA(canvasId,chartData){
  133. canvaLineA=new uCharts({
  134. $this:_self,
  135. canvasId: canvasId,
  136. type: 'line',
  137. fontSize:8,
  138. legend:{show:false},
  139. dataLabel:false,
  140. dataPointShape:true,
  141. background:'#FFFFFF',
  142. pixelRatio:_self.pixelRatio,
  143. categories: chartData.categories,
  144. series: [{
  145. name: '',
  146. data: chartData.data,
  147. color: '#1790FF'
  148. }],
  149. animation: true,
  150. xAxis: {
  151. type:'grid',
  152. gridColor:'#CCCCCC',
  153. gridType:'dash',
  154. dashLength:8,
  155. },
  156. yAxis: {
  157. gridType:'dash',
  158. gridColor:'#CCCCCC',
  159. dashLength:8,
  160. splitNumber:5,
  161. min:10,
  162. max:180,
  163. format:(val)=>{return val.toFixed(0)}
  164. },
  165. width: _self.cWidth*_self.pixelRatio,
  166. height: _self.cHeight*_self.pixelRatio,
  167. extra: {
  168. line:{
  169. type: 'straight'
  170. }
  171. }
  172. });
  173. },
  174. touchLineA(e) {
  175. canvaLineA.showToolTip(e, {
  176. format: function (item, category) {
  177. return category + ' ' + item.name + ':' + item.data
  178. }
  179. });
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. page{
  186. background-color: #f3f3f3;
  187. }
  188. .top{
  189. position: relative;
  190. width: 750rpx;
  191. height: 458rpx;
  192. image{
  193. width: 750rpx;
  194. height: 458rpx;
  195. }
  196. .time{
  197. position: absolute;
  198. right: 40rpx;
  199. bottom: 50rpx;
  200. }
  201. }
  202. </style>