From d06c1068b10d0f76f249d88aabc06507ed1976eb Mon Sep 17 00:00:00 2001 From: pipipi-pikachu <1171051090@qq.com> Date: Thu, 21 Jan 2021 20:45:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=83=8C=E6=99=AF=E6=B8=90?= =?UTF-8?q?=E5=8F=98=E5=A1=AB=E5=85=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useSlideBackgroundStyle.ts | 13 +++- src/types/slides.ts | 7 +- .../ElementStylePanel/ShapeStylePanel.vue | 6 +- src/views/Editor/Toolbar/SlideStylePanel.vue | 69 ++++++++++++++++++- .../element/ShapeElement/GradientDefs.vue | 4 +- 5 files changed, 88 insertions(+), 11 deletions(-) diff --git a/src/hooks/useSlideBackgroundStyle.ts b/src/hooks/useSlideBackgroundStyle.ts index b55603e..6b05b08 100644 --- a/src/hooks/useSlideBackgroundStyle.ts +++ b/src/hooks/useSlideBackgroundStyle.ts @@ -10,6 +10,9 @@ export default (background: Ref) => { color, image, imageSize, + gradientColor, + gradientRotate, + gradientType, } = background.value if(type === 'solid') return { backgroundColor: color } @@ -25,9 +28,17 @@ export default (background: Ref) => { return { backgroundImage: `url(${image}`, 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' } }) diff --git a/src/types/slides.ts b/src/types/slides.ts index de9cfe5..092df86 100644 --- a/src/types/slides.ts +++ b/src/types/slides.ts @@ -73,7 +73,7 @@ export interface PPTImageElement { } export interface ShapeGradient { - type: 'line' | 'radial'; + type: 'linear' | 'radial'; color: [string, string]; rotate: number; } @@ -167,10 +167,13 @@ export interface PPTAnimation { } export interface SlideBackground { - type: 'solid' | 'image'; + type: 'solid' | 'image' | 'gradient'; color?: string; image?: string; imageSize?: 'cover' | 'contain' | 'repeat' | 'initial'; + gradientType?: 'linear' | 'radial'; + gradientColor?: [string, string]; + gradientRotate?: number; } export interface Slide { diff --git a/src/views/Editor/Toolbar/ElementStylePanel/ShapeStylePanel.vue b/src/views/Editor/Toolbar/ElementStylePanel/ShapeStylePanel.vue index cdfcd01..371de7e 100644 --- a/src/views/Editor/Toolbar/ElementStylePanel/ShapeStylePanel.vue +++ b/src/views/Editor/Toolbar/ElementStylePanel/ShapeStylePanel.vue @@ -25,7 +25,7 @@ @change="value => updateGradient({ type: value })" v-else > - 线性渐变 + 线性渐变 径向渐变 @@ -55,7 +55,7 @@ -
+
渐变角度:
纯色填充 图片填充 + 渐变填充
+ @@ -77,7 +130,7 @@ export default defineComponent({ const { addHistorySnapshot } = useHistorySnapshot() - const updateBackgroundType = (type: 'solid' | 'image') => { + const updateBackgroundType = (type: 'solid' | 'image' | 'gradient') => { if(type === 'solid') { const newBackground: SlideBackground = { ...background.value, @@ -86,7 +139,7 @@ export default defineComponent({ } store.commit(MutationTypes.UPDATE_SLIDE, { background: newBackground }) } - else { + else if(type === 'image') { const newBackground: SlideBackground = { ...background.value, type: 'image', @@ -95,6 +148,16 @@ export default defineComponent({ } 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() } diff --git a/src/views/components/element/ShapeElement/GradientDefs.vue b/src/views/components/element/ShapeElement/GradientDefs.vue index 1c58d3e..9728546 100644 --- a/src/views/components/element/ShapeElement/GradientDefs.vue +++ b/src/views/components/element/ShapeElement/GradientDefs.vue @@ -1,6 +1,6 @@