container.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div :class="$style.container">
  3. <template v-for="(row, rowIndex) in rowData">
  4. <dv-decoration-10 v-if="rowIndex === 1" :key="`lineOne${rowIndex}`" />
  5. <div :key="`row${rowIndex}`" :class="$style.row" :style="`width: ${row.length / 4 * 100}%;`">
  6. <template v-for="(item, index) in row">
  7. <div :key="`${rowIndex * 4 + index}`" :class="$style.column" :style="`width: ${1 / row.length * 100}%;`">
  8. <div :id="`card${rowIndex * 4 + index}`" />
  9. </div>
  10. <dv-decoration-2
  11. v-if="index !== row.length - 1"
  12. :key="`line${rowIndex * 4 + index}`"
  13. :reverse="true"
  14. :dur="4 + index * 2"
  15. />
  16. </template>
  17. </div>
  18. <dv-decoration-10 v-if="rowIndex === 1" :key="`lineTwo${rowIndex}`" />
  19. </template>
  20. </div>
  21. </template>
  22. <script>
  23. import echarts from 'echarts'
  24. import { chartOption } from './option'
  25. export default {
  26. name: 'chart',
  27. components: {},
  28. props: {
  29. info: {
  30. type: Array,
  31. default: () => []
  32. },
  33. fontSize: {
  34. type: Number,
  35. default: 18
  36. },
  37. chooseYear: {
  38. type: String,
  39. default: ''
  40. }
  41. },
  42. data () {
  43. return {}
  44. },
  45. computed: {
  46. rowData () {
  47. const data = []
  48. for (let i = 0; i < this.info.length; i += 4) {
  49. data.push(this.info.slice(i, i + 4))
  50. }
  51. return data
  52. }
  53. },
  54. watch: {
  55. info: {
  56. handler () {
  57. this.init()
  58. },
  59. deep: true
  60. }
  61. },
  62. created () {},
  63. mounted () {
  64. this.init()
  65. },
  66. methods: {
  67. init () {
  68. const D = new Date()
  69. // 控制数据显示,历史数据显示整年,本年度数据显示到当前月
  70. const y = parseInt(D.toJSON().slice(0, 4))
  71. const m = parseInt(this.chooseYear) < y ? 12 : parseInt(D.toJSON().split('-')[1])
  72. const w = window.innerWidth
  73. this.fontSize = w >= 1600 ? 20 : w > 1366 && w < 1600 ? 18 : 16
  74. setTimeout(() => {
  75. this.info.forEach((item, index) => {
  76. const chart = echarts.init(document.getElementById(`card${index}`))
  77. const option = JSON.parse(JSON.stringify(chartOption))
  78. const xData = item.data.map((i, index) => index + 1).slice(0, m)
  79. const yData = item.data.map(i => i.result || 0).slice(0, m)
  80. const yMax = Math.max(...yData)
  81. const yMin = Math.min(...yData)
  82. const limit = item.data.map(i => i.limit).filter(i => i !== undefined)[0]
  83. const limitValue = item.data.map(i => i.limitValue).filter(i => i)[0]
  84. // if (parseFloat(limit) > parseFloat(yMax)) {
  85. // // console.log('>', parseFloat(limit), parseFloat(yMax), item.title)
  86. // option.yAxis.max = limit
  87. // }
  88. // if (parseFloat(limit) < parseFloat(yMin)) {
  89. // // console.log('<', parseFloat(limit), parseFloat(yMax), item.title)
  90. // option.yAxis.min = limit
  91. // }
  92. // console.log(option.yAxis.max, option.yAxis.min, item.title)
  93. // console.log(item.title, yData)
  94. option.title.text = item.title
  95. option.title.textStyle.fontSize = this.fontSize
  96. option.title.subtext = `限值${limitValue}`
  97. option.xAxis.data = xData
  98. option.series[0].data = yData
  99. option.series[0].markLine.data[0].yAxis = limit
  100. option.series[0].markLine.data[0].label.formatter = limit
  101. chart.setOption(option)
  102. })
  103. }, 100)
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" module>
  109. .container {
  110. width: 96%;
  111. height: calc(100% - 40px);
  112. padding: 20px 2%;
  113. .row {
  114. position: relative;
  115. display: flex;
  116. justify-content: space-between;
  117. width: 100%;
  118. height: calc((100% - 70px) / 3);
  119. // margin: 15px 0 15px;
  120. .column {
  121. width: 24%;
  122. height: 100%;
  123. background-color: rgba(6, 30, 93, 0.5);
  124. > div {
  125. width: 100%;
  126. height: 100%;
  127. }
  128. }
  129. }
  130. :global {
  131. .dv-decoration-10 {
  132. width: 96%;
  133. height: 5px;
  134. margin: 15px 2%;
  135. }
  136. .dv-decoration-2 {
  137. width:5px;
  138. height:100%;
  139. }
  140. }
  141. }
  142. </style>