zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template>
  <div v-if='dataSource.length'>
    <div :style="{ padding: '0 0 32px 32px' }">
      <h4 :style="{ marginTop: '20px' }" style='text-align: center'>{{ title }}</h4>
      <v-chart :forceFit='true'  :height='height' :data='dataSource'  :scale='scale' :padding='padding'  :onClick="handleClick" >
        <v-tooltip />
        <v-interval
          position='type*value'
          opacity='1'
          :label='barLabel'
          :size='26'
        >
        </v-interval>
        <v-axis
          dataKey='type'
          :label='label'
          :tickLine='tickLine'
          :line='line'
        >
        </v-axis>
        <v-coord type='rect' direction='LB'></v-coord>
        <v-axis
          dataKey='value'
          :label='null'
          :title='titleConfig'
        >
        </v-axis>
      </v-chart>
    </div>
  </div>
</template>
 
<script>
import { ChartEventMixins } from './mixins/ChartMixins'
import { triggerWindowResizeEvent } from '@/utils/util'
import { WEEKLY_LEFT_TOGGLE } from '@/vuebus/event-bus'
 
 
function sortData(sortType) {
  if (sortType === 'positive') {
    data.sort(function(a, b) {
      return b.value - a.value
    })
  } else {
    data.sort(function(a, b) {
      return a.value - b.value
    })
  }
}
 
export default {
  name: 'BarHorizontal',
  mixins: [ChartEventMixins],
  props: {
    dataSource: {
      type: Array,
      default: () => [],
      required: true
    },
    max: {
      type: Number,
      default: 10
    },
    title: {
      type: String,
      default: ''
    },
    height: {
      type: Number,
      default: 400
    }
  },
  watch: {
     height: {
    immediate: true,
    handler() {
      triggerWindowResizeEvent()
      console.info(this.height)
    },
  },
   /* dataSource: {
      immediate: true,
      handler() {
        this.height = this.dataSource.length * 40
        console.info(this.dataSource.length)
      },
    },*/
  },
  mounted() {
    this.$bus.$on(WEEKLY_LEFT_TOGGLE, () => {
      triggerWindowResizeEvent()
    })
  },
  methods: {
 
  },
  data() {
    return {
      sortType: 'negative',
      padding: [20, 60, 50, 100],
      scale:[{
        dataKey: 'value',
 
        min: 0,
        nice: false,
        alias: '工时(h)'
      }],
      label:{
        textStyle: {
          fill: '#8d8d8d',
          fontSize: 12
        }
      },
      barLabel:['value', {
        textStyle: {
          fill: '#8d8d8d'
        },
        offset: 10
      }],
      tickLine:{
        alignWithLabel: false,
        length: 0
      },
      titleConfig:{
        offset: 30,
        textStyle: {
          fontSize: 12,
          fontWeight: 300
        }
      },
      line:{
        lineWidth: 0
      }
    }
  },
  beforeDestroy() {
    this.$bus.$off(WEEKLY_LEFT_TOGGLE)
  }
}
</script>