From f40cdd23962daf715d028d5a0f9ea381c870ee1e Mon Sep 17 00:00:00 2001 From: zhangrenyuan <18990852002@163.com> Date: Thu, 27 Nov 2025 19:33:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=84=20refactor:=20=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5=EF=BC=8C?= =?UTF-8?q?=E5=85=A8=E5=B1=80=EF=BC=81=EF=BC=81=EF=BC=88=E6=8A=8Alang?= =?UTF-8?q?=E5=86=99=E4=BA=86headers=EF=BC=8C=E5=88=87=E6=8D=A2=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E5=90=8E=E4=BC=9A=E5=85=A8=E5=B1=80=E5=88=B7=E6=96=B0?= =?UTF-8?q?=EF=BC=8C=E5=8C=85=E6=8B=AC=E6=B5=8F=E8=A7=88=E5=99=A8=E5=90=8E?= =?UTF-8?q?=E7=BB=AD=E4=BC=98=E5=8C=96=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/dialogs/LanguageSwitch.vue | 9 +++++++-- src/components/locales/index.js | 2 +- src/components/locales/lang/en.js | 2 ++ src/main.ts | 13 ++++++++++++- src/util/request.js | 12 +++++------- src/views/audit/gold/rechargeAudit.vue | 2 +- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/components/dialogs/LanguageSwitch.vue b/src/components/dialogs/LanguageSwitch.vue index 702bc89..264ab5e 100644 --- a/src/components/dialogs/LanguageSwitch.vue +++ b/src/components/dialogs/LanguageSwitch.vue @@ -5,7 +5,7 @@ width="300px" :close-on-click-modal="false" append-to-body - class="language-switch-dialog" + class="lang-switch-dialog" > @@ -83,9 +83,14 @@ const open = () => { // 确认修改 const handleConfirm = () => { locale.value = tempLang.value - localStorage.setItem('language', tempLang.value) + localStorage.setItem('lang', tempLang.value) ElMessage.success(`语言已切换为:${getLangLabel(tempLang.value)}`) dialogVisible.value = false + + // 触发页面刷新以重新加载数据 + setTimeout(() => { + window.location.reload() + }, 500) } defineExpose({ diff --git a/src/components/locales/index.js b/src/components/locales/index.js index 0422819..3a2aa27 100644 --- a/src/components/locales/index.js +++ b/src/components/locales/index.js @@ -15,7 +15,7 @@ const messages = { // 获取浏览器默认语言或缓存语言 const getLocale = () => { // 优先读取缓存,没有则读取浏览器语言,默认 zh-CN - return localStorage.getItem('language') || 'zh-CN' + return localStorage.getItem('lang') || 'zh-CN' } const i18n = createI18n({ diff --git a/src/components/locales/lang/en.js b/src/components/locales/lang/en.js index 3236083..71945a3 100644 --- a/src/components/locales/lang/en.js +++ b/src/components/locales/lang/en.js @@ -32,6 +32,8 @@ export default { // Currency Types SGD: 'SGD', goldCoin: '', // Gold Coin label intentionally empty + // 对话框标题 + will: 'Will', }, // Audit Group diff --git a/src/main.ts b/src/main.ts index 9079501..23beb46 100644 --- a/src/main.ts +++ b/src/main.ts @@ -49,4 +49,15 @@ app.use(ElementPlus, { const adminStore = useAdminStore() const messageStore = useMessageStore() adminStore.initFromLocalStorage() -messageStore.initFromLocalStorage() \ No newline at end of file +messageStore.initFromLocalStorage() + +// 初始化语言设置 +const initLanguage = () => { + const lang = localStorage.getItem('lang') + if (!lang) { + // 如果没有设置语言,默认使用中文 + localStorage.setItem('lang', 'zh-CN') + } +} + +initLanguage() \ No newline at end of file diff --git a/src/util/request.js b/src/util/request.js index 2b312ca..5871979 100644 --- a/src/util/request.js +++ b/src/util/request.js @@ -26,15 +26,13 @@ export const uploadFile = (file) => { service.interceptors.request.use(config => { const token = localStorage.getItem('token') if (token) { - // 请求体里面为什么放token? - // if (config.data) { - // config.data.token = token; - // } else { - // config.data = { token }; - // } config.headers.token = `${token}` } + // 统一使用 'lang' 作为键名 + const lang = localStorage.getItem('lang') || 'zh-CN' + config.headers.lang = lang return config + }, error => { return Promise.reject(error) }) @@ -56,4 +54,4 @@ service.interceptors.response.use( } ) -export default service +export default service \ No newline at end of file diff --git a/src/views/audit/gold/rechargeAudit.vue b/src/views/audit/gold/rechargeAudit.vue index 3a316b8..6d42dce 100644 --- a/src/views/audit/gold/rechargeAudit.vue +++ b/src/views/audit/gold/rechargeAudit.vue @@ -94,7 +94,7 @@ - +