diff --git a/index.html b/index.html index 80a2f82..38fde13 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - + diff --git a/src/App.vue b/src/App.vue index 3914481..ec92ba7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,9 +5,10 @@ import imgs from './assets/imgs' import { DimensionColors, DimensionName, findAllTraitByDimension, getRandomDimensionRating, getRandomTraitRating, TraitName } from './config'; import Game from './views/Game.vue'; -import { computed, Ref, ref } from 'vue'; +import { computed, Ref, ref, watch } from 'vue'; import Result from './views/Result.vue'; - +import { useI18n } from 'vue-i18n' +import { setHtmlLang } from './utils' const pIndex = ref(0) const result: Ref> = ref(getRandomDimensionRating()) @@ -30,10 +31,16 @@ function finishGame(r: Record, t: Record({ useScope: 'global' }) + +// 监听locale变化,同步更新HTML lang属性 +watch(locale, (newLocale) => { + setHtmlLang(newLocale) +}, { immediate: true }) const GraphDimensions = computed(() => { const average = Object.values(result.value).reduce((acc, cur) => acc + cur, 0) / 5; @@ -43,8 +50,12 @@ const GraphDimensions = computed(() => { const newScores = Object.entries(result.value).map(([dimName, score]) => { const mean = average const newScore = Math.max(8, score + sign(score - mean) * Math.abs(score - mean) ** p) + + const currentLang = lang[locale.value as keyof typeof lang] ?? lang.en + return { - name_zh: lang.zh_CN.questionData.DimensionName[dimName as DimensionName], + + name_zh: currentLang.questionData.DimensionName[dimName as DimensionName], name_en: lang.en.questionData.DimensionName[dimName as DimensionName], value: newScore, color: DimensionColors[dimName as DimensionName], @@ -85,7 +96,7 @@ const topFiveTraits = computed(() => { const gender = ref('_gender_') -const username = ref('_username_') +const username = ref('_userna_') const age = ref(0) function submitUserInfo(data: { gender: string, username: string, age: number }) { @@ -95,18 +106,24 @@ function submitUserInfo(data: { gender: string, username: string, age: number }) pIndex.value = 3 } -const showDebug = ref(1) +const showDebug = ref(-5)