language.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <cwg-page-wrapper>
  3. <view class="page page-shadow">
  4. <view v-for="item in localesList" :key="item" class="lang-item" :class="{ active: currentLang === item }"
  5. @click="changeLang(item)">
  6. {{ t(`language.${item}`) }}
  7. <view v-if="currentLang === item" class="check">
  8. <cwg-icon name="icon_select" />
  9. </view>
  10. </view>
  11. </view>
  12. </cwg-page-wrapper>
  13. </template>
  14. <script setup lang="ts">
  15. import { ref } from "vue";
  16. import { useI18n } from "vue-i18n";
  17. import { lang } from "@/composables/config";
  18. import { localesList, LANG_MAP } from "@/locale/index";
  19. const { locale, t } = useI18n();
  20. const currentLang = ref(lang.value || locale.value);
  21. function changeLang(langValue: string) {
  22. locale.value = langValue;
  23. lang.value = langValue;
  24. const localeValue = LANG_MAP[langValue] || 'zh-Hans';
  25. uni.setLocale(localeValue);
  26. currentLang.value = langValue;
  27. }
  28. </script>
  29. <style scoped lang="scss">
  30. @import "@/uni.scss";
  31. .title {
  32. font-size: px2rpx(22);
  33. color: #000;
  34. font-weight: bold;
  35. margin-bottom: px2rpx(44);
  36. }
  37. .lang-item {
  38. background: var(--main-bg);
  39. border-radius: px2rpx(14);
  40. padding: px2rpx(18);
  41. font-size: px2rpx(20);
  42. margin-bottom: px2rpx(44);
  43. color: #000;
  44. display: flex;
  45. align-items: center;
  46. cursor: pointer;
  47. transition: background 0.2s;
  48. }
  49. .lang-item.active {
  50. border-radius: px2rpx(10);
  51. background: rgba(255, 209, 216, 0.85);
  52. }
  53. .check {
  54. margin-left: auto;
  55. svg {
  56. width: px2rpx(44);
  57. height: px2rpx(44);
  58. font-size: px2rpx(44);
  59. margin-right: px2rpx(12);
  60. color: #4caf50;
  61. }
  62. }
  63. </style>