language.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <div class="page">
  3. <div class="title">{{ t('language.selectLang') }}</div>
  4. <div v-for="item in localesList" :key="item" class="lang-item" :class="{ active: currentLang === item }" @click="changeLang(item)">
  5. {{ t(`language.${item}`) }}
  6. <span v-if="currentLang === item" class="check">✔</span>
  7. </div>
  8. </div>
  9. </template>
  10. <script setup lang="ts">
  11. import { useI18n } from 'vue-i18n'
  12. import { ref } from 'vue'
  13. import { localesList } from '@/plugin/i18n'
  14. import { lang } from '@/composables/config'
  15. const { locale, t } = useI18n()
  16. const currentLang = ref(lang.value || locale.value)
  17. function changeLang(langValue: string) {
  18. locale.value = langValue
  19. lang.value = langValue
  20. currentLang.value = langValue
  21. }
  22. </script>
  23. <style scoped lang="scss">
  24. .title {
  25. font-size: var(--font-size-22);
  26. font-weight: bold;
  27. margin-bottom: 24px;
  28. }
  29. .lang-item {
  30. background: var(--main-bg);
  31. border-radius: 14px;
  32. padding: 18px 18px;
  33. font-size: var(--font-size-18);
  34. margin-bottom: 16px;
  35. color: var(--main-yellow);
  36. display: flex;
  37. align-items: center;
  38. cursor: pointer;
  39. transition: background 0.2s;
  40. }
  41. .lang-item.active {
  42. background: var(--main-yellow);
  43. color: var(--main-bg);
  44. font-weight: bold;
  45. }
  46. .check {
  47. margin-left: auto;
  48. color: var(--main-bg);
  49. font-size: var(--font-size-18);
  50. }
  51. </style>