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
| <template> <div class="z_progress" :style="{height:height,borderRadius:radius}"> <div v-for="(item,index) in mdata" :key="index" class="z_progress_inner" :style="{width:item.rate+'%',backgroundColor:item.color,borderRadius:radius}"></div> </div> </template>
<script> export default { name: 'ZProgress', props: { height: { type: String, default () { return '8px' } }, radius: { type: String, default () { return '4px' } }, max: { type: Number, default () { return 100 } }, colors: { type: Array, default () { return ['#1989fa', 'rgb(242, 130, 106)', 'rgb(114, 50, 221)'] } }, values: { type: Array, default () { return [30, 60] } } }, mounted () { }, computed: { mdata () { const temp = [] for (let i = 0; i < this.values.length; i++) { let color = '' if (i < this.colors.length) { color = this.colors[i] } else { color = this.colors[this.colors.length - 1] } const value = this.values[i] const max = this.max const rate = parseFloat('' + (1.0 * value * 100 / max)) temp.push({ value: value, color: color, rate: rate }) } temp.sort((n1, n2) => { return n2.value - n1.value }) return temp } }, methods: {} } </script>
<style scoped> .z_progress { background-color: #f3f3f3; width: 100%; position: relative; }
.z_progress_inner { height: 100%; position: absolute; top: 0; left: 0; } </style>
|