language.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 } 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. currentLang.value = langValue;
  25. }
  26. </script>
  27. <style scoped lang="scss">
  28. @import "@/uni.scss";
  29. .title {
  30. font-size: px2rpx(22);
  31. color: #000;
  32. font-weight: bold;
  33. margin-bottom: px2rpx(44);
  34. }
  35. .lang-item {
  36. background: var(--main-bg);
  37. border-radius: px2rpx(14);
  38. padding: px2rpx(18);
  39. font-size: px2rpx(20);
  40. margin-bottom: px2rpx(44);
  41. color: #000;
  42. display: flex;
  43. align-items: center;
  44. cursor: pointer;
  45. transition: background 0.2s;
  46. }
  47. .lang-item.active {
  48. border-radius: px2rpx(10);
  49. background: rgba(255, 209, 216, 0.85);
  50. }
  51. .check {
  52. margin-left: auto;
  53. svg {
  54. width: px2rpx(44);
  55. height: px2rpx(44);
  56. font-size: px2rpx(44);
  57. margin-right: px2rpx(12);
  58. color: #4caf50;
  59. }
  60. }
  61. </style>