feat(frontend): add font size, namespace UI prefs per user

Build on the font picker with three additions per user feedback:

- Font size selector (Small / Normal / Large) wired through a new
  --app-font-scale CSS variable; the body font-size and every
  --td-font-size-* token are wrapped in calc(... * var(--app-font-scale))
  so TDesign components scale together with the body
- localStorage keys for theme, font family, mono font and font size are
  now namespaced as WeKnora_${userId}_${key}; falls back to "anon" before
  login. Each user keeps their own preferences in the same browser
- auth store calls reloadFontFromStorage / reloadThemeFromStorage on
  setUser (when the active user changes) and in logout, so a user switch
  swaps the applied preferences without a reload

https://claude.ai/code/session_01S1FVPf4jRfWXkTSnpMmMp7
This commit is contained in:
Claude
2026-05-02 08:21:37 +00:00
committed by lyingbug
parent f140c12518
commit bafcbd5e5f
10 changed files with 190 additions and 34 deletions
+14
View File
@@ -3,6 +3,15 @@ import { ref, computed } from 'vue'
import type { UserInfo, TenantInfo, KnowledgeBaseInfo } from '@/api/auth'
import type { TenantInfo as TenantInfoFromAPI } from '@/api/tenant'
import i18n from '@/i18n'
import { reloadFontFromStorage } from '@/composables/useFont'
import { reloadThemeFromStorage } from '@/composables/useTheme'
// Per-user UI preferences are namespaced by user id in localStorage.
// Reload them whenever the active user changes.
function reloadUserPreferences() {
reloadFontFromStorage()
reloadThemeFromStorage()
}
export const useAuthStore = defineStore('auth', () => {
// 状态
@@ -45,9 +54,13 @@ export const useAuthStore = defineStore('auth', () => {
// 操作方法
const setUser = (userData: UserInfo) => {
const previousId = user.value?.id
user.value = userData
// 保存到localStorage
localStorage.setItem('weknora_user', JSON.stringify(userData))
if (previousId !== userData.id) {
reloadUserPreferences()
}
}
const setTenant = (tenantData: TenantInfo) => {
@@ -140,6 +153,7 @@ export const useAuthStore = defineStore('auth', () => {
} catch {
/* ignore */
}
reloadUserPreferences()
}
const initFromStorage = () => {