Newer
Older
CloudBrainNew / src / components / annularProgress / annularComp.vue
StephanieGitHub on 4 Feb 2021 2 KB first commit
<!--
 * @Description: 环形进度条加名字文字,常用于设备在线情况标识
 * @Author: 王晓颖
 * @Date: 2020-12-01 09:36:22
 -->
<template>
  <div class="annular-container">
    <div class="circular-chart">
      <annular-progress
        :width="data.echartData.width"
        :height="data.echartData.height"
        :data="data.echartData.percent"
        :color="data.echartData.color"
      />
    </div>
    <div class="info-box">
      <div>
        <span>名称:{{data.name}}</span>
      </div>
      <div>
        <span>在线设备数:<b :style="'color:'+data.color">{{value.online}}</b></span>
        <!--<span>离线率:{{data.leave}} %</span>-->
      </div>
    </div>
  </div>

</template>

<script>
import AnnularProgress from './annularProgress'
export default {
  name: 'annularComp',
  components: {AnnularProgress},
  props: {
    value: {
      type: Object,
      default: () => {
        return {
          name: '电子标识器', // 设备名称
          total: 100, // 设备总数
          online: 95, // 在线数
          color: ['#fc5e5f', '#f90006']
        }
      }
    }
  },
  data () {
    return {
      data: {
        name: '电子标识器',
        leave: '5',
        online: '10',
        color: '#fc5e5f',
        echartData: {
          width: '100%',
          height: '100%',
          percent: 50,
          color: ['#fc5e5f', '#f90006']
        }
      }
    }
  },
  mounted () {
    this.refreshValue()
  },
  watch: {
    value (val) {
      this.refreshValue()
    }
  },
  methods: {
    refreshValue () {
      console.log('refreshValue')
      const val = this.value
      if (val) {
        const online = Math.round(val.online / val.total * 100) // 求在线率
        this.data.online = online
        this.data.leave = 100 - online
        this.data.color = val.color[0]
        this.data.name = val.name
        this.data.echartData = {
          id: val.id,
          width: 0,
          height: 0,
          percent: online,
          color: val.color
        }
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .annular-container{
    width:100%;
    height:100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .circular-chart{
      width:30%;
      margin-right:5px;
    }
    @import '../../assets/css/variable.scss';
    .info-box{
      flex:1;
      div{
        overflow: hidden;
        height: .12rem;
      }
      span{
        font-size: .04rem;
        color:$blockTextColor;
        -webkit-transform-origin-x: 0;
        transform:  scale(0.5833333333333334);
        -webkit-transform: scale(.5);
        b{
          font-weight: bold;
          font-size: .07rem
        }
      }
    }
  }

</style>