| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <template>
- <view class="cwg-language">
- <cwg-dropdown :menu-list="customMenuList" @menuClick="handleMenuClick">
- <view class="pc-header-btn">
- <cwg-icon name="cwg-lang" :color="iconColor" :size="20" />
- </view>
- </cwg-dropdown>
- </view>
- </template>
- <script setup lang="ts">
- import { computed } from 'vue'
- import { useI18n } from 'vue-i18n'
- import { localesList, LANG_MAP } from '@/locale/index'
- import { lang } from '@/composables/config'
- const props = defineProps({
- iconColor: {
- type: String,
- default: '#141d22'
- },
- })
- const { t, locale } = useI18n()
- const customMenuList = computed(() =>
- localesList.map((code) => ({
- label: t(`language.${code}`),
- type: code
- })),
- )
- function handleMenuClick({ value }: { value: any }) {
- const type = value?.type ?? value
- if (!type) return
- locale.value = type
- lang.value = type
- const localeValue = LANG_MAP[type] || 'zh-Hans'
- uni.setLocale(localeValue)
- }
- function getFlagSrc(code: string) {
- switch (code) {
- case 'en':
- return '/static/flag-en.png'
- case 'cn':
- return '/static/flag-cn.png'
- case 'zhHant':
- return '/static/flag-zhHant.png'
- case 'es':
- return '/static/flag-es.png'
- default:
- return '/static/flag-en.png'
- }
- }
- </script>
- <style scoped lang="scss">
- @import "@/uni.scss";
- .pc-header-btn {
- display: flex;
- align-items: center;
- cursor: pointer;
- gap: px2rpx(6);
- }
- .cwg-language {
- @media screen and (max-width: 991px) {
- :deep(.cwg-dropdown-menu-container) {
- right: px2rpx(-20) !important;
- }
- }
- }
- :deep(.cwg-dropdown-menu-container .menu .menu-item) {
- min-height: px2rpx(36);
- }
- :deep(.cwg-dropdown) {
- overflow: visible !important;
- }
- </style>
|