Bonus-AI-LargeScreen/src/views/updateIDCard/pieIDResultCount.vue

149 lines
4.3 KiB
Vue
Raw Normal View History

2024-07-26 18:26:40 +08:00
<template>
<div class="pieBoxIDResultCount">
<div class="pieIDResultCount" ref="pieIDResultCount"></div>
<div class="pieTextBoxIDResultCount">
<div class='pieTextIDResultCount'>
识别正确数
</div>
<div class='pieTextIDResultCount'>
识别错误数
</div>
</div>
</div>
</template>
<script>
import { init, graphic } from 'echarts'
2024-07-29 17:49:56 +08:00
import { getPieData } from "@/api/updateIDCard/updateIDCard.js";
function roundToTwo(num) {
let tmp_num = num.toFixed(2).toString();
return tmp_num;
}
2024-07-26 18:26:40 +08:00
export default {
name: 'pieIDResultCount',
data() {
return {
pieOneChart: null,
pieEntityNameValue: {
2024-07-29 17:49:56 +08:00
pieright: '',
pieerror: ''
2024-07-26 18:26:40 +08:00
}
}
},
mounted() {
2024-07-29 17:49:56 +08:00
this.getPieDataID();
},
created() {
this.interval_IDPie = setInterval(() => {
this.pieIDResultCount();
}, 60 * 60 * 1000); // 5分钟 = 5 * 60 * 1000 毫秒
2024-07-26 18:26:40 +08:00
},
methods: {
2024-07-29 17:49:56 +08:00
getPieDataID() {
getPieData(1).then(res => {
try {
if (res.code == 200) {
this.pieEntityNameValue.pieright = (res.data.correctNu / res.data.totalNu * 100);
this.pieEntityNameValue.pieerror = (res.data.incorrectNu / res.data.totalNu * 100);
this.pieIDResultCount()
}
} catch (error) {
console.error('Error:', error);
}
}).catch(error => {
console.error('Error:', error);
});
},
2024-07-26 18:26:40 +08:00
pieIDResultCount() {
let pieBlank = {
color: 'rgba(255,255,255,.8)',
};
let pieEntity = {
color: new graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: 'rgba(0, 255, 225, 0.3)' },
{ offset: .5, color: 'rgba(100, 255, 100, 1)' },
{ offset: 1, color: 'rgba(0, 255, 255, 0.7)' },
]),
};
let pieRadius = [30, 60];
let pieIDResultCount = init(this.$refs.pieIDResultCount);
2024-07-29 17:49:56 +08:00
console.log(this.pieEntityNameValue)
console.log(this.pieEntityNameValue.pieright)
let pieData = [
{ name: 'pieright', value: this.pieEntityNameValue.pieright },
{ name: 'pieerror', value: this.pieEntityNameValue.pieerror }
];
// console.log(pieData)
2024-07-26 18:26:40 +08:00
pieIDResultCount.setOption({
series: pieData.map((data, index) => ({
type: 'pie',
top: '15%',
2024-07-29 17:49:56 +08:00
center: [`${23 + 51 * index}%`, '50%'],
2024-07-26 18:26:40 +08:00
radius: pieRadius,
label: {
show: true,
formatter: function (params) {
if (params.name === 'blank')
2024-07-29 17:49:56 +08:00
return roundToTwo(100 - params.value) + "%"
2024-07-26 18:26:40 +08:00
else
2024-07-29 17:49:56 +08:00
return roundToTwo(params.value) + "%"//没有这个参数会出现数据漂移的现象如0.1+0.2=0.3
2024-07-26 18:26:40 +08:00
},
position: 'center',
fontSize: 15,
fontWeight: 'bold',
color: 'rgba(0, 255, 255, 0.7)'
},
data: [
2024-07-29 17:49:56 +08:00
{ name: 'entity', value: data.value, itemStyle: pieEntity },
2024-07-26 18:26:40 +08:00
{ name: 'blank', value: 100 - data.value, itemStyle: pieBlank }
]
}))
});
},
}
}
</script>
<style scoped>
.pieBoxIDResultCount {
height: 20rem;
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.pieIDResultCount {
flex: 10;
width: 100%;
}
.pieTextBoxIDResultCount {
flex: 2;
display: flex;
color: #fff;
width: 100%;
font-size: 1rem;
2024-07-29 17:49:56 +08:00
margin-left: 30%;
2024-07-26 18:26:40 +08:00
}
.pieTextIDResultCount {
flex: 1
}
</style>