duhuizhe
2023-10-16 3aa55dd3f62cee2c1c4c0aa74e1570acf83f8927
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<template>
  <div v-loading="loading" style="width: 100%; height: 192px; position: relative">
    <div style="width: 100%; height: 100%" ref="batchPlan"></div>
    <div class="title-box">
      <p class="num">100%</p>
      <p>批次计划</p>
    </div>
    <div class="tag-box">
      <div class="item-box" v-for="(item, index) in dataList" :key="index">
        <div class="example" :style="{ background: item.color }"></div>
        <div class="name">{{ item.name }}</div>
        <div class="value">{{ item.value }}%</div>
      </div>
    </div>
  </div>
</template>
 
<script>
import dataVRequest from '@/api/dataV.js';
import echarts from 'echarts';
 
export default {
  name: 'batch-plan',
  data() {
    return {
      loading: true,
      dataList: [],
      colorList: ['#70B1F6', '#077CF2', '#1DD5A5', '#E6C364', '#E56A3D'],
    };
  },
  mounted() {
    // 监听屏幕宽度变化:当浏览器发生resize事件的时候,触发echart的resize事件,重绘canvas
 
    // 基于准备好的dom,初始化echarts实例
    const batchPlan = echarts.init(this.$refs.batchPlan);
    window.addEventListener('resize', () => {
      this.$nextTick(() => {
        batchPlan.resize();
      });
    });
    // 查询数据
    dataVRequest.queryProjectNumByBatch().then((res) => {
      this.loading = false;
      this.dataList = res.map((item, index) => ({
        ...item,
        value: item.num,
        name: item.projectBatchName,
        color: this.colorList[index],
      }));
      // 绘制图表
      batchPlan.setOption({
        color: this.colorList,
        tooltip: {
          trigger: 'item',
        },
        grid: {
          right: 200,
          top: 30,
        },
        series: [
          {
            type: 'pie',
            radius: ['60%', '90%'],
            center: ['160', '95'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center',
            },
            labelLine: {
              show: false,
            },
            data: this.dataList,
          },
        ],
      });
    });
  },
};
</script>
 
<style lang="scss" scoped>
.title-box {
  color: #fff;
  font-size: 16px;
  position: absolute;
  left: 127px;
  top: 75px;
  text-align: center;
 
  .num {
    font-size: 20px;
    font-weight: bold;
  }
}
.tag-box {
  position: absolute;
  right: 60px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
 
  .item-box {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
  }
 
  .example {
    width: 10px;
    height: 10px;
    margin-right: 10px;
  }
 
  .name {
    margin-right: 25px;
    color: rgba(255, 255, 255, 0.74);
  }
 
  .value {
    color: #cd963f;
  }
}
</style>