From 96694604ecd399aeca6fbd74b181877cda87abd8 Mon Sep 17 00:00:00 2001 From: fly6516 Date: Sat, 17 May 2025 09:49:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(store):=20=E9=87=8D=E6=9E=84=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E9=85=8D=E7=BD=AE=E7=8A=B6=E6=80=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=B9=B6=E6=B7=BB=E5=8A=A0=E6=8C=81=E4=B9=85=E5=8C=96?= =?UTF-8?q?=E6=94=AF=E6=8C=81-=20=E9=87=8D=E6=9E=84=20useEditorConfigStore?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E5=AE=8C=E6=95=B4=E7=9A=84=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E9=85=8D=E7=BD=AE=E7=8A=B6=E6=80=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86=20-=20=E6=B7=BB=E5=8A=A0=20setConfig=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=BB=A5=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE=20-=20?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=85=8D=E7=BD=AE=E7=9A=84=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=8C=81=E4=B9=85=E5=8C=96=20-=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20EditorConfigPanel=20=E7=BB=84=E4=BB=B6=E4=BB=A5?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84=E7=8A=B6=E6=80=81=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/editor-config-panel.tsx | 14 +++++++------ src/lib/store.ts | 27 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/components/editor-config-panel.tsx b/src/components/editor-config-panel.tsx index 2b7a535..651f542 100644 --- a/src/components/editor-config-panel.tsx +++ b/src/components/editor-config-panel.tsx @@ -1,19 +1,21 @@ -import React from 'react'; +"use client" + +import { useState } from 'react'; import { useEditorConfigStore } from '@/lib/store'; -export const EditorConfigPanel = () => { - const { config, updateConfig } = useEditorConfigStore(); +export function EditorConfigPanel() { + const { config, setConfig } = useEditorConfigStore(); const handleFontFamilyChange = (e: React.ChangeEvent) => { - updateConfig({ fontFamily: e.target.value }); + setConfig({ fontFamily: e.target.value }); }; const handleFontSizeChange = (e: React.ChangeEvent) => { - updateConfig({ fontSize: parseInt(e.target.value) }); + setConfig({ fontSize: parseInt(e.target.value) }); }; const handleLineHeightChange = (e: React.ChangeEvent) => { - updateConfig({ lineHeight: parseInt(e.target.value) }); + setConfig({ lineHeight: parseInt(e.target.value) }); }; const handleReset = () => { diff --git a/src/lib/store.ts b/src/lib/store.ts index f090145..e5b8efe 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -34,4 +34,29 @@ export const useEditorConfigStore = create((set) => { return { config: state.defaultConfig }; }), }; -}); \ No newline at end of file +}); + +export interface EditorConfigState { + config: any; + setConfig: (config: any) => void; +} + +export const useEditorConfigStore = create((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 }); + } + }; +});