Compare commits

..

No commits in common. "4202d94a4471935e8e943fc5cbbbd34dd61d3661" and "3be7cec1c2836c3fc3f754137f50b043df374b2f" have entirely different histories.

View File

@ -11,17 +11,11 @@ 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 = computed(() => { const alphabet = [
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'];
@ -52,18 +46,10 @@ function groupByPinyinInitial(data) {
locale.value === 'ja-JP' ? country.ja : locale.value === 'ja-JP' ? country.ja :
country.en; country.en;
// 使 const initial = locale.value === 'ja-JP' ? '' :
let initial; locale.value === 'zh-CN' || locale.value === 'zh-TW' ?
if (locale.value === 'zh-CN' || locale.value === 'zh-TW') { pinyin(countryName, {style: pinyin.STYLE_FIRST_LETTER})[0][0].toUpperCase() :
// 使 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] = [];
@ -75,38 +61,12 @@ function groupByPinyinInitial(data) {
} }
}); });
//
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') { if (locale.value === 'ja-JP') {
return grouped; //
} else { grouped[''] = grouped[''].sort((a, b) => a.displayName.localeCompare(b.displayName, 'ja-JP'));
//
const sortedGrouped = {};
// #
sortedGrouped['#'] = grouped['#'];
//
Object.keys(grouped)
.filter(key => key !== '#')
.sort()
.forEach(key => {
sortedGrouped[key] = grouped[key];
});
return sortedGrouped;
} }
return grouped;
} }
const groupedCountries = ref([]) const groupedCountries = ref([])
@ -122,7 +82,6 @@ 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;
} }
@ -143,7 +102,7 @@ const handleCountrySelect = (country) => {
} }
initData() initData()
console.log('searchCountry',searchCountry.value)
// //
watch(locale, () => { watch(locale, () => {
initData() initData()