Files
NotesAgentic/frontend/src/stores/layoutPreferences.ts
T
admin d703ab64e3
CI / docs-check (push) Canceled after 0s
CI / backend-test (push) Canceled after 0s
CI / service-test (push) Canceled after 0s
CI / frontend-test (push) Canceled after 0s
CI / rust-core (push) Canceled after 0s
CI / docs-check (pull_request) Canceled after 0s
CI / backend-test (pull_request) Canceled after 0s
CI / service-test (pull_request) Canceled after 0s
CI / frontend-test (pull_request) Canceled after 0s
CI / rust-core (pull_request) Canceled after 0s
docs: 将仓库代码注释统一为中文
2026-09-10 00:40:56 +08:00

22 lines
1.1 KiB
TypeScript

import { defineStore } from 'pinia'
import { ref, watch } from 'vue'
export const useLayoutPreferencesStore = defineStore('layoutPreferences', () => {
function stored(key: string) { try { return localStorage.getItem(key) } catch { return null } }
function width(key: string) {
const value = Number(stored(key))
return Number.isFinite(value) && value >= 200 ? Math.min(520, value) : 272
}
const primaryExpanded = ref(stored('primary-sidebar-expanded') === 'true')
const workspaceWidth = ref(width('workspace-sidebar-width'))
const chatWidth = ref(width('chat-sidebar-width'))
watch(() => [primaryExpanded.value, workspaceWidth.value, chatWidth.value], () => {
try {
localStorage.setItem('primary-sidebar-expanded', String(primaryExpanded.value))
localStorage.setItem('workspace-sidebar-width', String(workspaceWidth.value))
localStorage.setItem('chat-sidebar-width', String(chatWidth.value))
} catch { /* 当本地存储不可用时,保持当前布局可用。 */ }
}, { flush: 'sync' })
return { primaryExpanded, workspaceWidth, chatWidth }
})