feat: 新增预览背景图

This commit is contained in:
MTrun 2022-03-07 15:39:40 +08:00
parent c2e01b3907
commit b9b7c75627
4 changed files with 8 additions and 4 deletions

View File

@ -18,7 +18,7 @@
import { PropType, computed } from 'vue' import { PropType, computed } from 'vue'
import { ChartEditStorageType } from '../../index.d' import { ChartEditStorageType } from '../../index.d'
import { chartColors } from '@/settings/chartThemes/index' import { chartColors } from '@/settings/chartThemes/index'
import { useSizeStyle, useComponentStyle } from '../../hooks/useStyle.hook' import { useSizeStyle, useComponentStyle } from '../../utils'
const props = defineProps({ const props = defineProps({
localStorageInfo: { localStorageInfo: {

View File

@ -17,7 +17,7 @@ import { usePreviewScale } from '@/hooks/index'
import { RenderList } from './components/RenderList/index' import { RenderList } from './components/RenderList/index'
import { ChartEditStorageType } from './index.d' import { ChartEditStorageType } from './index.d'
import { getLocalStorageInfo } from './utils/index' import { getLocalStorageInfo } from './utils/index'
import { useEditCanvasConfigStyle } from './hooks/useStyle.hook' import { useEditCanvasConfigStyle } from './utils'
const previewRef = ref() const previewRef = ref()

View File

@ -1,3 +1,4 @@
export * from './style'
import { getLocalStorage } from '@/utils' import { getLocalStorage } from '@/utils'
import { StorageEnum } from '@/enums/storageEnum' import { StorageEnum } from '@/enums/storageEnum'
import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d' import { ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'

View File

@ -16,16 +16,19 @@ export const useSizeStyle = (attr: AttrType, scale?: number) => {
const sizeStyle = { const sizeStyle = {
width: `${scale ? scale * attr.w : attr.w}px`, width: `${scale ? scale * attr.w : attr.w}px`,
height: `${scale ? scale * attr.h : attr.h}px`, height: `${scale ? scale * attr.h : attr.h}px`,
border: '1px solid red'
} }
return sizeStyle return sizeStyle
} }
export const useEditCanvasConfigStyle = (canvas: EditCanvasConfigType) => { export const useEditCanvasConfigStyle = (canvas: EditCanvasConfigType) => {
// 背景
const computedBackground = canvas.selectColor
? { background: canvas.background }
: { background: `url(${canvas.backgroundImage}) no-repeat center/100% !important` }
return { return {
position: 'relative', position: 'relative',
width: canvas.width ? `${canvas.width || 100}px` : '100%', width: canvas.width ? `${canvas.width || 100}px` : '100%',
height: canvas.height ? `${canvas.height}px` : '100%', height: canvas.height ? `${canvas.height}px` : '100%',
border: '1px solid red' ...computedBackground
} }
} }