Legend.vue 2.31 KB
<template>
  <div class="legend-box">
    <div class="legend-item flex" v-for="(item, index) in dataList" :key="index">
      <div class="legend-item-text" v-for="(itm, inx) in legentList" :key="inx">
        <template v-if="inx == 0">
          <div class="flex legend-item-right">
            <div class="icon" :style="{ background: colors[index] }"></div>
            <div class="item-content" :style="{ width: itm.width,'max-width': itm.width }">{{ item[itm.name] }}</div>
          </div>
        </template>
        <template v-else>
          <div class="flex item-content" :style="{ width: itm.width,'max-width': itm.width }">
            <!-- <div v-show="itm.hasIcon">{{ itm.hasIcon }}</div>
            <div v-if="itm.type == 'number'">{{numAddSymbol(item[itm.name])}}</div>
            <div v-else-if="itm.type == 'decimal'">{{toPercent(item[itm.name])}}</div>
            <div v-else>{{ item[itm.name] }}</div> -->
            {{ itm.hasIcon ? itm.hasIcon : '' }}{{ itm.type == 'number' ? numAddSymbol(item[itm.name]) : itm.type == 'decimal' ? toPercent(item[itm.name]) : item[itm.name] }}{{ itm.unitIcon ? itm.unitIcon : '' }}
          </div>
        </template>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Legend',
  data() {
    return {
      dataList: this.list
    }
  },
  props: {
    list: {
      type: Array,
      default: () => []
    },
    legentList: {
      type: Array,
      default: () => []
    },
    colors: {
      type: Array,
      default: () => ['#FF6E76', '#7CFFB2', ' #FDF006', '#4FA0FF', '#EB6001', '#BF98FF', '#BF98FF', '#58D9F9']
    }
  },
  watch: {
    list(val) {
      this.dataList = val
    }
  },
  mounted() {},
  methods: {}
}
</script>

<style lang="scss" scoped>
.legend-box {
  margin-left: 0.42vw;
  .legend-item {
    font-size: 12px;
    font-weight: 400;
    line-height: 18px;
    color: #c9c9c9ff;
    justify-content: space-between;
    &-text {
      // margin-right: 1.39vw;
    }
    &-text:last-child {
      margin-right: 0;
    }
    &-right {
      // margin-right: 1.39vw;
    }

    .item-content {
      text-align: left;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .icon {
      width: 5px;
      height: 5px;
      background: #bf98ff;
      border-radius: 50%;
      margin: 4px;
    }
  }
}
</style>