Merge remote-tracking branch 'origin/main'

This commit is contained in:
xingyy 2025-02-19 15:14:10 +08:00
commit ddebdbae4a

View File

@ -11,11 +11,17 @@ const router = useRouter()
console.log('router',router) console.log('router',router)
const { t, locale } = useI18n() const { t, locale } = useI18n()
const value = ref(''); const value = ref('');
const alphabet = [ const alphabet = computed(() => {
'#', if (!groupedCountries.value) return ['#'];
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' //
]; const letters = Object.keys(groupedCountries.value)
.filter(key => key !== '#')
.sort();
// #
return ['#', ...letters];
});
// //
const frequentCountryCodes = ['CN', 'TW', 'JP', 'US']; const frequentCountryCodes = ['CN', 'TW', 'JP', 'US'];
@ -46,11 +52,19 @@ function groupByPinyinInitial(data) {
locale.value === 'zh-TW' ? country.tw : locale.value === 'zh-TW' ? country.tw :
locale.value === 'ja-JP' ? country.ja : locale.value === 'ja-JP' ? country.ja :
country.en; country.en;
const initial = locale.value === 'ja-JP' ? '' : // 使
locale.value === 'zh-CN' || locale.value === 'zh-TW' ? let initial;
pinyin(countryName, {style: pinyin.STYLE_FIRST_LETTER})[0][0].toUpperCase() : if (locale.value === 'zh-CN' || locale.value === 'zh-TW') {
countryName.charAt(0).toUpperCase(); // 使
const pinyinName = locale.value === 'zh-CN' ? country.cn : country.tw;
initial = pinyin(pinyinName, {style: pinyin.STYLE_FIRST_LETTER})[0][0].toUpperCase();
} else if (locale.value === 'ja-JP') {
initial = '';
} else {
// 使 en
initial = country.en.charAt(0).toUpperCase();
}
if (!grouped[initial]) { if (!grouped[initial]) {
grouped[initial] = []; grouped[initial] = [];
@ -62,12 +76,38 @@ function groupByPinyinInitial(data) {
} }
}); });
if (locale.value === 'ja-JP') { //
// Object.keys(grouped).forEach(key => {
grouped[''] = grouped[''].sort((a, b) => a.displayName.localeCompare(b.displayName, 'ja-JP')); grouped[key].sort((a, b) => {
} if (locale.value === 'zh-CN' || locale.value === 'zh-TW') {
// 使
const pinyinA = pinyin(locale.value === 'zh-CN' ? a.cn : a.tw, {style: pinyin.STYLE_NORMAL}).join('');
const pinyinB = pinyin(locale.value === 'zh-CN' ? b.cn : b.tw, {style: pinyin.STYLE_NORMAL}).join('');
return pinyinA.localeCompare(pinyinB);
} else if (locale.value === 'ja-JP') {
return a.displayName.localeCompare(b.displayName, 'ja-JP');
} else {
return a.en.localeCompare(b.en);
}
});
});
return grouped; if (locale.value === 'ja-JP') {
return grouped;
} else {
//
const sortedGrouped = {};
// #
sortedGrouped['#'] = grouped['#'];
//
Object.keys(grouped)
.filter(key => key !== '#')
.sort()
.forEach(key => {
sortedGrouped[key] = grouped[key];
});
return sortedGrouped;
}
} }
const groupedCountries = ref([]) const groupedCountries = ref([])
@ -83,6 +123,7 @@ const searchCountry = computed(() => {
const countries = groupedCountries.value[initial].filter(country => const countries = groupedCountries.value[initial].filter(country =>
country.displayName.toLowerCase().includes(value.value.toLowerCase()) country.displayName.toLowerCase().includes(value.value.toLowerCase())
); );
if (countries.length > 0) { if (countries.length > 0) {
filtered[initial] = countries; filtered[initial] = countries;
} }
@ -103,7 +144,7 @@ const handleCountrySelect = (country) => {
} }
initData() initData()
console.log('searchCountry',searchCountry.value)
// //
watch(locale, () => { watch(locale, () => {
initData() initData()