This commit is contained in:
xingyy 2025-02-27 15:00:46 +08:00
parent 462a2b23a9
commit 950625f880
4 changed files with 14 additions and 32 deletions

View File

@ -1,5 +1,9 @@
<script setup>
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const props = defineProps({
modelValue: {
type: [Number, String]
@ -21,7 +25,7 @@ const props = defineProps({
placeholder: {
type: String,
default: '请选择'
default: () => t('components.form.pleaseSelect')
},
disabled: {
@ -75,9 +79,9 @@ const openPopup=()=>{
@confirm="onConfirm"
@cancel="show = false"
:default-index="columns.findIndex(x => x.value === modelValue)"
title="请选择"
confirm-button-text="确定"
cancel-button-text="取消"
:title="t('components.form.pleaseSelect')"
:confirm-button-text="t('components.dialog.confirm')"
:cancel-button-text="t('components.dialog.cancel')"
/>
</van-popup>
</div>

View File

@ -81,7 +81,7 @@ fetchData()
<!-- 设置选项 -->
<div class="px-16px mb-20px">
<van-cell-group inset>
<van-cell :title="$t('settings.language')" is-link @click="router.push('/profile/language')" />
<!-- 移除语言设置入口 -->
</van-cell-group>
</div>

View File

@ -34,32 +34,11 @@ export default defineNuxtPlugin(() => {
return 'zh-CN'
}
// 获取用户手动设置的语言或系统语言
const lang = localStorage.getItem('lang')
if (lang) {
// 用户手动设置了语言,优先使用
setLocale(lang as TypeLocale)
Locale.use(lang)
} else {
// 用户未手动设置语言,使用系统语言
const systemLang = getSystemLanguage()
setLocale(systemLang as TypeLocale)
Locale.use(systemLang)
// 将系统语言保存到 localStorage以便下次使用
localStorage.setItem('lang', systemLang)
}
// 使用系统语言
const systemLang = getSystemLanguage()
setLocale(systemLang as TypeLocale)
Locale.use(systemLang)
// 监听系统语言变化(当用户未手动设置语言时)
window.addEventListener('languagechange', () => {
// 只有当用户未手动设置语言时,才跟随系统语言变化
if (!localStorage.getItem('lang')) {
const systemLang = getSystemLanguage()
setLocale(systemLang as TypeLocale)
Locale.use(systemLang)
}
})
// 监听语言变化,当语言变化时,如果有活跃的 WebSocket 连接,则重新连接
watch(() => i18n.locale.value, (newLocale) => {
// 如果 WebSocket 插件已加载并且有活跃连接

View File

@ -54,11 +54,10 @@ export default defineNuxtConfig({
lazy: true,
strategy: 'no_prefix',
detectBrowserLanguage: {
useCookie: true,
useCookie: false,
cookieKey: 'i18n_redirected',
redirectOn: 'root',
alwaysRedirect: true,
fallbackLocale: 'zh-CN'
},
defaultLocale: 'zh-CN',
vueI18n: './i18n/i18n.config.ts',