Browse Source

fix: 按红黄绿排序

master
buaixuexideshitongxue 23 hours ago
parent
commit
a003d759df
  1. 2
      src/components/datav/chart-bar-fixbug.vue
  2. 25
      src/views/datav/Lmgz.vue

2
src/components/datav/chart-bar-fixbug.vue

@ -25,7 +25,7 @@
class="bar-item_content-bar" class="bar-item_content-bar"
:style="{ :style="{
width: `${(item.value / max) * 100}%`, width: `${(item.value / max) * 100}%`,
background: getColor((item.value / max) * 100), background: item.barColor || getColor((item.value / max) * 100),
}" }"
></div> ></div>
</div> </div>

25
src/views/datav/Lmgz.vue

@ -400,7 +400,7 @@ function getData1() {
groupId: groupId1.value, groupId: groupId1.value,
type: type1.value type: type1.value
}).then(data => { }).then(data => {
list1.value = data list1.value = withRankColors(data)
}); });
} }
@ -411,7 +411,7 @@ function getData2() {
groupId: groupId2.value, groupId: groupId2.value,
type: type2.value type: type2.value
}).then(data => { }).then(data => {
list2.value = data list2.value = withRankColors(data)
}); });
} }
@ -422,10 +422,23 @@ function getData3() {
groupId: groupId3.value, groupId: groupId3.value,
type: type3.value type: type3.value
}).then(data => { }).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) { function withProfileScope(data, query, category) {
return data.map(item => ({ return data.map(item => ({
...item, ...item,
@ -444,7 +457,7 @@ function getData4() {
groupId: groupId4.value groupId: groupId4.value
}; };
leadNegative(query).then(data => { 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 groupId: groupId5.value
}; };
policeNegative(query).then(data => { 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 groupId: groupId6.value
}; };
auxNegative(query).then(data => { auxNegative(query).then(data => {
list6.value = withProfileScope(data, query, 'aux'); list6.value = withRankColors(withProfileScope(data, query, 'aux'));
}); });
} }

Loading…
Cancel
Save