feat: 主题色支持多色

This commit is contained in:
zxc 2025-03-14 16:30:10 +08:00
parent bccb23c559
commit 373426bfad
10 changed files with 27 additions and 27 deletions

View File

@ -96,7 +96,7 @@ export default () => {
width: 400, width: 400,
height: 400, height: 400,
rotate: 0, rotate: 0,
themeColors: [theme.value.themeColor], themeColors: theme.value.themeColors,
textColor: theme.value.fontColor, textColor: theme.value.fontColor,
data: CHART_DEFAULT_DATA[type], data: CHART_DEFAULT_DATA[type],
}) })
@ -145,7 +145,7 @@ export default () => {
color: '#eeece1', color: '#eeece1',
}, },
theme: { theme: {
color: theme.value.themeColor, color: theme.value.themeColors[0],
rowHeader: true, rowHeader: true,
rowFooter: false, rowFooter: false,
colHeader: false, colHeader: false,
@ -202,7 +202,7 @@ export default () => {
height, height,
viewBox: data.viewBox, viewBox: data.viewBox,
path: data.path, path: data.path,
fill: theme.value.themeColor, fill: theme.value.themeColors[0],
fixedRatio: false, fixedRatio: false,
rotate: 0, rotate: 0,
...supplement, ...supplement,
@ -239,7 +239,7 @@ export default () => {
start, start,
end, end,
points: data.points, points: data.points,
color: theme.value.themeColor, color: theme.value.themeColors[0],
style: data.style, style: data.style,
width: 2, width: 2,
} }
@ -306,7 +306,7 @@ export default () => {
loop: false, loop: false,
autoplay: false, autoplay: false,
fixedRatio: true, fixedRatio: true,
color: theme.value.themeColor, color: theme.value.themeColors[0],
src, src,
}) })
} }

View File

@ -267,7 +267,7 @@ export default () => {
top: el.top, top: el.top,
rotate: 0, rotate: 0,
fixedRatio: false, fixedRatio: false,
color: theme.value.themeColor, color: theme.value.themeColors[0],
loop: false, loop: false,
autoplay: false, autoplay: false,
}) })
@ -504,7 +504,7 @@ export default () => {
left: el.left, left: el.left,
top: el.top, top: el.top,
rotate: 0, rotate: 0,
themeColors: el.colors.length ? el.colors : [theme.value.themeColor], themeColors: el.colors.length ? el.colors : theme.value.themeColors,
textColor: theme.value.fontColor, textColor: theme.value.fontColor,
data: { data: {
labels, labels,

View File

@ -311,7 +311,7 @@ export default () => {
} }
slidesStore.setTheme({ slidesStore.setTheme({
backgroundColor: theme.background, backgroundColor: theme.background,
themeColor: theme.colors[0], themeColors: theme.colors,
fontColor: theme.fontColor, fontColor: theme.fontColor,
fontName: theme.fontname, fontName: theme.fontname,
}) })
@ -322,7 +322,7 @@ export default () => {
// 将当前主题配置应用到全部页面 // 将当前主题配置应用到全部页面
const applyThemeToAllSlides = (applyAll = false) => { const applyThemeToAllSlides = (applyAll = false) => {
const newSlides: Slide[] = JSON.parse(JSON.stringify(slides.value)) const newSlides: Slide[] = JSON.parse(JSON.stringify(slides.value))
const { themeColor, backgroundColor, fontColor, fontName, outline, shadow } = theme.value const { themeColors, backgroundColor, fontColor, fontName, outline, shadow } = theme.value
for (const slide of newSlides) { for (const slide of newSlides) {
if (!slide.background || slide.background.type !== 'image') { if (!slide.background || slide.background.type !== 'image') {
@ -339,17 +339,17 @@ export default () => {
} }
if (el.type === 'shape') { if (el.type === 'shape') {
el.fill = themeColor el.fill = themeColors[0]
if (el.gradient) delete el.gradient if (el.gradient) delete el.gradient
} }
else if (el.type === 'line') el.color = themeColor else if (el.type === 'line') el.color = themeColors[0]
else if (el.type === 'text') { else if (el.type === 'text') {
el.defaultColor = fontColor el.defaultColor = fontColor
el.defaultFontName = fontName el.defaultFontName = fontName
if (el.fill) el.fill = themeColor if (el.fill) el.fill = themeColors[0]
} }
else if (el.type === 'table') { else if (el.type === 'table') {
if (el.theme) el.theme.color = themeColor if (el.theme) el.theme.color = themeColors[0]
for (const rowCells of el.data) { for (const rowCells of el.data) {
for (const cell of rowCells) { for (const cell of rowCells) {
if (cell.style) { if (cell.style) {
@ -360,11 +360,11 @@ export default () => {
} }
} }
else if (el.type === 'chart') { else if (el.type === 'chart') {
el.themeColors = [themeColor] el.themeColors = themeColors
el.textColor = fontColor el.textColor = fontColor
} }
else if (el.type === 'latex') el.color = fontColor else if (el.type === 'latex') el.color = fontColor
else if (el.type === 'audio') el.color = themeColor else if (el.type === 'audio') el.color = themeColors[0]
} }
} }
slidesStore.setSlides(newSlides) slidesStore.setSlides(newSlides)

View File

@ -32,7 +32,7 @@ export const useSlidesStore = defineStore('slides', {
state: (): SlidesState => ({ state: (): SlidesState => ({
title: '未命名演示文稿', // 幻灯片标题 title: '未命名演示文稿', // 幻灯片标题
theme: { theme: {
themeColor: '#5b9bd5', themeColors: ['#5b9bd5', '#ed7d31', '#a5a5a5', '#ffc000', '#4472c4', '#70ad47'],
fontColor: '#333', fontColor: '#333',
fontName: '', fontName: '',
backgroundColor: '#fff', backgroundColor: '#fff',

View File

@ -754,7 +754,7 @@ export interface Slide {
*/ */
export interface SlideTheme { export interface SlideTheme {
backgroundColor: string backgroundColor: string
themeColor: string themeColors: string[]
fontColor: string fontColor: string
fontName: string fontName: string
outline: PPTElementOutline outline: PPTElementOutline

View File

@ -152,7 +152,7 @@ const create = () => {
fill: 'rgba(0, 0, 0, 0)', fill: 'rgba(0, 0, 0, 0)',
outline: { outline: {
width: 2, width: 2,
color: theme.value.themeColor, color: theme.value.themeColors[0],
style: 'solid', style: 'solid',
}, },
}) })

View File

@ -213,7 +213,7 @@ const updateTheme = (color: string, index: number) => {
// //
const addThemeColor = () => { const addThemeColor = () => {
const props = { const props = {
themeColors: [...themeColors.value, theme.value.themeColor], themeColors: [...themeColors.value, theme.value.themeColors[0]],
} }
updateElement(props) updateElement(props)
} }

View File

@ -196,7 +196,7 @@ import Popover from '@/components/Popover.vue'
const slidesStore = useSlidesStore() const slidesStore = useSlidesStore()
const { handleElement, handleElementId, selectedTableCells: selectedCells } = storeToRefs(useMainStore()) const { handleElement, handleElementId, selectedTableCells: selectedCells } = storeToRefs(useMainStore())
const themeColor = computed(() => slidesStore.theme.themeColor) const themeColor = computed(() => slidesStore.theme.themeColors[0])
const fontSizeOptions = [ const fontSizeOptions = [
'12px', '14px', '16px', '18px', '20px', '22px', '24px', '28px', '32px', '12px', '14px', '16px', '18px', '20px', '22px', '24px', '28px', '32px',

View File

@ -162,18 +162,18 @@
<ColorButton :color="theme.backgroundColor" /> <ColorButton :color="theme.backgroundColor" />
</Popover> </Popover>
</div> </div>
<div class="row"> <!-- <div class="row">
<div style="width: 40%;">主题色</div> <div style="width: 40%;">主题色</div>
<Popover trigger="click" style="width: 60%;"> <Popover trigger="click" style="width: 60%;">
<template #content> <template #content>
<ColorPicker <ColorPicker
:modelValue="theme.themeColor" :modelValue="theme.themeColors[0]"
@update:modelValue="value => updateTheme({ themeColor: value })" @update:modelValue="value => updateTheme({ themeColors: value })"
/> />
</template> </template>
<ColorButton :color="theme.themeColor" /> <ColorButton :color="theme.themeColors[0]" />
</Popover> </Popover>
</div> </div> -->
<template v-if="moreThemeConfigsVisible"> <template v-if="moreThemeConfigsVisible">
<div class="row"> <div class="row">

View File

@ -54,7 +54,7 @@
<div class="handler"> <div class="handler">
<div class="state" :class="{ 'active': selectedIndex.themeColor === index }"></div> <div class="state" :class="{ 'active': selectedIndex.themeColor === index }"></div>
<div class="config-btn" @click="selectedIndex.themeColor = index">选择</div> <div class="config-btn" @click="selectedIndex.themeColor = index">选择</div>
<div class="config-btn" @click="updateTheme({ themeColor: item }); selectedIndex.themeColor = index">配置到主题</div> <!-- <div class="config-btn" @click="updateTheme({ themeColor: item }); selectedIndex.themeColor = index">配置到主题</div> -->
</div> </div>
</div> </div>
</div> </div>
@ -133,7 +133,7 @@ const updateTheme = (themeProps: Partial<SlideTheme>) => {
const updateAllThemes = () => { const updateAllThemes = () => {
slidesStore.setTheme({ slidesStore.setTheme({
backgroundColor: themeStyles.value.backgroundColors[selectedIndex.value.backgroundColor], backgroundColor: themeStyles.value.backgroundColors[selectedIndex.value.backgroundColor],
themeColor: themeStyles.value.themeColors[selectedIndex.value.themeColor], themeColors: themeStyles.value.themeColors,
fontColor: themeStyles.value.fontColors[selectedIndex.value.fontColor], fontColor: themeStyles.value.fontColors[selectedIndex.value.fontColor],
fontName: themeStyles.value.fontNames[selectedIndex.value.fontName], fontName: themeStyles.value.fontNames[selectedIndex.value.fontName],
}) })