This commit is contained in:
xingyy 2025-01-10 13:23:11 +08:00
parent b9fb752bb0
commit afe57c16f7

View File

@ -22,7 +22,25 @@ function groupByPinyinInitial(data) {
return grouped;
}
const groupedCountries = groupByPinyinInitial(countryCode);
const groupedCountries = ref([])
const initData=()=>{
groupedCountries.value = groupByPinyinInitial(countryCode);
}
const searchCountry = computed(() => {
if (!value.value) {
return groupedCountries.value;
}
return Object.keys(groupedCountries.value).reduce((filtered, initial) => {
const countries = groupedCountries.value[initial].filter(country =>
country.cn.includes(value.value)
);
if (countries.length > 0) {
filtered[initial] = countries;
}
return filtered;
}, {});
});
initData()
</script>
<template>
@ -30,22 +48,22 @@ const groupedCountries = groupByPinyinInitial(countryCode);
<van-sticky>
<van-search v-model="value" placeholder="请输入国家和地区"/>
</van-sticky>
<van-index-bar class="mt-[00px]" :index-list="alphabet">
<van-index-bar sticky :sticky-offset-top="55" class="mt-[00px]" :index-list="alphabet">
<template v-for="(countries, index) in searchCountry" :key="index">
<van-index-anchor
v-for="(countries, index) in groupedCountries"
:key="index"
:index="index"
>
<div class="text-#939393 text-[14px] pl-[16px] bg-[#F3F3F3]">{{ index }}</div>
<van-cell v-for="country in countries" :key="country.code" :title="country.cn"/>
</van-index-anchor>
></van-index-anchor>
<van-cell v-for="country in countries" :key="country.code" :title="country.cn">
<div class="pr-[25px]"> +{{ country.zone }}</div>
</van-cell>
</template>
</van-index-bar>
<van-back-top right="15vw" bottom="10vh"/>
</div>
</template>
<style scoped>
:deep(.van-index-anchor) {
padding: 0;
}
</style>