style.ts
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { PickCreateComponentType } from '@/packages/index.d'
import { EditCanvasConfigType } from '@/store/modules/chartEditStore/chartEditStore.d'
/// THINGS_KIT 修改背景图片
import { useBackgroundSelect } from '@/utils/external/useBackgroundImageSelect'
type AttrType = PickCreateComponentType<'attr'>
type StatusType = PickCreateComponentType<'status'>
type PreviewConfig = PickCreateComponentType<'preview'>
// 设置位置
export const getComponentAttrStyle = (attr: AttrType, index: number) => {
const componentStyle = {
zIndex: index + 1,
left: `${attr.x}px`,
top: `${attr.y}px`
}
return componentStyle
}
// 设置大小
export const getSizeStyle = (attr: AttrType, scale?: number) => {
return {
width: `${scale ? scale * attr.w : attr.w}px`,
height: `${scale ? scale * attr.h : attr.h}px`
}
}
// 设置状态样式
export const getStatusStyle = (attr: StatusType) => {
return {
display: attr.hide ? 'none' : 'block'
}
}
// 设置预览配置样式
export const getPreviewConfigStyle = (previewConfig: PreviewConfig) => {
const previewStyle: Partial<CSSStyleDeclaration> = {}
if (previewConfig) {
if (previewConfig.overFlowHidden) {
previewStyle.overflow = 'hidden'
}
}
return previewStyle
}
// THINGS_KIT 修改背景图片
const { getBackgroundImagePath } = useBackgroundSelect()
// 全局样式
export const getEditCanvasConfigStyle = (canvas: EditCanvasConfigType) => {
// 背景
const computedBackground = canvas.selectColor
? { background: canvas.background }
: {
background: `url(${getBackgroundImagePath(canvas.backgroundImage as unknown as string)}) center center / cover no-repeat !important`
}
return {
position: 'relative' as const,
width: canvas.width ? `${canvas.width || 100}px` : '100%',
height: canvas.height ? `${canvas.height}px` : '100%',
...computedBackground
}
}