diff --git a/src/components/ColorPicker/Saturation.vue b/src/components/ColorPicker/Saturation.vue index e5ddf7a8..155149b6 100644 --- a/src/components/ColorPicker/Saturation.vue +++ b/src/components/ColorPicker/Saturation.vue @@ -68,7 +68,6 @@ const handleChange = (e: MouseEvent) => { }) } - const unbindEventListeners = () => { window.removeEventListener('mousemove', handleChange) window.removeEventListener('mouseup', unbindEventListeners) diff --git a/src/components/GradientBar.vue b/src/components/GradientBar.vue new file mode 100644 index 00000000..34234b0a --- /dev/null +++ b/src/components/GradientBar.vue @@ -0,0 +1,145 @@ + + + + + \ No newline at end of file diff --git a/src/hooks/useExport.ts b/src/hooks/useExport.ts index 0bc2d81c..6fa6628f 100644 --- a/src/hooks/useExport.ts +++ b/src/hooks/useExport.ts @@ -396,8 +396,10 @@ export default () => { const c = formatColor(background.color) pptxSlide.background = { color: c.color, transparency: (1 - c.alpha) * 100 } } - else if (background.type === 'gradient' && background.gradientColor) { - const [color1, color2] = background.gradientColor + else if (background.type === 'gradient' && background.gradient) { + const colors = background.gradient.colors + const color1 = colors[0].color + const color2 = colors[colors.length - 1].color const color = tinycolor.mix(color1, color2).toHexString() const c = formatColor(color) pptxSlide.background = { color: c.color, transparency: (1 - c.alpha) * 100 } diff --git a/src/hooks/useImport.ts b/src/hooks/useImport.ts index 8538a354..c21a8a51 100644 --- a/src/hooks/useImport.ts +++ b/src/hooks/useImport.ts @@ -120,9 +120,14 @@ export default () => { else if (type === 'gradient') { background = { type: 'gradient', - gradientType: 'linear', - gradientColor: [value.colors[0].color, value.colors[value.colors.length - 1].color], - gradientRotate: value.rot, + gradient: { + type: 'linear', + colors: value.colors.map(item => ({ + ...item, + pos: parseInt(item.pos), + })), + rotate: value.rot, + }, } } else { diff --git a/src/hooks/useSlideBackgroundStyle.ts b/src/hooks/useSlideBackgroundStyle.ts index 86114586..a00b8d90 100644 --- a/src/hooks/useSlideBackgroundStyle.ts +++ b/src/hooks/useSlideBackgroundStyle.ts @@ -11,9 +11,7 @@ export default (background: Ref) => { color, image, imageSize, - gradientColor, - gradientRotate, - gradientType, + gradient, } = background.value // 纯色背景 @@ -38,13 +36,12 @@ export default (background: Ref) => { } // 渐变色背景 - 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}` } + else if (type === 'gradient' && gradient) { + const { type, colors, rotate } = gradient + const list = colors.map(item => `${item.color} ${item.pos}%`) + + if (type === 'radial') return { backgroundImage: `radial-gradient(${list.join(',')}` } + return { backgroundImage: `linear-gradient(${rotate}deg, ${list.join(',')}` } } return { backgroundColor: '#fff' } diff --git a/src/hooks/useSlideTheme.ts b/src/hooks/useSlideTheme.ts index a895aaad..ba5a16d7 100644 --- a/src/hooks/useSlideTheme.ts +++ b/src/hooks/useSlideTheme.ts @@ -30,10 +30,10 @@ export default () => { if (slide.background.type === 'solid' && slide.background.color) { backgroundColorValues.push({ area: 1, value: slide.background.color }) } - else if (slide.background.type === 'gradient' && slide.background.gradientColor) { - backgroundColorValues.push(...slide.background.gradientColor.map(item => ({ + else if (slide.background.type === 'gradient' && slide.background.gradient) { + backgroundColorValues.push(...slide.background.gradient.colors.map(item => ({ area: 1, - value: item, + value: item.color, }))) } else backgroundColorValues.push({ area: 1, value: theme.value.backgroundColor }) diff --git a/src/types/slides.ts b/src/types/slides.ts index 3ece86fa..24049cfa 100644 --- a/src/types/slides.ts +++ b/src/types/slides.ts @@ -34,6 +34,17 @@ export const enum ElementTypes { AUDIO = 'audio', } +export type GradientType = 'linear' | 'radial' +export type GradientColor = { + pos: number + color: string +} +export interface Gradient { + type: GradientType + colors: GradientColor[] + rotate: number +} + /** * 元素阴影 * @@ -261,7 +272,7 @@ export interface PPTImageElement extends PPTBaseElement { * rotate: 渐变角度(线性渐变) */ export interface ShapeGradient { - type: 'linear' | 'radial' + type: GradientType color: [string, string] rotate: number } @@ -653,9 +664,7 @@ export interface SlideBackground { color?: string image?: string imageSize?: 'cover' | 'contain' | 'repeat' - gradientType?: 'linear' | 'radial' - gradientColor?: [string, string] - gradientRotate?: number + gradient?: Gradient } diff --git a/src/views/Editor/Toolbar/ElementStylePanel/ShapeStylePanel.vue b/src/views/Editor/Toolbar/ElementStylePanel/ShapeStylePanel.vue index 48ea4964..82f81efe 100644 --- a/src/views/Editor/Toolbar/ElementStylePanel/ShapeStylePanel.vue +++ b/src/views/Editor/Toolbar/ElementStylePanel/ShapeStylePanel.vue @@ -41,7 +41,7 @@