feat: 进入主页同步登录页语言

This commit is contained in:
zhangyh
2025-11-25 13:26:52 +08:00
parent f906230d65
commit 0ef8b3060c
2 changed files with 22 additions and 4 deletions

View File

@@ -62,10 +62,8 @@
},
methods: {
onInput(val, index) {
console.log("input", val, index);
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
console.log("input=>", val, index);
// val = val.replace(/[^0-9]/g, '');
val = String(val).replace(/\D/g, "");
this.getCtData[index] = val;

View File

@@ -1127,7 +1127,21 @@ export default defineComponent({
document.addEventListener('click', this.operateClick)
}
this.getCredits()
this.getLang('')
// 获取用户语言并检查是否需要与 localStorage 中的 loginLanguage 同步
this.getLang('').then(userLanguage => {
// 检查 localStorage 中的 loginLanguage
const loginLanguage = localStorage.getItem('loginLanguage')
if (loginLanguage && userLanguage && loginLanguage !== userLanguage) {
// 如果 loginLanguage 与用户当前语言不同,则更新用户语言
this.setLocale(loginLanguage)
}
}).catch(() => {
// 如果获取用户语言失败,也检查 localStorage
const loginLanguage = localStorage.getItem('loginLanguage')
if (loginLanguage && loginLanguage !== this.locale) {
this.setLocale(loginLanguage)
}
})
//语言适配
let tl1 = gsap.timeline({ paused: true })
@@ -1289,11 +1303,13 @@ export default defineComponent({
//获取当前语言
getLang(v) {
let data
Https.axiosPost(Https.httpUrls.getUserLanguage, data).then(rv => {
return Https.axiosPost(Https.httpUrls.getUserLanguage, data).then(rv => {
if (rv) {
this.locale = rv
setLang(rv)
return rv
}
return null
})
},
setLang(v) {
@@ -1323,6 +1339,10 @@ export default defineComponent({
},
setLocale(v) {
// 同步更新 localStorage 中的 loginLanguage
if (v) {
localStorage.setItem('loginLanguage', v)
}
this.setLang(v)
},
openTask(data) {