218 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			Vue
		
	
	
	
			
		
		
	
	
			218 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			Vue
		
	
	
	
<template>
 | 
						|
  <div class="pei-container">
 | 
						|
    <div class="pie-main">
 | 
						|
      <div class="pie-box">
 | 
						|
        <div class="title">
 | 
						|
          <div class="percent">{{ total }}</div>
 | 
						|
          <div class="name">{{ name }}</div>
 | 
						|
        </div>
 | 
						|
        <VueEcharts :options="options" autoresize style="width: 100%;height: 100%;"></VueEcharts>
 | 
						|
      </div>
 | 
						|
    </div>
 | 
						|
    <div class="info-main">
 | 
						|
      <div class="row-con">
 | 
						|
        <div class="row" v-for="(item, index) in data" :key="index">
 | 
						|
          <div class="mark" :style="{ backgroundColor: item.color }"></div>
 | 
						|
          <div class="name">{{ item.name }}</div>
 | 
						|
          <div class="value">
 | 
						|
            <span class="percent">{{ getPercents(item.value) }}</span>
 | 
						|
            <span class="split-line">|</span>
 | 
						|
            <span class="value-info">{{ item.value }}</span>
 | 
						|
          </div>
 | 
						|
        </div>
 | 
						|
      </div>
 | 
						|
    </div>
 | 
						|
  </div>
 | 
						|
</template>
 | 
						|
 | 
						|
<script>
 | 
						|
import echartsMixin from "../mixins/echarts.mixin";
 | 
						|
export default {
 | 
						|
  name: "Pie",
 | 
						|
  mixins: [echartsMixin],
 | 
						|
  props: {
 | 
						|
    name: {
 | 
						|
      type: String,
 | 
						|
      default: ''
 | 
						|
    }
 | 
						|
  },
 | 
						|
  computed: {
 | 
						|
    total () {
 | 
						|
      return this.data.reduce((a, b) => a + b.value || 0, 0) || 0
 | 
						|
    },
 | 
						|
    options () {
 | 
						|
      const data = this.data.map(item => item.value)
 | 
						|
      const colors = this.data.map(item => item.color)
 | 
						|
      return {
 | 
						|
        color: colors,
 | 
						|
        tooltip: false,
 | 
						|
        series: [
 | 
						|
          {
 | 
						|
            type: 'pie',
 | 
						|
            radius: ['93%', '83%'],
 | 
						|
            avoidLabelOverlap: false,
 | 
						|
            label: {
 | 
						|
              show: false,
 | 
						|
              position: 'center',
 | 
						|
            },
 | 
						|
            labelLine: {
 | 
						|
              show: false,
 | 
						|
            },
 | 
						|
            itemStyle: {
 | 
						|
              borderColor: 'transparent',
 | 
						|
              borderWidth: 5,
 | 
						|
            },
 | 
						|
            data: data
 | 
						|
          },
 | 
						|
        ],
 | 
						|
      }
 | 
						|
    }
 | 
						|
  },
 | 
						|
  methods: {
 | 
						|
    getPercents (num = 0) {
 | 
						|
      const total = this.data.reduce((a, b) => a + b.value || 0, 0)
 | 
						|
      if (num === 0) return '0%'
 | 
						|
      if (total === 0) return '100%'
 | 
						|
      return (num * 100 / total).toFixed(2) + '%'
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
</script>
 | 
						|
 | 
						|
<style scoped lang="less">
 | 
						|
@import "assets/styles/mixin";
 | 
						|
.pei-container {
 | 
						|
  width: 100%;
 | 
						|
  height: 100%;
 | 
						|
  .clear-fix;
 | 
						|
  .pie-main {
 | 
						|
    height: 100%;
 | 
						|
    width: 168px;
 | 
						|
    position: relative;
 | 
						|
    float: left;
 | 
						|
    .pie-box {
 | 
						|
      width: 146px;
 | 
						|
      height: 146px;
 | 
						|
      background: url('assets/images/圆环背景.png') center no-repeat;
 | 
						|
      background-size: 146px 146px;
 | 
						|
      position: absolute;
 | 
						|
      left: 50%;
 | 
						|
      top: 50%;
 | 
						|
      transform: translate(-50%, -50%);
 | 
						|
    }
 | 
						|
    .title {
 | 
						|
      position: absolute;
 | 
						|
      left: 50%;
 | 
						|
      top: 50%;
 | 
						|
      transform: translate(-50%, -50%);
 | 
						|
      .percent {
 | 
						|
        font-family: HIKLDH-Number-CondensedMedium;
 | 
						|
        font-size: 32px;
 | 
						|
        color: #F3FAFF;
 | 
						|
        letter-spacing: 0;
 | 
						|
        text-align: center;
 | 
						|
        font-weight: 500;
 | 
						|
      }
 | 
						|
      .name {
 | 
						|
        font-family: MicrosoftYaHeiUI;
 | 
						|
        font-size: 14px;
 | 
						|
        color: rgba(255,255,255,0.50);
 | 
						|
        letter-spacing: 0;
 | 
						|
        text-align: center;
 | 
						|
        font-weight: 400;
 | 
						|
        margin-top: 10px;
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
  .info-main {
 | 
						|
    overflow: hidden;
 | 
						|
    position: relative;
 | 
						|
    height: 100%;
 | 
						|
    .row-con {
 | 
						|
      width: 100%;
 | 
						|
      position: absolute;
 | 
						|
      top: 50%;
 | 
						|
      transform: translateY(-50%);
 | 
						|
      left: 0;
 | 
						|
      padding-left: 40px;
 | 
						|
      height: 100%;
 | 
						|
      overflow-y: auto;
 | 
						|
      padding-right: 10px;
 | 
						|
      /* 整个滚动条 */
 | 
						|
      &::-webkit-scrollbar {
 | 
						|
        /* 对应纵向滚动条的宽度 */
 | 
						|
        width: 10px;
 | 
						|
        /* 对应横向滚动条的宽度 */
 | 
						|
        height: 10px;
 | 
						|
      }
 | 
						|
 | 
						|
      /* 滚动条上的滚动滑块 */
 | 
						|
      &::-webkit-scrollbar-thumb {
 | 
						|
        background-color: #08EBF5;
 | 
						|
        border-radius: 32px;
 | 
						|
      }
 | 
						|
 | 
						|
      /* 滚动条轨道 */
 | 
						|
      &::-webkit-scrollbar-track {
 | 
						|
        background-color: #dbeffd;
 | 
						|
        border-radius: 32px;
 | 
						|
      }
 | 
						|
    }
 | 
						|
 | 
						|
    .row {
 | 
						|
      .clear-fix;
 | 
						|
      line-height: 20px;
 | 
						|
      margin-top: 8px;
 | 
						|
      &:first-child {
 | 
						|
        margin-top: 0;
 | 
						|
      }
 | 
						|
      .mark {
 | 
						|
        width: 6px;
 | 
						|
        height: 6px;
 | 
						|
        border-radius: 50%;
 | 
						|
        float: left;
 | 
						|
        display: inline-block;
 | 
						|
        margin-top: 7px;
 | 
						|
      }
 | 
						|
      .name {
 | 
						|
        float: left;
 | 
						|
        font-family: MicrosoftYaHeiUI;
 | 
						|
        font-size: 14px;
 | 
						|
        color: #F3FAFF;
 | 
						|
        letter-spacing: 0;
 | 
						|
        font-weight: 400;
 | 
						|
        padding-left: 10px;
 | 
						|
 | 
						|
      }
 | 
						|
      .value {
 | 
						|
 | 
						|
        overflow: hidden;
 | 
						|
        ont-family: HIKLDH-Number-CondensedBold;
 | 
						|
        font-size: 16px;
 | 
						|
        color: #08EBF5;
 | 
						|
        letter-spacing: 0;
 | 
						|
        text-align: right;
 | 
						|
        font-weight: 700;
 | 
						|
        display: flex;
 | 
						|
        justify-content: flex-end;
 | 
						|
        align-items: center;
 | 
						|
        .split-line {
 | 
						|
          color: rgba(8,235,245,0.70);
 | 
						|
          margin: 0 10px;
 | 
						|
 | 
						|
        }
 | 
						|
        .value-info {
 | 
						|
          font-family: HIKLDH-Number-CondensedBold;
 | 
						|
          font-size: 16px;
 | 
						|
          color: rgba(8,235,245,0.70);
 | 
						|
          letter-spacing: 0;
 | 
						|
          font-weight: 700;
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
 | 
						|
  }
 | 
						|
}
 | 
						|
</style>
 | 
						|
 |