+
渐变角度:
updateBackground({ gradientRotate: value as number })"
+ :value="background.gradient.rotate || 0"
+ @update:value="value => updateGradientBackground({ rotate: value as number })"
style="width: 60%;"
/>
@@ -306,7 +301,7 @@
import { computed, ref } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore } from '@/store'
-import type { SlideBackground, SlideTheme } from '@/types/slides'
+import type { Gradient, GradientType, SlideBackground, SlideTheme } from '@/types/slides'
import { PRESET_THEMES } from '@/configs/theme'
import { WEB_FONTS } from '@/configs/font'
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
@@ -324,6 +319,7 @@ import Select from '@/components/Select.vue'
import Popover from '@/components/Popover.vue'
import NumberInput from '@/components/NumberInput.vue'
import Modal from '@/components/Modal.vue'
+import GradientBar from '@/components/GradientBar.vue'
const slidesStore = useSlidesStore()
const { availableFonts } = storeToRefs(useMainStore())
@@ -331,6 +327,7 @@ const { slides, currentSlide, viewportRatio, theme } = storeToRefs(slidesStore)
const moreThemeConfigsVisible = ref(false)
const themeStylesExtractVisible = ref(false)
+const currentGradientIndex = ref(0)
const background = computed(() => {
if (!currentSlide.value.background) {
@@ -372,21 +369,38 @@ const updateBackgroundType = (type: 'solid' | 'image' | 'gradient') => {
const newBackground: SlideBackground = {
...background.value,
type: 'gradient',
- gradientType: background.value.gradientType || 'linear',
- gradientColor: background.value.gradientColor || ['#fff', '#fff'],
- gradientRotate: background.value.gradientRotate || 0,
+ gradient: background.value.gradient || {
+ type: 'linear',
+ colors: [
+ { pos: 0, color: '#fff' },
+ { pos: 100, color: '#fff' },
+ ],
+ rotate: 0,
+ },
}
slidesStore.updateSlide({ background: newBackground })
}
addHistorySnapshot()
}
-// 设置背景图片
+// 设置背景
const updateBackground = (props: Partial
) => {
slidesStore.updateSlide({ background: { ...background.value, ...props } })
addHistorySnapshot()
}
+// 设置渐变背景
+const updateGradientBackground = (props: Partial) => {
+ updateBackground({ gradient: { ...background.value.gradient!, ...props } })
+}
+const updateGradientBackgroundColors = (color: string) => {
+ const colors = background.value.gradient!.colors.map((item, index) => {
+ if (index === currentGradientIndex.value) return { ...item, color }
+ return item
+ })
+ updateGradientBackground({ colors })
+}
+
// 上传背景图片
const uploadBackgroundImage = (files: FileList) => {
const imageFile = files[0]
diff --git a/src/views/components/element/ShapeElement/GradientDefs.vue b/src/views/components/element/ShapeElement/GradientDefs.vue
index 4e76a757..ff2bf1a0 100644
--- a/src/views/components/element/ShapeElement/GradientDefs.vue
+++ b/src/views/components/element/ShapeElement/GradientDefs.vue
@@ -19,9 +19,11 @@