From a003d759dfb2de6155cbcbb2997a5611f2f8ec41 Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Thu, 5 Nov 2026 17:26:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8C=89=E7=BA=A2=E9=BB=84=E7=BB=BF?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/datav/chart-bar-fixbug.vue | 2 +- src/views/datav/Lmgz.vue | 25 +++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/datav/chart-bar-fixbug.vue b/src/components/datav/chart-bar-fixbug.vue index a3d4b83..451a813 100644 --- a/src/components/datav/chart-bar-fixbug.vue +++ b/src/components/datav/chart-bar-fixbug.vue @@ -25,7 +25,7 @@ class="bar-item_content-bar" :style="{ width: `${(item.value / max) * 100}%`, - background: getColor((item.value / max) * 100), + background: item.barColor || getColor((item.value / max) * 100), }" > diff --git a/src/views/datav/Lmgz.vue b/src/views/datav/Lmgz.vue index c542ec2..f12834c 100644 --- a/src/views/datav/Lmgz.vue +++ b/src/views/datav/Lmgz.vue @@ -400,7 +400,7 @@ function getData1() { groupId: groupId1.value, type: type1.value }).then(data => { - list1.value = data + list1.value = withRankColors(data) }); } @@ -411,7 +411,7 @@ function getData2() { groupId: groupId2.value, type: type2.value }).then(data => { - list2.value = data + list2.value = withRankColors(data) }); } @@ -422,10 +422,23 @@ function getData3() { groupId: groupId3.value, type: type3.value }).then(data => { - list3.value = data + list3.value = withRankColors(data) }); } +function withRankColors(data) { + const rankedItems = data.map((item, index) => ({ item, index })) + .sort((a, b) => Number(b.item.value) - Number(a.item.value) || a.index - b.index); + const redCount = Math.ceil(data.length / 3); + const yellowCount = Math.ceil((data.length - redCount) / 2); + const barColors = []; + rankedItems.forEach(({ index }, rank) => { + const colorIndex = rank < redCount ? 0 : rank < redCount + yellowCount ? 1 : 2; + barColors[index] = colors[colorIndex].color; + }); + return data.map((item, index) => ({ ...item, barColor: barColors[index] })); +} + function withProfileScope(data, query, category) { return data.map(item => ({ ...item, @@ -444,7 +457,7 @@ function getData4() { groupId: groupId4.value }; leadNegative(query).then(data => { - list4.value = withProfileScope(data, query, 'lead'); + list4.value = withRankColors(withProfileScope(data, query, 'lead')); }); } @@ -455,7 +468,7 @@ function getData5() { groupId: groupId5.value }; policeNegative(query).then(data => { - list5.value = withProfileScope(data, query, 'police'); + list5.value = withRankColors(withProfileScope(data, query, 'police')); }); } @@ -466,7 +479,7 @@ function getData6() { groupId: groupId6.value }; auxNegative(query).then(data => { - list6.value = withProfileScope(data, query, 'aux'); + list6.value = withRankColors(withProfileScope(data, query, 'aux')); }); }