Skip to content

Commit a7875cb

Browse files
committed
fix(preview): preview elements in corrent position
1 parent 2e5cd15 commit a7875cb

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

front-end/h5/src/components/core/editor/canvas/edit.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ export default {
8989
const style = element.getStyle()
9090
const data = {
9191
style,
92-
class: 'element-on-edit-canvas', // TODO 添加为何添加 class 的原因:与 handleClickCanvas 配合
92+
// 添加 class 的原因:与 handleClickCanvasProp 配合,
93+
// 当点击编辑画布上的其它区域(clickEvent.target.classList 不包含下面的 className)的时候,设置 editingElement=null
94+
class: 'element-on-edit-canvas',
9395
props: element.pluginProps, // #6 #3
9496
on: {
9597
// 高亮当前点击的元素

front-end/h5/src/components/core/editor/canvas/preview.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@ export default {
33
methods: {
44
renderPreview (h, elements) {
55
return (
6-
<div style={{ height: '100%' }}>
7-
{elements.map((element, index) => {
8-
return (() => {
6+
<div style={{ height: '100%', position: 'relative' }}>
7+
{
8+
elements.map((element, index) => {
9+
/**
10+
* TODO 是否可以将 renderElement 进行抽象成 renderBaseElement?
11+
* renderBaseElement
12+
* -> renderBaseElementWithEvent()
13+
* -> renderBaseElementWithCustomStyle()
14+
*/
15+
const style = element.getStyle('absolute'/** position */)
916
const data = {
10-
style: element.getStyle(),
11-
props: element.pluginProps, // #6 #3
12-
nativeOn: {}
17+
style,
18+
props: element.pluginProps
1319
}
1420
return h(element.name, data)
15-
})()
16-
})}
21+
})
22+
}
1723
</div>
1824
)
1925
}

front-end/h5/src/components/core/models/element.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Element {
4040
})
4141
}
4242

43-
getStyle () {
43+
getStyle (position = 'static') {
4444
const pluginProps = this.pluginProps
4545
const commonStyle = this.commonStyle
4646
let style = {
@@ -51,7 +51,8 @@ class Element {
5151
fontSize: `${pluginProps.fontSize || commonStyle.fontSize}px`,
5252
color: pluginProps.color || commonStyle.color,
5353
// backgroundColor: pluginProps.backgroundColor || commonStyle.backgroundColor,
54-
textAlign: pluginProps.textAlign || commonStyle.textAlign
54+
textAlign: pluginProps.textAlign || commonStyle.textAlign,
55+
position
5556
}
5657
return style
5758
}

front-end/h5/src/components/core/support/shape.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,12 @@ export default {
136136
}
137137
},
138138
render (h) {
139+
const style = this.element.getStyle('absolute'/** position */)
139140
return (
140141
<div
141142
onClick={this.handleWrapperClick}
142143
onMousedown={this.handleMousedown}
143-
style={{ ...this.element.getStyle(), position: 'absolute' }}
144+
style={style}
144145
>
145146
{
146147
this.active &&

0 commit comments

Comments
 (0)