refactor: 性别分布数据取值逻辑

This commit is contained in:
rd
2025-07-17 14:42:01 +08:00
parent ea918038d3
commit 46ced21844

View File

@ -18,16 +18,16 @@
<a-space> <a-space>
<span style="width: 8px; height: 8px; background-color: #f64b31; border-radius: 50%"></span> <span style="width: 8px; height: 8px; background-color: #f64b31; border-radius: 50%"></span>
<span>女性</span> <span>女性</span>
<span v-if="genderData.length > 0" style="width: 40px">{{ genderData[0].rate * 100 }}%</span> <span>{{ (girlData.rate * 100).toFixed(2) }}%</span>
<span>TGI</span> <span>TGI</span>
<span v-if="genderData.length > 0">{{ genderData[0].tgi }}</span> <span>{{ girlData.tgi }}</span>
</a-space> </a-space>
<a-space> <a-space>
<span style="width: 8px; height: 8px; background-color: #2a59f3; border-radius: 50%"></span> <span style="width: 8px; height: 8px; background-color: #2a59f3; border-radius: 50%"></span>
<span>男性</span> <span>男性</span>
<span v-if="genderData.length > 1" style="width: 40px">{{ genderData[1].rate * 100 }}%</span> <span>{{ (boyData.rate * 100).toFixed(2) }}%</span>
<span>TGI</span> <span>TGI</span>
<span v-if="genderData.length > 1">{{ genderData[1].tgi }}</span> <span>{{ boyData.tgi }}</span>
</a-space> </a-space>
</a-space> </a-space>
</a-space> </a-space>
@ -145,10 +145,13 @@ const topHeaderRef = ref();
const selectedIndustry = computed(() => topHeaderRef.value?.selectedIndustry); const selectedIndustry = computed(() => topHeaderRef.value?.selectedIndustry);
const selectedSubCategory = computed(() => topHeaderRef.value?.selectedSubCategory); const selectedSubCategory = computed(() => topHeaderRef.value?.selectedSubCategory);
const selectedTimePeriod = computed(() => topHeaderRef.value?.selectedTimePeriod); const selectedTimePeriod = computed(() => topHeaderRef.value?.selectedTimePeriod);
const genderData = ref([]); const genderData = ref([]);
const genderValueData = ref([]); const genderValueData = ref([]);
const ageValueData = ref([]); const ageValueData = ref([]);
const geoList = ref([]); const geoList = ref([]);
const boyData = computed(() => genderData.value.find( v => v.gender === 1) ?? {})
const girlData = computed(() => genderData.value.find( v => v.gender === 2) ?? {})
// 监听筛选条件变化 // 监听筛选条件变化
watch([selectedIndustry, selectedTimePeriod, selectedSubCategory], () => { watch([selectedIndustry, selectedTimePeriod, selectedSubCategory], () => {
getAgeDistributionsList(); getAgeDistributionsList();
@ -233,7 +236,7 @@ const getGenderDistributionsList = async () => {
await nextTick(); await nextTick();
genderValueData.value = data.map((item) => ({ genderValueData.value = data.map((item) => ({
value: item.rate * 100, value: (item.rate * 100).toFixed(2),
tgi: item.tgi, tgi: item.tgi,
name: item.gender === 1 ? '女性' : '男性', name: item.gender === 1 ? '女性' : '男性',
})); }));