cwg-language.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view class="cwg-language">
  3. <cwg-dropdown :menu-list="customMenuList" @menuClick="handleMenuClick" showActive :activeKey="lang">
  4. <view class="pc-header-btn">
  5. <cwg-icon name="cwg-lang" :color="iconColor " :size="20" />
  6. </view>
  7. </cwg-dropdown>
  8. </view>
  9. </template>
  10. <script setup lang="ts">
  11. import { computed } from 'vue'
  12. import { useI18n } from 'vue-i18n'
  13. import { localesList, switchAppLanguage } from '@/locale/index'
  14. import { lang } from '@/composables/config'
  15. const props = defineProps({
  16. iconColor: {
  17. type: String,
  18. default: '#97A1C0'
  19. },
  20. })
  21. const { t, locale } = useI18n()
  22. const customMenuList = computed(() =>
  23. localesList.map((code) => ({
  24. label: t(`language.${code}`),
  25. type: code
  26. })),
  27. )
  28. function handleMenuClick({ value }: { value: any }) {
  29. const type = value?.type ?? value
  30. switchAppLanguage(type, { locale, lang })
  31. }
  32. function getFlagSrc(code: string) {
  33. switch (code) {
  34. case 'en':
  35. return '/static/flag-en.png'
  36. case 'cn':
  37. return '/static/flag-cn.png'
  38. case 'zhHant':
  39. return '/static/flag-zhHant.png'
  40. case 'es':
  41. return '/static/flag-es.png'
  42. default:
  43. return '/static/flag-en.png'
  44. }
  45. }
  46. </script>
  47. <style scoped lang="scss">
  48. @import "@/uni.scss";
  49. .pc-header-btn {
  50. display: flex;
  51. align-items: center;
  52. cursor: pointer;
  53. gap: px2rpx(6);
  54. }
  55. .cwg-language {
  56. @media screen and (max-width: 991px) {
  57. :deep(.cwg-dropdown-menu-container) {
  58. right: px2rpx(-20) !important;
  59. }
  60. }
  61. }
  62. :deep(.cwg-dropdown-menu-container .menu .menu-item) {
  63. min-height: px2rpx(36);
  64. }
  65. :deep(.cwg-dropdown) {
  66. overflow: visible !important;
  67. }
  68. </style>