From d27e5268f39cdb73a1edf19d5ce614081adf25b5 Mon Sep 17 00:00:00 2001 From: scout <1134087124@qq.com> Date: Wed, 15 Jan 2025 13:05:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(country):=20=E6=96=B0=E5=A2=9E=E5=9B=BD?= =?UTF-8?q?=E5=AE=B6=E5=9C=B0=E5=8C=BA=E9=80=89=E6=8B=A9=E5=8A=9F=E8=83=BD?= =?UTF-8?q?,=E6=94=AF=E6=8C=81=E5=B8=B8=E7=94=A8=E5=9B=BD=E5=AE=B6?= =?UTF-8?q?=E5=BF=AB=E9=80=9F=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/pages/countryRegion/index.vue | 134 ++++++++++++++++++++++++------ 1 file changed, 107 insertions(+), 27 deletions(-) diff --git a/app/pages/countryRegion/index.vue b/app/pages/countryRegion/index.vue index a13fe01..cba249c 100644 --- a/app/pages/countryRegion/index.vue +++ b/app/pages/countryRegion/index.vue @@ -3,37 +3,69 @@ import {ref, computed, watch} from 'vue'; import pinyin from 'pinyin'; import countryCode from './data/index.js'; import { useI18n } from 'vue-i18n' - +import { useRouter } from 'vue-router' +definePageMeta({ + title: '国家地区', + i18n: 'countryRegion.title', +}) +const router = useRouter() 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 frequentCountryCodes = ['CN', 'TW', 'JP', 'US']; + function groupByPinyinInitial(data) { const grouped = {}; + + // 先处理常用国家 + grouped['#'] = []; data.forEach(country => { - // 根据当前语言选择对应的国家名称 - const countryName = locale.value === 'zh-CN' ? country.cn : - locale.value === 'zh-TW' ? country.tw : - 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(); - - if (!grouped[initial]) { - grouped[initial] = []; + if (frequentCountryCodes.includes(country.code)) { + const countryName = locale.value === 'zh-CN' ? country.cn : + locale.value === 'zh-TW' ? country.tw : + locale.value === 'ja-JP' ? country.ja : + country.en; + grouped['#'].push({ + ...country, + displayName: countryName + }); } - grouped[initial].push({ - ...country, - displayName: countryName - }); }); + // 处理其他国家 + data.forEach(country => { + if (!frequentCountryCodes.includes(country.code)) { + const countryName = locale.value === 'zh-CN' ? country.cn : + locale.value === 'zh-TW' ? country.tw : + 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(); + + if (!grouped[initial]) { + grouped[initial] = []; + } + grouped[initial].push({ + ...country, + displayName: countryName + }); + } + }); + + if (locale.value === 'ja-JP') { + // 日文环境下按照片假名排序 + grouped[''] = grouped[''].sort((a, b) => a.displayName.localeCompare(b.displayName, 'ja-JP')); + } + return grouped; } @@ -59,6 +91,16 @@ const searchCountry = computed(() => { const showIndexBar = computed(() => locale.value !== 'ja-JP') +const handleCountrySelect = (country) => { + router.push({ + path: '/login', + query: { + zone: country.zone, + countryName: country.displayName + } + }) +} + initData() // 监听语言变化,重新初始化数据 @@ -78,20 +120,58 @@ watch(locale, () => { :sticky-offset-top="55" :index-list="alphabet" > + + {{ t('countryRegion.frequentCountry') }} + +
+{{ country.zone }}
+
+ +
- +
+
{{ t('countryRegion.frequentCountry') }}
+ +
+{{ country.zone }}
+
+
+ +
+{{ country.zone }}