From a21bde97f93608b89967d838e2cde28b375c84e5 Mon Sep 17 00:00:00 2001 From: tianyaxiang Date: Sat, 1 Feb 2025 09:31:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E7=89=88=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/editor/StyleConfigDialog.tsx | 7 ++++- src/components/editor/WechatEditor.tsx | 34 +++++++++++++++------ src/config/wechat-templates.ts | 20 ++++++------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/components/editor/StyleConfigDialog.tsx b/src/components/editor/StyleConfigDialog.tsx index 05f84c5..592da7c 100644 --- a/src/components/editor/StyleConfigDialog.tsx +++ b/src/components/editor/StyleConfigDialog.tsx @@ -1,6 +1,6 @@ 'use client' -import { useState } from 'react' +import { useState, useEffect } from 'react' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog' import { Label } from '@/components/ui/label' import { Input } from '@/components/ui/input' @@ -33,6 +33,11 @@ export function StyleConfigDialog({ value, onChangeAction }: StyleConfigDialogPr const [currentOptions, setCurrentOptions] = useState(value) const [customizedFields, setCustomizedFields] = useState>(new Set()) + useEffect(() => { + setCurrentOptions(value) + setCustomizedFields(new Set()) + }, [value]) + const handleOptionChange = ( category: keyof RendererOptions, subcategory: string, diff --git a/src/components/editor/WechatEditor.tsx b/src/components/editor/WechatEditor.tsx index b0d1aa4..cf084b3 100644 --- a/src/components/editor/WechatEditor.tsx +++ b/src/components/editor/WechatEditor.tsx @@ -81,18 +81,27 @@ export default function WechatEditor() { block: { ...(template?.options?.block || {}), ...(styleOptions.block || {}), - // 确保标题使用主题颜色和正确的字体大小 + // 合并标题样式,保留模版中的其他样式属性 h1: { - fontSize: styleOptions.block?.h1?.fontSize || '24px', - color: styleOptions.base?.themeColor || '#1a1a1a' + ...(template?.options?.block?.h1 || {}), + ...(styleOptions.block?.h1 || {}), + fontSize: styleOptions.block?.h1?.fontSize || template?.options?.block?.h1?.fontSize || '24px', + color: styleOptions.base?.themeColor || template?.options?.base?.themeColor || '#1a1a1a', + borderBottom: `2px solid ${styleOptions.base?.themeColor || template?.options?.base?.themeColor || '#1a1a1a'}` }, h2: { - fontSize: styleOptions.block?.h2?.fontSize || '20px', - color: styleOptions.base?.themeColor || '#1a1a1a' + ...(template?.options?.block?.h2 || {}), + ...(styleOptions.block?.h2 || {}), + fontSize: styleOptions.block?.h2?.fontSize || template?.options?.block?.h2?.fontSize || '20px', + color: styleOptions.base?.themeColor || template?.options?.base?.themeColor || '#1a1a1a', + borderBottom: `2px solid ${styleOptions.base?.themeColor || template?.options?.base?.themeColor || '#1a1a1a'}` }, h3: { - fontSize: styleOptions.block?.h3?.fontSize || '18px', - color: styleOptions.base?.themeColor || '#1a1a1a' + ...(template?.options?.block?.h3 || {}), + ...(styleOptions.block?.h3 || {}), + fontSize: styleOptions.block?.h3?.fontSize || template?.options?.block?.h3?.fontSize || '18px', + color: styleOptions.base?.themeColor || template?.options?.base?.themeColor || '#1a1a1a', + borderLeft: `3px solid ${styleOptions.base?.themeColor || template?.options?.base?.themeColor || '#1a1a1a'}` } }, inline: { @@ -384,6 +393,13 @@ export default function WechatEditor() { }) }, [value, handleEditorChange]) + // 处理模版选择 + const handleTemplateSelect = useCallback((templateId: string) => { + setSelectedTemplate(templateId) + // 重置样式设置为模版默认值 + setStyleOptions({}) + }, []) + return (
@@ -397,7 +413,7 @@ export default function WechatEditor() { onCopyPreview={handleCopy} onNewArticle={handleNewArticle} onArticleSelect={handleArticleSelect} - onTemplateSelect={setSelectedTemplate} + onTemplateSelect={handleTemplateSelect} onTemplateChange={() => setValue(value)} onStyleOptionsChange={setStyleOptions} onPreviewToggle={() => setShowPreview(!showPreview)} @@ -412,7 +428,7 @@ export default function WechatEditor() {