|
1 | 1 | import { defineStore } from 'pinia'; |
2 | | -import { ref } from 'vue'; |
| 2 | +import { useLocalStorage } from '@vueuse/core'; |
3 | 3 |
|
4 | 4 | // 侧边栏面板布局常量 |
5 | 5 | export const PANEL_MIN_WIDTH = 150; |
6 | 6 | export const PANEL_MAX_WIDTH = 600; |
| 7 | +const LEGACY_UI_SETTINGS_STORAGE_KEY = 'freecell-log-studio.ui-settings'; |
| 8 | + |
| 9 | +interface StoredUiSettings { |
| 10 | + showTime?: boolean; |
| 11 | + showAccount?: boolean; |
| 12 | +} |
| 13 | + |
| 14 | +function readLegacyUiSettings(): StoredUiSettings { |
| 15 | + try { |
| 16 | + const raw = localStorage.getItem(LEGACY_UI_SETTINGS_STORAGE_KEY); |
| 17 | + if (!raw) { |
| 18 | + return {}; |
| 19 | + } |
| 20 | + |
| 21 | + const parsed = JSON.parse(raw) as unknown; |
| 22 | + if (typeof parsed !== 'object' || parsed === null) { |
| 23 | + return {}; |
| 24 | + } |
| 25 | + |
| 26 | + return { |
| 27 | + showTime: |
| 28 | + typeof (parsed as StoredUiSettings).showTime === 'boolean' |
| 29 | + ? (parsed as StoredUiSettings).showTime |
| 30 | + : undefined, |
| 31 | + showAccount: |
| 32 | + typeof (parsed as StoredUiSettings).showAccount === 'boolean' |
| 33 | + ? (parsed as StoredUiSettings).showAccount |
| 34 | + : undefined, |
| 35 | + }; |
| 36 | + } catch { |
| 37 | + return {}; |
| 38 | + } |
| 39 | +} |
7 | 40 |
|
8 | 41 | function uiStore() { |
9 | | - const leftPanelWidth = ref(232); |
10 | | - const rightPanelWidth = ref(280); |
| 42 | + const legacyUiSettings = readLegacyUiSettings(); |
| 43 | + const leftPanelWidth = useLocalStorage( |
| 44 | + 'freecell-log-studio.ui.leftPanelWidth', |
| 45 | + 232, |
| 46 | + ); |
| 47 | + const rightPanelWidth = useLocalStorage( |
| 48 | + 'freecell-log-studio.ui.rightPanelWidth', |
| 49 | + 280, |
| 50 | + ); |
| 51 | + const showTime = useLocalStorage( |
| 52 | + 'freecell-log-studio.ui.showTime', |
| 53 | + legacyUiSettings.showTime ?? true, |
| 54 | + ); |
| 55 | + const showAccount = useLocalStorage( |
| 56 | + 'freecell-log-studio.ui.showAccount', |
| 57 | + legacyUiSettings.showAccount ?? true, |
| 58 | + ); |
11 | 59 | // 深色模式 |
12 | | - const isDarkMode = ref(detectSystemDark()); |
13 | | - const followSystem = ref(true); |
| 60 | + const isDarkMode = useLocalStorage( |
| 61 | + 'freecell-log-studio.ui.isDarkMode', |
| 62 | + detectSystemDark(), |
| 63 | + ); |
| 64 | + const followSystem = useLocalStorage( |
| 65 | + 'freecell-log-studio.ui.followSystem', |
| 66 | + true, |
| 67 | + ); |
14 | 68 |
|
15 | 69 | function detectSystemDark() { |
16 | 70 | return ( |
@@ -44,19 +98,27 @@ function uiStore() { |
44 | 98 | } |
45 | 99 | } |
46 | 100 | // 显示隐藏消息 |
47 | | - const showHidden = ref(false); |
| 101 | + const showHidden = useLocalStorage( |
| 102 | + 'freecell-log-studio.ui.showHidden', |
| 103 | + false, |
| 104 | + ); |
48 | 105 | function toggleShowHidden() { |
49 | 106 | showHidden.value = !showHidden.value; |
50 | 107 | } |
51 | 108 |
|
52 | | - const exportPreviewAlwaysWhite = ref(false); |
| 109 | + const exportPreviewAlwaysWhite = useLocalStorage( |
| 110 | + 'freecell-log-studio.ui.exportPreviewAlwaysWhite', |
| 111 | + false, |
| 112 | + ); |
53 | 113 | function toggleExportPreviewAlwaysWhite() { |
54 | 114 | exportPreviewAlwaysWhite.value = !exportPreviewAlwaysWhite.value; |
55 | 115 | } |
56 | 116 |
|
57 | 117 | return { |
58 | 118 | leftPanelWidth, |
59 | 119 | rightPanelWidth, |
| 120 | + showTime, |
| 121 | + showAccount, |
60 | 122 | exportPreviewAlwaysWhite, |
61 | 123 | isDarkMode, |
62 | 124 | followSystem, |
|
0 commit comments