feat(头部组件): 引入语言切换功能

This commit is contained in:
hzj 2025-10-29 20:28:04 +08:00
parent 5cad3cad1d
commit 14dd6a0cf9

View File

@ -19,6 +19,8 @@
<img :src="backImg" alt="" style="width: 100%; aspect-ratio: 1/1; display: block" />
</button>
</div>
<!-- 标题 -->
<h1
style="
font-size: 1.2em;
@ -40,15 +42,66 @@
style="width: 100%; display: block"
/>
</button>
<!-- 语言切换 -->
<div
style="
display: flex;
align-items: center;
position: relative;
color: rgba(187, 146, 255, 1) !important;
"
@click="showLang"
v-if="showLanguageList"
>
<div style="font-weight: bold">{{ currentLangType }}</div>
<!-- <div
style="margin-left: 5px; transition: transform 0.5s"
:class="{ rotated: visibleList }"
>
>
</div> -->
<transition name="slide-fade">
<div
style="
position: absolute;
right: 0;
top: 100%;
padding: 10px;
display: flex;
flex-direction: column;
width: max-content;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 10px;
margin-top: 5px;
backdrop-filter: blur(8px);
"
v-show="visibleList"
class="extraList"
>
<div
style="padding: 8px; color: white !important; font-weight: 590"
v-for="lang in langStore.langList"
@click.stop="handleLanguageChange(lang)"
>
{{ lang.value }}
</div>
</div>
</transition>
</div>
<!-- 插槽 -->
<slot name="extraFunction"></slot>
</div>
</div>
</template>
<script setup>
import { isInApp } from '@/utils/appBridge.js'
import { useRouter, useRoute } from 'vue-router'
import { computed, ref, onMounted } from 'vue'
import { closePage, isInApp } from '@/utils/appBridge.js'
import { computed, ref, onMounted, watch } from 'vue'
import { useLangStore } from '@/stores/lang'
import { setLocale } from '@/locales/i18n'
// props
const props = defineProps({
@ -68,12 +121,14 @@ const props = defineProps({
type: Boolean,
default: false,
},
showLanguageList: {
type: Boolean,
default: false,
},
color: {
type: String,
default: '#fff',
},
backImg: {
type: String,
default: () => {
@ -87,6 +142,32 @@ defineEmits(['help'])
const router = useRouter()
const route = useRoute()
const langStore = useLangStore()
const visibleList = ref(false) //
//
const currentLangType = computed(() => {
return langStore.selectedLang?.value || 'EN'
})
// UI
watch(
() => langStore.selectedLang,
(newLang) => {
console.log('Language changed in header:', newLang)
},
{ deep: true }
)
const handleLanguageChange = (item) => {
visibleList.value = false
console.log('visibleList.value', visibleList.value)
console.log('Changing language to:', item)
setLocale(langStore, item.type)
// visibleList
}
// APP
const isInAppEnvironment = ref(false)
@ -117,13 +198,20 @@ const handleBack = () => {
if (isCurrentlyHomePage.value && isInApp()) {
// APP
console.log('home back')
closePage()
// closePage() //
} else {
//
router.go(-1)
}
}
//
const showLang = () => {
visibleList.value = !visibleList.value
console.log('visibleList.value', visibleList.value)
}
//
onMounted(() => {
isInAppEnvironment.value = isInApp()