UnsafePositionChart.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="unsafe-position-chart">
  3. <div class="chart-container" ref="positionChart"></div>
  4. <div class="position-info">
  5. <div class="info-text">X光机操作员: {{ chartsData.total }}</div>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. import * as echarts from 'echarts'
  11. export default {
  12. name: 'UnsafePositionChart',
  13. props: {
  14. chartsData: {
  15. type: Object,
  16. default: () => ({
  17. total: 279,
  18. positions: {
  19. labels: ['X光机', '开包台', '引导岗', '验证岗', '维序岗'],
  20. data: [279, 0, 0, 0, 0]
  21. }
  22. })
  23. }
  24. },
  25. data() {
  26. return {
  27. chart: null
  28. }
  29. },
  30. mounted() {
  31. this.$nextTick(() => {
  32. this.initChart()
  33. })
  34. },
  35. watch: {
  36. chartsData: {
  37. deep: true,
  38. handler() {
  39. this.$nextTick(() => {
  40. if (this.chart) this.chart.dispose()
  41. this.initChart()
  42. })
  43. }
  44. }
  45. },
  46. methods: {
  47. initChart() {
  48. if (!this.$refs.positionChart) return
  49. this.chart = echarts.init(this.$refs.positionChart)
  50. const option = {
  51. responsive: true,
  52. maintainAspectRatio: false,
  53. grid: {
  54. left: '15%',
  55. right: '5%',
  56. bottom: '15%',
  57. top: '10%'
  58. },
  59. xAxis: {
  60. type: 'category',
  61. data: this.chartsData.positions.labels,
  62. axisLine: {
  63. lineStyle: {
  64. color: 'rgba(255, 255, 255, 0.1)'
  65. }
  66. },
  67. axisLabel: {
  68. color: 'rgba(255, 255, 255, 0.5)',
  69. fontSize: 10,
  70. // rotate: 30
  71. }
  72. },
  73. yAxis: {
  74. type: 'value',
  75. axisLine: {
  76. show: false
  77. },
  78. axisTick: {
  79. show: false
  80. },
  81. splitLine: {
  82. lineStyle: {
  83. color: 'rgba(255, 255, 255, 0.05)'
  84. }
  85. },
  86. axisLabel: {
  87. color: 'rgba(255, 255, 255, 0.5)',
  88. fontSize: 10
  89. }
  90. },
  91. series: [{
  92. type: 'bar',
  93. data: this.chartsData.positions.data,
  94. itemStyle: {
  95. color: {
  96. type: 'linear',
  97. x: 0,
  98. y: 0,
  99. x2: 0,
  100. y2: 1,
  101. colorStops: [{
  102. offset: 0, color: '#F472B6'
  103. }, {
  104. offset: 1, color: '#DB2777'
  105. }]
  106. }
  107. },
  108. barWidth: '60%'
  109. }]
  110. }
  111. this.chart.setOption(option)
  112. }
  113. },
  114. beforeDestroy() {
  115. if (this.chart) this.chart.dispose()
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .unsafe-position-chart {
  121. .chart-container {
  122. height: 240rpx;
  123. }
  124. .position-info {
  125. margin-top: 16rpx;
  126. text-align: center;
  127. .info-text {
  128. font-size: 24rpx;
  129. color: rgba(255, 255, 255, 0.5);
  130. }
  131. }
  132. }
  133. </style>