refactor(store): 重构编辑器配置状态管理

- 移除了 useEditorConfigStore 的实现
- 修改了 resetConfig 的实现,使用 state.defaultConfig 作为默认配置- 重命名 EditorConfigState为 EditorConfigState2
This commit is contained in:
fly6516 2025-05-17 09:57:55 +08:00
parent 96694604ec
commit 2ca98cccfb

View File

@ -32,31 +32,11 @@ export const useEditorConfigStore = create<EditorConfigState>((set) => {
resetConfig: () => set((state) => {
localStorage.removeItem('editorConfig');
return { config: state.defaultConfig };
}),
})
};
});
export interface EditorConfigState {
interface EditorConfigState2 {
config: any;
setConfig: (config: any) => void;
}
export const useEditorConfigStore = create<EditorConfigState>((set) => {
// 从localStorage读取保存的配置
let savedConfig = null;
if (typeof window !== 'undefined') {
savedConfig = localStorage.getItem('editorConfig');
}
const parsedConfig = savedConfig ? JSON.parse(savedConfig) : {};
return {
config: parsedConfig,
setConfig: (config) => {
if (typeof window !== 'undefined') {
localStorage.setItem('editorConfig', JSON.stringify(config));
}
set({ config });
}
};
});