59 lines
1.7 KiB
TypeScript
Raw Normal View History

import { PickCreateComponentType } from '@/packages/index.d'
2022-03-07 15:21:45 +08:00
import { EditCanvasConfigType } from '@/store/modules/chartEditStore/chartEditStore.d'
type AttrType = PickCreateComponentType<'attr'>
2022-03-09 09:21:47 +08:00
type StylesType = PickCreateComponentType<'styles'>
2022-04-25 16:50:20 +08:00
// 设置位置
2022-03-17 10:53:18 +08:00
export const getComponentAttrStyle = (attr: AttrType, index: number) => {
const componentStyle = {
zIndex: index + 1,
left: `${attr.x}px`,
top: `${attr.y}px`
}
return componentStyle
}
2022-04-25 16:50:20 +08:00
// 设置大小
2022-03-17 10:53:18 +08:00
export const getSizeStyle = (attr: AttrType, scale?: number) => {
const sizeStyle = {
width: `${scale ? scale * attr.w : attr.w}px`,
2022-03-09 09:21:47 +08:00
height: `${scale ? scale * attr.h : attr.h}px`
}
return sizeStyle
}
2022-03-07 15:21:45 +08:00
2022-04-25 16:50:20 +08:00
// 全局样式
2022-03-17 10:53:18 +08:00
export const getEditCanvasConfigStyle = (canvas: EditCanvasConfigType) => {
2022-03-07 15:39:40 +08:00
// 背景
const computedBackground = canvas.selectColor
? { background: canvas.background }
2022-03-09 09:21:47 +08:00
: {
background: `url(${canvas.backgroundImage}) no-repeat center/100% !important`
}
2022-03-07 15:21:45 +08:00
return {
2022-04-26 11:37:25 +08:00
position: 'relative' as const,
2022-03-07 15:21:45 +08:00
width: canvas.width ? `${canvas.width || 100}px` : '100%',
height: canvas.height ? `${canvas.height}px` : '100%',
2022-03-07 15:39:40 +08:00
...computedBackground
2022-03-07 15:21:45 +08:00
}
}
2022-03-09 09:21:47 +08:00
// 动画
export const animationsClass = (animations: string[]) => {
if (animations.length) {
return `animate__animated animate__${animations[0]}`
}
return ''
}
2022-03-09 17:37:32 +08:00
2022-04-25 16:50:20 +08:00
// 滤镜
2022-04-25 16:17:22 +08:00
export const getStyle = (styles: StylesType | EditCanvasConfigType) => {
2022-04-19 22:07:54 +08:00
const { opacity, saturate, contrast, hueRotate, brightness } = styles
2022-03-09 17:37:32 +08:00
return {
// 透明度
2022-04-19 22:07:54 +08:00
opacity: opacity,
filter: `saturate(${saturate}) contrast(${contrast}) hue-rotate(${hueRotate}deg) brightness(${brightness})`
2022-03-09 17:37:32 +08:00
}
}