优化模版样式
This commit is contained in:
parent
54ea0b97a9
commit
a21bde97f9
@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
@ -33,6 +33,11 @@ export function StyleConfigDialog({ value, onChangeAction }: StyleConfigDialogPr
|
|||||||
const [currentOptions, setCurrentOptions] = useState<RendererOptions>(value)
|
const [currentOptions, setCurrentOptions] = useState<RendererOptions>(value)
|
||||||
const [customizedFields, setCustomizedFields] = useState<Set<string>>(new Set())
|
const [customizedFields, setCustomizedFields] = useState<Set<string>>(new Set())
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCurrentOptions(value)
|
||||||
|
setCustomizedFields(new Set())
|
||||||
|
}, [value])
|
||||||
|
|
||||||
const handleOptionChange = (
|
const handleOptionChange = (
|
||||||
category: keyof RendererOptions,
|
category: keyof RendererOptions,
|
||||||
subcategory: string,
|
subcategory: string,
|
||||||
|
@ -81,18 +81,27 @@ export default function WechatEditor() {
|
|||||||
block: {
|
block: {
|
||||||
...(template?.options?.block || {}),
|
...(template?.options?.block || {}),
|
||||||
...(styleOptions.block || {}),
|
...(styleOptions.block || {}),
|
||||||
// 确保标题使用主题颜色和正确的字体大小
|
// 合并标题样式,保留模版中的其他样式属性
|
||||||
h1: {
|
h1: {
|
||||||
fontSize: styleOptions.block?.h1?.fontSize || '24px',
|
...(template?.options?.block?.h1 || {}),
|
||||||
color: styleOptions.base?.themeColor || '#1a1a1a'
|
...(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: {
|
h2: {
|
||||||
fontSize: styleOptions.block?.h2?.fontSize || '20px',
|
...(template?.options?.block?.h2 || {}),
|
||||||
color: styleOptions.base?.themeColor || '#1a1a1a'
|
...(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: {
|
h3: {
|
||||||
fontSize: styleOptions.block?.h3?.fontSize || '18px',
|
...(template?.options?.block?.h3 || {}),
|
||||||
color: styleOptions.base?.themeColor || '#1a1a1a'
|
...(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: {
|
inline: {
|
||||||
@ -384,6 +393,13 @@ export default function WechatEditor() {
|
|||||||
})
|
})
|
||||||
}, [value, handleEditorChange])
|
}, [value, handleEditorChange])
|
||||||
|
|
||||||
|
// 处理模版选择
|
||||||
|
const handleTemplateSelect = useCallback((templateId: string) => {
|
||||||
|
setSelectedTemplate(templateId)
|
||||||
|
// 重置样式设置为模版默认值
|
||||||
|
setStyleOptions({})
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex flex-col">
|
<div className="h-full flex flex-col">
|
||||||
<div className="hidden sm:block">
|
<div className="hidden sm:block">
|
||||||
@ -397,7 +413,7 @@ export default function WechatEditor() {
|
|||||||
onCopyPreview={handleCopy}
|
onCopyPreview={handleCopy}
|
||||||
onNewArticle={handleNewArticle}
|
onNewArticle={handleNewArticle}
|
||||||
onArticleSelect={handleArticleSelect}
|
onArticleSelect={handleArticleSelect}
|
||||||
onTemplateSelect={setSelectedTemplate}
|
onTemplateSelect={handleTemplateSelect}
|
||||||
onTemplateChange={() => setValue(value)}
|
onTemplateChange={() => setValue(value)}
|
||||||
onStyleOptionsChange={setStyleOptions}
|
onStyleOptionsChange={setStyleOptions}
|
||||||
onPreviewToggle={() => setShowPreview(!showPreview)}
|
onPreviewToggle={() => setShowPreview(!showPreview)}
|
||||||
@ -412,7 +428,7 @@ export default function WechatEditor() {
|
|||||||
<div className="flex-1 mr-2">
|
<div className="flex-1 mr-2">
|
||||||
<WechatStylePicker
|
<WechatStylePicker
|
||||||
value={selectedTemplate}
|
value={selectedTemplate}
|
||||||
onSelect={setSelectedTemplate}
|
onSelect={handleTemplateSelect}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
@ -17,6 +17,7 @@ export const templates: Template[] = [
|
|||||||
styles: '',
|
styles: '',
|
||||||
options: {
|
options: {
|
||||||
base: {
|
base: {
|
||||||
|
themeColor: '#16a34a',
|
||||||
primaryColor: '#000000',
|
primaryColor: '#000000',
|
||||||
textAlign: 'left',
|
textAlign: 'left',
|
||||||
lineHeight: '1.75',
|
lineHeight: '1.75',
|
||||||
@ -44,7 +45,7 @@ export const templates: Template[] = [
|
|||||||
padding: '0 0.2em',
|
padding: '0 0.2em',
|
||||||
margin: '4em auto 2em',
|
margin: '4em auto 2em',
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
background: 'var(--md-primary-color)',
|
borderBottom: '2px solid var(--md-primary-color)',
|
||||||
fontSize: '1.2em',
|
fontSize: '1.2em',
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
textAlign: 'center'
|
textAlign: 'center'
|
||||||
@ -183,6 +184,7 @@ export const templates: Template[] = [
|
|||||||
styles: 'prose-elegant',
|
styles: 'prose-elegant',
|
||||||
options: {
|
options: {
|
||||||
base: {
|
base: {
|
||||||
|
themeColor: '#16a34a',
|
||||||
primaryColor: '#16a34a',
|
primaryColor: '#16a34a',
|
||||||
textAlign: 'justify',
|
textAlign: 'justify',
|
||||||
lineHeight: '1.8'
|
lineHeight: '1.8'
|
||||||
@ -198,15 +200,13 @@ export const templates: Template[] = [
|
|||||||
textAlign: 'center'
|
textAlign: 'center'
|
||||||
},
|
},
|
||||||
h2: {
|
h2: {
|
||||||
display: 'table',
|
display: 'table',
|
||||||
padding: '0.2em 1em',
|
padding: '0 1.5em',
|
||||||
margin: '4em auto 2em',
|
borderBottom: '2px solid #16a34a',
|
||||||
color: '#fff',
|
margin: '2.5em auto 1.2em',
|
||||||
background: '#16a34a',
|
fontSize: '1.4em',
|
||||||
fontSize: '1.2em',
|
fontWeight: 'bold',
|
||||||
fontWeight: 'bold',
|
textAlign: 'center'
|
||||||
textAlign: 'center',
|
|
||||||
borderRadius: '4px'
|
|
||||||
},
|
},
|
||||||
h3: {
|
h3: {
|
||||||
paddingLeft: '8px',
|
paddingLeft: '8px',
|
||||||
|
Loading…
Reference in New Issue
Block a user