DemuMesDataV/src/components/labelLine/index.vue

96 lines
1.5 KiB
Vue
Raw Normal View History

2018-12-20 18:25:34 +08:00
<template>
<div class="label-line">
<div class="label-item"
2018-12-21 15:47:57 +08:00
v-for="(labelItem, i) in labelData"
2018-12-20 18:25:34 +08:00
:key="labelItem">
2018-12-21 15:47:57 +08:00
<div :class="type" :style="`background-color: ${labelColor[i % labelColorNum]};`"></div>
2018-12-20 18:25:34 +08:00
<div>{{ labelItem }}</div>
</div>
</div>
</template>
<script>
export default {
name: 'LabelLine',
2018-12-21 15:47:57 +08:00
props: ['label', 'colors'],
data () {
return {
labelData: [],
labelColor: [],
labelColorNum: 0,
type: 'rect'
}
},
watch: {
label () {
const { init } = this
init()
},
colors () {
const { init } = this
init()
}
},
methods: {
init () {
const { label, colors } = this
if (!label) return
const { data, color, type } = label
if (!data) return
this.labelData = data
let trueColor = color || colors
typeof trueColor === 'string' && (trueColor = [trueColor])
this.labelColor = trueColor
this.labelColorNum = trueColor.length
this.type = type || 'rect'
}
},
mounted () {
const { init } = this
init()
}
2018-12-20 18:25:34 +08:00
}
</script>
<style lang="less">
.label-line {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
font-size: 10px;
.label-item {
height: 20px;
display: flex;
flex-direction: row;
align-items: center;
margin: 0px 5px 5px 5px;
2018-12-21 15:47:57 +08:00
}
2018-12-20 18:25:34 +08:00
2018-12-21 15:47:57 +08:00
.rect {
width: 10px;
height: 10px;
margin-right: 5px;
}
.rectangle {
width: 30px;
height: 10px;
margin-right: 5px;
2018-12-20 18:25:34 +08:00
}
}
</style>