mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
新增背景渐变填充功能
This commit is contained in:
parent
96e811d502
commit
d06c1068b1
@ -10,6 +10,9 @@ export default (background: Ref<SlideBackground | undefined>) => {
|
|||||||
color,
|
color,
|
||||||
image,
|
image,
|
||||||
imageSize,
|
imageSize,
|
||||||
|
gradientColor,
|
||||||
|
gradientRotate,
|
||||||
|
gradientType,
|
||||||
} = background.value
|
} = background.value
|
||||||
|
|
||||||
if(type === 'solid') return { backgroundColor: color }
|
if(type === 'solid') return { backgroundColor: color }
|
||||||
@ -25,9 +28,17 @@ export default (background: Ref<SlideBackground | undefined>) => {
|
|||||||
return {
|
return {
|
||||||
backgroundImage: `url(${image}`,
|
backgroundImage: `url(${image}`,
|
||||||
backgroundRepeat: 'no-repeat',
|
backgroundRepeat: 'no-repeat',
|
||||||
backgroundSize: imageSize,
|
backgroundSize: imageSize || 'cover',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(type === 'gradient') {
|
||||||
|
const rotate = gradientRotate || 0
|
||||||
|
const color1 = gradientColor ? gradientColor[0] : '#fff'
|
||||||
|
const color2 = gradientColor ? gradientColor[1] : '#fff'
|
||||||
|
|
||||||
|
if(gradientType === 'radial') return { backgroundImage: `radial-gradient(${color1}, ${color2}` }
|
||||||
|
return { backgroundImage: `linear-gradient(${rotate}deg, ${color1}, ${color2}` }
|
||||||
|
}
|
||||||
|
|
||||||
return { backgroundColor: '#fff' }
|
return { backgroundColor: '#fff' }
|
||||||
})
|
})
|
||||||
|
@ -73,7 +73,7 @@ export interface PPTImageElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ShapeGradient {
|
export interface ShapeGradient {
|
||||||
type: 'line' | 'radial';
|
type: 'linear' | 'radial';
|
||||||
color: [string, string];
|
color: [string, string];
|
||||||
rotate: number;
|
rotate: number;
|
||||||
}
|
}
|
||||||
@ -167,10 +167,13 @@ export interface PPTAnimation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface SlideBackground {
|
export interface SlideBackground {
|
||||||
type: 'solid' | 'image';
|
type: 'solid' | 'image' | 'gradient';
|
||||||
color?: string;
|
color?: string;
|
||||||
image?: string;
|
image?: string;
|
||||||
imageSize?: 'cover' | 'contain' | 'repeat' | 'initial';
|
imageSize?: 'cover' | 'contain' | 'repeat' | 'initial';
|
||||||
|
gradientType?: 'linear' | 'radial';
|
||||||
|
gradientColor?: [string, string];
|
||||||
|
gradientRotate?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Slide {
|
export interface Slide {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
@change="value => updateGradient({ type: value })"
|
@change="value => updateGradient({ type: value })"
|
||||||
v-else
|
v-else
|
||||||
>
|
>
|
||||||
<SelectOption value="line">线性渐变</SelectOption>
|
<SelectOption value="linear">线性渐变</SelectOption>
|
||||||
<SelectOption value="radial">径向渐变</SelectOption>
|
<SelectOption value="radial">径向渐变</SelectOption>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
@ -55,7 +55,7 @@
|
|||||||
<ColorButton :color="gradient.color[1]" style="flex: 3;" />
|
<ColorButton :color="gradient.color[1]" style="flex: 3;" />
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
<div class="row" v-if="gradient.type === 'line'">
|
<div class="row" v-if="gradient.type === 'linear'">
|
||||||
<div style="flex: 2;">渐变角度:</div>
|
<div style="flex: 2;">渐变角度:</div>
|
||||||
<Slider
|
<Slider
|
||||||
:min="0"
|
:min="0"
|
||||||
@ -109,7 +109,7 @@ export default defineComponent({
|
|||||||
if(!handleElement.value) return
|
if(!handleElement.value) return
|
||||||
fill.value = handleElement.value.fill || '#000'
|
fill.value = handleElement.value.fill || '#000'
|
||||||
|
|
||||||
gradient.value = handleElement.value.gradient || { type: 'line', rotate: 0, color: [fill.value, '#fff'] }
|
gradient.value = handleElement.value.gradient || { type: 'linear', rotate: 0, color: [fill.value, '#fff'] }
|
||||||
|
|
||||||
fillType.value = handleElement.value.gradient ? 'gradient' : 'fill'
|
fillType.value = handleElement.value.gradient ? 'gradient' : 'fill'
|
||||||
}, { deep: true, immediate: true })
|
}, { deep: true, immediate: true })
|
||||||
|
@ -9,8 +9,10 @@
|
|||||||
>
|
>
|
||||||
<SelectOption value="solid">纯色填充</SelectOption>
|
<SelectOption value="solid">纯色填充</SelectOption>
|
||||||
<SelectOption value="image">图片填充</SelectOption>
|
<SelectOption value="image">图片填充</SelectOption>
|
||||||
|
<SelectOption value="gradient">渐变填充</SelectOption>
|
||||||
</Select>
|
</Select>
|
||||||
<div style="flex: 1;"></div>
|
<div style="flex: 1;"></div>
|
||||||
|
|
||||||
<Popover trigger="click" v-if="background.type === 'solid'">
|
<Popover trigger="click" v-if="background.type === 'solid'">
|
||||||
<template #content>
|
<template #content>
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
@ -20,18 +22,30 @@
|
|||||||
</template>
|
</template>
|
||||||
<ColorButton :color="background.color || '#fff'" style="flex: 10;" />
|
<ColorButton :color="background.color || '#fff'" style="flex: 10;" />
|
||||||
</Popover>
|
</Popover>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
style="flex: 10;"
|
style="flex: 10;"
|
||||||
:value="background.size || 'cover'"
|
:value="background.size || 'cover'"
|
||||||
@change="value => updateBackground({ imageSize: value })"
|
@change="value => updateBackground({ imageSize: value })"
|
||||||
v-else
|
v-else-if="background.type === 'image'"
|
||||||
>
|
>
|
||||||
<SelectOption value="initial">原始大小</SelectOption>
|
<SelectOption value="initial">原始大小</SelectOption>
|
||||||
<SelectOption value="contain">缩放</SelectOption>
|
<SelectOption value="contain">缩放</SelectOption>
|
||||||
<SelectOption value="repeat">拼贴</SelectOption>
|
<SelectOption value="repeat">拼贴</SelectOption>
|
||||||
<SelectOption value="cover">缩放铺满</SelectOption>
|
<SelectOption value="cover">缩放铺满</SelectOption>
|
||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
|
<Select
|
||||||
|
style="flex: 10;"
|
||||||
|
:value="background.gradientType"
|
||||||
|
@change="value => updateBackground({ gradientType: value })"
|
||||||
|
v-else
|
||||||
|
>
|
||||||
|
<SelectOption value="linear">线性渐变</SelectOption>
|
||||||
|
<SelectOption value="radial">径向渐变</SelectOption>
|
||||||
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="background-image-wrapper" v-if="background.type === 'image'">
|
<div class="background-image-wrapper" v-if="background.type === 'image'">
|
||||||
<FileInput @change="files => uploadBackgroundImage(files)">
|
<FileInput @change="files => uploadBackgroundImage(files)">
|
||||||
<div class="background-image">
|
<div class="background-image">
|
||||||
@ -41,6 +55,45 @@
|
|||||||
</div>
|
</div>
|
||||||
</FileInput>
|
</FileInput>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="background-gradient-wrapper" v-if="background.type === 'gradient'">
|
||||||
|
<div class="row">
|
||||||
|
<div style="flex: 2;">起点颜色:</div>
|
||||||
|
<Popover trigger="click">
|
||||||
|
<template #content>
|
||||||
|
<ColorPicker
|
||||||
|
:modelValue="background.gradientColor[0]"
|
||||||
|
@update:modelValue="value => updateBackground({ gradientColor: [value, background.gradientColor[1]] })"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<ColorButton :color="background.gradientColor[0]" style="flex: 3;" />
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div style="flex: 2;">终点颜色:</div>
|
||||||
|
<Popover trigger="click">
|
||||||
|
<template #content>
|
||||||
|
<ColorPicker
|
||||||
|
:modelValue="background.gradientColor[1]"
|
||||||
|
@update:modelValue="value => updateBackground({ gradientColor: [background.gradientColor[0], value] })"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
<ColorButton :color="background.gradientColor[1]" style="flex: 3;" />
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
<div class="row" v-if="background.gradientType === 'linear'">
|
||||||
|
<div style="flex: 2;">渐变角度:</div>
|
||||||
|
<Slider
|
||||||
|
:min="0"
|
||||||
|
:max="360"
|
||||||
|
:step="15"
|
||||||
|
:value="background.gradientRotate"
|
||||||
|
style="flex: 3;"
|
||||||
|
@change="value => updateBackground({ gradientRotate: value })"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row"><Button style="flex: 1;" @click="applyAllSlide()">应用到全部</Button></div>
|
<div class="row"><Button style="flex: 1;" @click="applyAllSlide()">应用到全部</Button></div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -77,7 +130,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
const { addHistorySnapshot } = useHistorySnapshot()
|
const { addHistorySnapshot } = useHistorySnapshot()
|
||||||
|
|
||||||
const updateBackgroundType = (type: 'solid' | 'image') => {
|
const updateBackgroundType = (type: 'solid' | 'image' | 'gradient') => {
|
||||||
if(type === 'solid') {
|
if(type === 'solid') {
|
||||||
const newBackground: SlideBackground = {
|
const newBackground: SlideBackground = {
|
||||||
...background.value,
|
...background.value,
|
||||||
@ -86,7 +139,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
store.commit(MutationTypes.UPDATE_SLIDE, { background: newBackground })
|
store.commit(MutationTypes.UPDATE_SLIDE, { background: newBackground })
|
||||||
}
|
}
|
||||||
else {
|
else if(type === 'image') {
|
||||||
const newBackground: SlideBackground = {
|
const newBackground: SlideBackground = {
|
||||||
...background.value,
|
...background.value,
|
||||||
type: 'image',
|
type: 'image',
|
||||||
@ -95,6 +148,16 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
store.commit(MutationTypes.UPDATE_SLIDE, { background: newBackground })
|
store.commit(MutationTypes.UPDATE_SLIDE, { background: newBackground })
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
const newBackground: SlideBackground = {
|
||||||
|
...background.value,
|
||||||
|
type: 'gradient',
|
||||||
|
gradientType: background.value.gradientType || 'linear',
|
||||||
|
gradientColor: background.value.gradientColor || ['#fff', '#fff'],
|
||||||
|
gradientRotate: background.value.gradientRotate || 0,
|
||||||
|
}
|
||||||
|
store.commit(MutationTypes.UPDATE_SLIDE, { background: newBackground })
|
||||||
|
}
|
||||||
addHistorySnapshot()
|
addHistorySnapshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<linearGradient
|
<linearGradient
|
||||||
v-if="type === 'line'"
|
v-if="type === 'linear'"
|
||||||
:id="id"
|
:id="id"
|
||||||
x1="0%"
|
x1="0%"
|
||||||
y1="0%"
|
y1="0%"
|
||||||
@ -29,7 +29,7 @@ export default defineComponent({
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: String as PropType<'line' | 'radial'>,
|
type: String as PropType<'linear' | 'radial'>,
|
||||||
},
|
},
|
||||||
color1: {
|
color1: {
|
||||||
type: String,
|
type: String,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user