|
|
@@ -4,7 +4,7 @@
|
|
|
<div class="tech-pie-chart">
|
|
|
<div class="chart-ring"></div>
|
|
|
<svg class="pie-svg" viewBox="0 0 500 500">
|
|
|
- <circle class="pie-segment" v-for="(item, index) in chartData" :key="index"
|
|
|
+ <circle class="pie-segment" v-for="(item, index) in pieData" :key="index"
|
|
|
ref="segments"
|
|
|
cx="250" cy="250" r="210"
|
|
|
/>
|
|
|
@@ -13,11 +13,15 @@
|
|
|
<div class="center-total">{{ centerTitle || total }}</div>
|
|
|
<div class="center-label">{{ centerSubTitle || '设备总数' }}</div>
|
|
|
</div>
|
|
|
+ <div class="chart-center" v-else-if="activeFaults.length === 0">
|
|
|
+ <div class="center-total">0</div>
|
|
|
+ <div class="center-label">故障</div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
|
|
|
<!-- 右侧数据面板 -->
|
|
|
<div class="status-panel">
|
|
|
- <div class="status-item" v-for="(item, index) in chartData" :key="index">
|
|
|
+ <div class="status-item" v-for="(item, index) in panelData" :key="index">
|
|
|
<div class="status-dot" :style="{ background: item.color }"></div>
|
|
|
<div class="status-text">{{ item.name }}</div>
|
|
|
<div class="status-num" :style="{ color: item.color }">{{ item.value }}</div>
|
|
|
@@ -57,6 +61,28 @@ export default {
|
|
|
computed: {
|
|
|
total() {
|
|
|
return this.chartData.reduce((sum, item) => sum + Number(item.value), 0);
|
|
|
+ },
|
|
|
+ // 过滤出故障项(名称不含"正常"且值大于0)
|
|
|
+ activeFaults() {
|
|
|
+ return this.chartData.filter(item => item.name.indexOf('正常') === -1 && Number(item.value) > 0);
|
|
|
+ },
|
|
|
+ // 故障总数
|
|
|
+ totalFaults() {
|
|
|
+ return this.activeFaults.reduce((sum, item) => sum + Number(item.value), 0);
|
|
|
+ },
|
|
|
+ // 饼图实际渲染的数据
|
|
|
+ pieData() {
|
|
|
+ if (this.activeFaults.length > 0) {
|
|
|
+ return this.activeFaults;
|
|
|
+ }
|
|
|
+ // 无故障时,用正常项的颜色画整圆
|
|
|
+ const normalItem = this.chartData.find(item => item.name.indexOf('正常') !== -1);
|
|
|
+ return [{ name: '正常', value: 1, color: normalItem ? normalItem.color : '#A0E551' }];
|
|
|
+ },
|
|
|
+ // 右侧面板:有故障显示故障项,无故障只显示正常项
|
|
|
+ panelData() {
|
|
|
+ if (this.activeFaults.length > 0) return this.activeFaults;
|
|
|
+ return this.chartData.filter(item => item.name.indexOf('正常') !== -1);
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
@@ -76,10 +102,11 @@ export default {
|
|
|
const segments = this.$refs.segments;
|
|
|
if (!segments || !segments.length) return;
|
|
|
|
|
|
- const total = this.total || 1;
|
|
|
+ const data = this.pieData;
|
|
|
+ const total = data.reduce((sum, item) => sum + Number(item.value), 0) || 1;
|
|
|
let currentOffset = 0;
|
|
|
|
|
|
- this.chartData.forEach((item, index) => {
|
|
|
+ data.forEach((item, index) => {
|
|
|
const segment = segments[index];
|
|
|
if (!segment) return;
|
|
|
const percent = item.value / total;
|
|
|
@@ -180,9 +207,7 @@ export default {
|
|
|
.center-total {
|
|
|
font-size: clamp(16px, 3vh, 36px);
|
|
|
font-weight: 700;
|
|
|
- background: linear-gradient(90deg, #00ff88, #ff2255);
|
|
|
- -webkit-background-clip: text;
|
|
|
- -webkit-text-fill-color: transparent;
|
|
|
+ color: #00ff88;
|
|
|
}
|
|
|
.center-label {
|
|
|
font-size: clamp(10px, 1.2vh, 14px);
|