修复页面背景图显示异常的问题

This commit is contained in:
pipipi-pikachu 2021-01-12 10:33:33 +08:00
parent eb33459d52
commit 3266d853c4
2 changed files with 4 additions and 8 deletions

View File

@ -8,6 +8,7 @@ export default (background: Ref<SlideBackground | undefined>) => {
const { type, value, size } = background.value const { type, value, size } = background.value
if(type === 'solid') return { backgroundColor: value } if(type === 'solid') return { backgroundColor: value }
else if(type === 'image') { else if(type === 'image') {
if(!value) return { backgroundColor: '#fff' }
if(size === 'repeat') { if(size === 'repeat') {
return { return {
backgroundImage: `url(${value}`, backgroundImage: `url(${value}`,

View File

@ -35,10 +35,7 @@
<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">
<div <div class="content" :style="{ backgroundImage: `url(${background.value})` }">
class="content"
:style="backgroundStyle"
>
<IconFont type="icon-plus" /> <IconFont type="icon-plus" />
</div> </div>
</div> </div>
@ -57,7 +54,6 @@ import useHistorySnapshot from '@/hooks/useHistorySnapshot'
import ColorButton from './common/ColorButton.vue' import ColorButton from './common/ColorButton.vue'
import { getImageDataURL } from '@/utils/image' import { getImageDataURL } from '@/utils/image'
import useSlideBackgroundStyle from '@/hooks/useSlideBackgroundStyle'
export default defineComponent({ export default defineComponent({
name: 'slide-style-panel', name: 'slide-style-panel',
@ -79,8 +75,6 @@ export default defineComponent({
return currentSlide.value.background return currentSlide.value.background
}) })
const { backgroundStyle } = useSlideBackgroundStyle(background)
const { addHistorySnapshot } = useHistorySnapshot() const { addHistorySnapshot } = useHistorySnapshot()
const updateBackgroundType = (type: 'solid' | 'image') => { const updateBackgroundType = (type: 'solid' | 'image') => {
@ -126,7 +120,6 @@ export default defineComponent({
return { return {
background, background,
backgroundStyle,
updateBackgroundType, updateBackgroundType,
updateBackground, updateBackground,
uploadBackgroundImage, uploadBackgroundImage,
@ -172,6 +165,8 @@ export default defineComponent({
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background-position: center; background-position: center;
background-size: contain;
background-repeat: no-repeat;
cursor: pointer; cursor: pointer;
} }
} }