-
Notifications
You must be signed in to change notification settings - Fork 232
支持语言切换时保存用户设置至服务器,修复多语言切换后刷新页面无法正确使用当前语言问题。 #719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -211,16 +211,23 @@ const useUserStore = defineStore( | |
|
|
||
| await nextTick() | ||
| useThemeColor().initThemeColor() | ||
| const locale = settings?.app?.useLocale ?? (language.value?.trim() || 'zh_CN') | ||
| const cacheLanguage = cache.get('language', '')?.trim?.() || '' | ||
| const settingsLanguage = settings?.app?.useLocale?.trim?.() || '' | ||
| const locale = cacheLanguage || settingsLanguage || 'zh_CN' | ||
| const appSettings = setting.getSettings('app') | ||
| if (appSettings) { | ||
| appSettings.useLocale = locale | ||
| } | ||
| setLanguage(locale) | ||
| } | ||
|
|
||
| function saveSettingToSever() { | ||
| const backend_setting = setting.getSettings() | ||
| useHttp().post('/admin/permission/update', { backend_setting }).then(() => { | ||
| return useHttp().post('/admin/permission/update', { backend_setting }).then(() => { | ||
| cache.set('sys_settings', backend_setting) | ||
| }).catch((error) => { | ||
| console.log(error) | ||
| return Promise.reject(error) | ||
| }) | ||
|
Comment on lines
+226
to
231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# 目的:定位所有 saveSettingToSever 调用点,核对是否有 await / .catch 处理
rg -nP --type=ts --type=tsx '\bsaveSettingToSever\s*\(' -C2Repository: mineadmin/MineAdmin Length of output: 90 🏁 Script executed: #!/bin/bash
# 搜索所有 saveSettingToSever 调用点(修正:不指定不支持的 tsx 类型)
rg -n 'saveSettingToSever\s*\(' --type=ts -C 3Repository: mineadmin/MineAdmin Length of output: 2069 🏁 Script executed: #!/bin/bash
# 如果上面失败,尝试不用类型过滤
rg -n 'saveSettingToSever\s*\(' -C 3Repository: mineadmin/MineAdmin Length of output: 2069 🏁 Script executed: #!/bin/bash
# 查看已知问题位置 settings.tsx 附近的代码
fd -e tsx -e ts | xargs grep -l 'saveSettingToSever' | head -5Repository: mineadmin/MineAdmin Length of output: 229
在 对比
建议修改 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议补充保存失败兜底,避免“本地已切换但服务端未持久化”无提示。
当前先更新本地语言再请求保存;若请求失败,用户侧没有明确反馈,后续刷新可能回退语言,体验上会像“切换失效”。建议在这里捕获异常并提示失败(必要时可按产品策略回滚本地状态)。
💡 建议修改
async function changeLanguage(item: { label: string, value: string }) { userStore.setLanguage(item.value) const appSettings = settingStore.getSettings('app') if (appSettings) { appSettings.useLocale = item.value } locale.value = item.value settingStore.setTitle(route.meta?.i18n ? t(route.meta?.i18n as string) : route.meta?.title as string) - await userStore.saveSettingToSever() + try { + await userStore.saveSettingToSever() + } + catch (error) { + // 按项目现有消息组件替换为对应提示 + console.error(error) + } }🤖 Prompt for AI Agents