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)
const { t, locale } = useI18n()
const value = ref('');
const alphabet = [
'#',
'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 alphabet = computed(() => {
if (!groupedCountries.value) return ['#'];
//
const letters = Object.keys(groupedCountries.value)
.filter(key => key !== '#')
.sort();
// #
return ['#', ...letters];
});
//
const frequentCountryCodes = ['CN', 'TW', 'JP', 'US'];
@ -47,10 +53,18 @@ function groupByPinyinInitial(data) {
locale.value === 'ja-JP' ? country.ja :
country.en;
const initial = locale.value === 'ja-JP' ? '' :
locale.value === 'zh-CN' || locale.value === 'zh-TW' ?
pinyin(countryName, {style: pinyin.STYLE_FIRST_LETTER})[0][0].toUpperCase() :
countryName.charAt(0).toUpperCase();
// 使
let initial;
if (locale.value === 'zh-CN' || locale.value === 'zh-TW') {
// 使
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]) {
grouped[initial] = [];
@ -62,12 +76,38 @@ function groupByPinyinInitial(data) {
}
});
if (locale.value === 'ja-JP') {
//
grouped[''] = grouped[''].sort((a, b) => a.displayName.localeCompare(b.displayName, 'ja-JP'));
//
Object.keys(grouped).forEach(key => {
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);
}
});
});
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([])
@ -83,6 +123,7 @@ const searchCountry = computed(() => {
const countries = groupedCountries.value[initial].filter(country =>
country.displayName.toLowerCase().includes(value.value.toLowerCase())
);
if (countries.length > 0) {
filtered[initial] = countries;
}
@ -103,7 +144,7 @@ const handleCountrySelect = (country) => {
}
initData()
console.log('searchCountry',searchCountry.value)
//
watch(locale, () => {
initData()