incomeCircle.vue
2.65 KB
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
<template>
<div class="progress-box">
<!-- 绘制圆环背景 -->
<canvas ref="canvasProgressbg" class="progress-bg" id="canvasProgressbg" width="240" height="240" />
<!-- 绘制加载中圆弧 -->
<canvas ref ="canvasProgress" class="progress-canvas" id="canvasProgress" width="240" height="240" />
</div>
</template>
<script>
import {mapState} from 'vuex';
export default {
name: 'income-circle',
props: {
data: {
type: Object,
default: {}
},
},
data() {
return {
};
},
computed: {
...mapState({
clientWidth: (state) => {
return state.yoho.window.clientWidth;
},
})
},
mounted() {
this.startDraw(this.data);
},
watch: {
data: function(val) {
this.startDraw(val)
}
},
methods: {
startDraw(val) {
let summary = {}
for(let key in val) {
let item = val[key];
if(item.includes('¥')) {
let value = val[key].split('¥')[1];
summary[key] = value
}
}
this.drawProgressbg(summary);
this.startProgress(summary);
},
// 画progress底部背景
drawProgressbg: function (summary) {
let c=document.getElementById("canvasProgressbg");
let ctx=c.getContext("2d");
ctx.lineWidth= 30 ;
let strokeStyle = '#E0E0E0'
if (summary && summary.totalIncome > 0) {
strokeStyle = '#65AB85';
}
ctx.strokeStyle=strokeStyle;
ctx.lineCap='round'
ctx.beginPath();
//设置一个原点(110,110),半径为100的圆的路径到当前路径
ctx.arc(120, 120, 100, 0, 2 * Math.PI, false);
ctx.stroke();
},
// 画progress进度
drawCircle: function (step) {
let c=document.getElementById("canvasProgress");
let context=c.getContext("2d");
context.lineWidth=30;
let strokeColor = '#002B47'
context.strokeStyle=strokeColor;
context.lineCap='round';
context.beginPath();
//参数step 为绘制的圆环周长,从0到2为一周 。 -Math.PI / 2 将起始角设在12点钟位置 ,结束角 通过改变 step 的值确定
context.arc(120, 120, 100, -Math.PI / 2, step * Math.PI - Math.PI / 2, false);
context.stroke();
},
// 开始progress
startProgress: function (summary) {
if (summary && summary.totalIncome > 0) {
this.drawCircle(summary.goodsIncome / (summary.totalIncome / 2))
}
},
}
};
</script>
<style lang="scss" scoped>
.progress-box {
position: absolute;
top: 36px;
right: 50px;
width: 204px;
height: 204px;
}
.progress-bg {
position: absolute;
width: 204px;
height: 204px;
}
.progress-canvas {
position: absolute;
width: 204px;
height: 204px;
}
</style>