hisAndLine.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="his-and-line">
  3. <div id="two" class="two"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { mapState } from 'vuex'
  8. export default {
  9. props: ['time', 'scope'],
  10. data() {
  11. return {
  12. dates: [],
  13. temps: [],
  14. eartags: [],
  15. chart: null,
  16. deviceCode: ''
  17. }
  18. },
  19. computed: {
  20. ...mapState(['baseUrl'])
  21. },
  22. methods: {
  23. draw () {
  24. this.chart.showLoading()
  25. const option = {
  26. tooltip: {
  27. trigger: 'axis'
  28. },
  29. legend: {
  30. data: ['环境温度', '耳标上传数据量']
  31. },
  32. xAxis: {
  33. data: this.dates
  34. },
  35. yAxis: [
  36. {
  37. type: 'value',
  38. name: '℃',
  39. axisLabel: {
  40. textStyle: {
  41. color: '#000'
  42. }
  43. },
  44. splitLine: {
  45. show:false
  46. },
  47. // axisLine: {
  48. // lineStyle: {
  49. // color: '#00ffff'
  50. // }
  51. // },
  52. axisTick: { // 刻度线
  53. show: false,
  54. }
  55. },
  56. {
  57. type: 'value',
  58. name: '次',
  59. axisLabel: {
  60. textStyle: {
  61. color: '#000'
  62. }
  63. },
  64. // axisLine: {
  65. // lineStyle: {
  66. // color: '#00ffff'
  67. // }
  68. // },
  69. axisTick: { // 刻度线
  70. show: false
  71. }
  72. }
  73. ],
  74. series: [
  75. {
  76. name: '环境温度',
  77. type: 'line',
  78. yAxisIndex: 1,
  79. itemStyle: {
  80. normal: {
  81. lineStyle: {
  82. color: '#02a7f0'
  83. },
  84. color: '#02a7f0'
  85. }
  86. },
  87. data: this.temps
  88. },
  89. {
  90. name: '耳标上传数据量',
  91. type: 'bar',
  92. barWidth: 20,
  93. itemStyle: {
  94. normal: {
  95. color: '#5fa7f0'
  96. }
  97. },
  98. data: this.eartags
  99. }
  100. ]
  101. }
  102. this.chart.setOption(option)
  103. setTimeout(() => {
  104. this.chart.hideLoading();//隐藏等待条
  105. }, 1000);
  106. },
  107. init () {
  108. this.chart = this.$echarts.init(document.getElementById('two'))
  109. this.deviceCode = this.$route.params.deviceCode
  110. this.$http({
  111. url: this.$http.adornUrl(`${this.baseUrl}/manager/eartagdata/${this.scope === 1? 'countByDay': 'countByTime' }`),
  112. method: 'get',
  113. params: this.$http.adornParams({
  114. 'deviceCode': this.deviceCode,
  115. 'startTime': this.time[0] || undefined,
  116. 'endTime': this.time[1] || undefined
  117. }, false)
  118. }).then(async({data}) => {
  119. if (data.code === 0) {
  120. this.dates = data.data.time
  121. this.temps = data.data.envTemp
  122. this.eartags = data.data.count
  123. this.draw()
  124. }
  125. }).catch(() => {
  126. })
  127. }
  128. },
  129. mounted () {
  130. this.init()
  131. },
  132. watch: {
  133. time: {
  134. handler(newVal) {
  135. if(newVal) {
  136. this.init()
  137. }
  138. }
  139. },
  140. scope: {
  141. handler (newValue) {
  142. if (newValue) {
  143. this.init()
  144. }
  145. }
  146. }
  147. }
  148. }
  149. </script>
  150. <style scoped>
  151. .his-and-line {
  152. margin: auto;
  153. height: 340px;
  154. padding: 20px 20px;
  155. }
  156. .two {
  157. height: 300px;
  158. width: 100%;
  159. margin: auto;
  160. }
  161. </style>