index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <view class="language-switcher" @click="handleSwitch">
  3. <text class="language-icon">🌐</text>
  4. <text class="language-text">{{ currentLocaleName }}</text>
  5. </view>
  6. </template>
  7. <script setup>
  8. import { computed } from 'vue'
  9. import { useI18n } from 'vue-i18n'
  10. import { useLocaleStore } from '@/store/locale'
  11. const { t } = useI18n()
  12. const localeStore = useLocaleStore()
  13. const currentLocaleName = computed(() => localeStore.getCurrentLocaleName())
  14. const handleSwitch = () => {
  15. const success = localeStore.toggleLocale()
  16. if (success) {
  17. uni.showToast({
  18. title: t('components.languageSwitcher.switchSuccess'),
  19. icon: 'success',
  20. duration: 1500
  21. })
  22. } else {
  23. uni.showToast({
  24. title: t('components.languageSwitcher.switchFailed'),
  25. icon: 'error',
  26. duration: 1500
  27. })
  28. }
  29. }
  30. </script>
  31. <style lang="scss" scoped>
  32. .language-switcher {
  33. display: inline-flex;
  34. align-items: center;
  35. gap: 8rpx;
  36. background: rgba(255, 255, 255, 0.2);
  37. padding: 12rpx 24rpx;
  38. border-radius: 30rpx;
  39. backdrop-filter: blur(10rpx);
  40. border: 1rpx solid rgba(255, 255, 255, 0.3);
  41. .language-icon {
  42. font-size: 28rpx;
  43. }
  44. .language-text {
  45. font-size: 24rpx;
  46. color: #ffffff;
  47. font-weight: 500;
  48. }
  49. }
  50. </style>