Skip to content

Commit e3a17da

Browse files
committed
refactor: 将 styleStore 中仅影响 ui 显示的字段移到 uiStore
- 将 showTime/showAccount 字段从 ViewSetting 迁移到 uiStore - 为 uiStore 做了 localStorage 持久化 - 对旧版本的 project 做了兼容性处理
1 parent 3992726 commit e3a17da

6 files changed

Lines changed: 75 additions & 29 deletions

File tree

src/components/common/MessageItem.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151
<span class="message-name" :style="computedStyles.nameStyle">
5252
{{ message.playerName }}
5353
<span
54-
v-if="styleStore.viewSettings.showAccount"
54+
v-if="uiStore.showAccount"
5555
class="message-account"
5656
>
5757
({{ message.account }})
5858
</span>
5959
</span>
6060

61-
<span class="message-time" v-if="styleStore.viewSettings.showTime">
61+
<span class="message-time" v-if="uiStore.showTime">
6262
{{ formatDate(message.time) }}
6363
</span>
6464
</div>
@@ -90,6 +90,7 @@ import { computed, ref, nextTick, watch } from 'vue';
9090
import type { Message } from '@/types/log';
9191
import { onClickOutside } from '@vueuse/core';
9292
import { useStyleStore } from '@/stores/styleStore';
93+
import { useUiStore } from '@/stores/uiStore';
9394
import { formatDate } from '@/utils/date';
9495
import { computeStyleForMessage } from '@/editor/styleEngine';
9596
import { Trash2, Plus, Scissors, ChevronsDown } from '@lucide/vue';
@@ -129,6 +130,7 @@ const emit = defineEmits<{
129130
}>();
130131
131132
const styleStore = useStyleStore();
133+
const uiStore = useUiStore();
132134
133135
const computedStyles = computed(function () {
134136
return computeStyleForMessage(props.message, styleStore.activeRules);

src/components/layout/SidebarLeft.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@
110110
<label class="setting-item">
111111
<input
112112
type="checkbox"
113-
v-model="styleStore.viewSettings.showTime"
113+
v-model="uiStore.showTime"
114114
/>
115115
<span>显示消息时间</span>
116116
</label>
117117
<label class="setting-item">
118118
<input
119119
type="checkbox"
120-
v-model="styleStore.viewSettings.showAccount"
120+
v-model="uiStore.showAccount"
121121
/>
122122
<span>显示帐号</span>
123123
</label>

src/io/localStorage/project.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ export function cloneRules(rules: ColorRule[]): ColorRule[] {
107107

108108
export function cloneViewSettings(viewSettings: ViewSettings): ViewSettings {
109109
return {
110-
showTime: viewSettings.showTime,
111-
showAccount: viewSettings.showAccount,
112110
hideOoc: viewSettings.hideOoc,
113111
hideCommand: viewSettings.hideCommand,
114112
enableMarkdown: viewSettings.enableMarkdown,
@@ -358,8 +356,6 @@ function normalizeRules(rawRules: unknown): ColorRule[] {
358356

359357
function normalizeViewSettings(rawViewSettings: unknown): ViewSettings {
360358
const defaults: ViewSettings = {
361-
showTime: true,
362-
showAccount: true,
363359
hideOoc: false,
364360
hideCommand: false,
365361
enableMarkdown: false,
@@ -371,14 +367,6 @@ function normalizeViewSettings(rawViewSettings: unknown): ViewSettings {
371367
}
372368

373369
return {
374-
showTime:
375-
typeof rawViewSettings.showTime === 'boolean'
376-
? rawViewSettings.showTime
377-
: defaults.showTime,
378-
showAccount:
379-
typeof rawViewSettings.showAccount === 'boolean'
380-
? rawViewSettings.showAccount
381-
: defaults.showAccount,
382370
hideOoc:
383371
typeof rawViewSettings.hideOoc === 'boolean'
384372
? rawViewSettings.hideOoc

src/stores/styleStore.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { collectIdentityValues } from '@/editor/identity';
77

88
function ruleStore() {
99
const viewSettings = ref<ViewSettings>({
10-
showTime: true,
11-
showAccount: true,
1210
hideOoc: false,
1311
hideCommand: false,
1412
enableMarkdown: false,
@@ -202,8 +200,6 @@ function ruleStore() {
202200

203201
function replaceViewSettings(newSettings: ViewSettings) {
204202
viewSettings.value = {
205-
showTime: newSettings.showTime,
206-
showAccount: newSettings.showAccount,
207203
hideOoc: newSettings.hideOoc,
208204
hideCommand: newSettings.hideCommand,
209205
enableMarkdown: newSettings.enableMarkdown,

src/stores/uiStore.ts

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,70 @@
11
import { defineStore } from 'pinia';
2-
import { ref } from 'vue';
2+
import { useLocalStorage } from '@vueuse/core';
33

44
// 侧边栏面板布局常量
55
export const PANEL_MIN_WIDTH = 150;
66
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+
}
740

841
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+
);
1159
// 深色模式
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+
);
1468

1569
function detectSystemDark() {
1670
return (
@@ -44,19 +98,27 @@ function uiStore() {
4498
}
4599
}
46100
// 显示隐藏消息
47-
const showHidden = ref(false);
101+
const showHidden = useLocalStorage(
102+
'freecell-log-studio.ui.showHidden',
103+
false,
104+
);
48105
function toggleShowHidden() {
49106
showHidden.value = !showHidden.value;
50107
}
51108

52-
const exportPreviewAlwaysWhite = ref(false);
109+
const exportPreviewAlwaysWhite = useLocalStorage(
110+
'freecell-log-studio.ui.exportPreviewAlwaysWhite',
111+
false,
112+
);
53113
function toggleExportPreviewAlwaysWhite() {
54114
exportPreviewAlwaysWhite.value = !exportPreviewAlwaysWhite.value;
55115
}
56116

57117
return {
58118
leftPanelWidth,
59119
rightPanelWidth,
120+
showTime,
121+
showAccount,
60122
exportPreviewAlwaysWhite,
61123
isDarkMode,
62124
followSystem,

src/types/style.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export interface ColorRule {
1616
}
1717

1818
export interface ViewSettings {
19-
showTime: boolean;
20-
showAccount: boolean;
2119
hideOoc: boolean;
2220
hideCommand: boolean;
2321
enableMarkdown: boolean;

0 commit comments

Comments
 (0)