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

View File

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

View File

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

View File

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