Commit a7875cbc73c0d18bc2459985ca3ce1d4dc44f141

Authored by ly525
1 parent 2e5cd151

fix(preview): preview elements in corrent position

front-end/h5/src/components/core/editor/canvas/edit.js
... ... @@ -89,7 +89,9 @@ export default {
89 89 const style = element.getStyle()
90 90 const data = {
91 91 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',
93 95 props: element.pluginProps, // #6 #3
94 96 on: {
95 97 // 高亮当前点击的元素
... ...
front-end/h5/src/components/core/editor/canvas/preview.js
... ... @@ -3,17 +3,23 @@ export default {
3 3 methods: {
4 4 renderPreview (h, elements) {
5 5 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 */)
9 16 const data = {
10   - style: element.getStyle(),
11   - props: element.pluginProps, // #6 #3
12   - nativeOn: {}
  17 + style,
  18 + props: element.pluginProps
13 19 }
14 20 return h(element.name, data)
15   - })()
16   - })}
  21 + })
  22 + }
17 23 </div>
18 24 )
19 25 }
... ...
front-end/h5/src/components/core/models/element.js
... ... @@ -40,7 +40,7 @@ class Element {
40 40 })
41 41 }
42 42  
43   - getStyle () {
  43 + getStyle (position = 'static') {
44 44 const pluginProps = this.pluginProps
45 45 const commonStyle = this.commonStyle
46 46 let style = {
... ... @@ -51,7 +51,8 @@ class Element {
51 51 fontSize: `${pluginProps.fontSize || commonStyle.fontSize}px`,
52 52 color: pluginProps.color || commonStyle.color,
53 53 // backgroundColor: pluginProps.backgroundColor || commonStyle.backgroundColor,
54   - textAlign: pluginProps.textAlign || commonStyle.textAlign
  54 + textAlign: pluginProps.textAlign || commonStyle.textAlign,
  55 + position
55 56 }
56 57 return style
57 58 }
... ...
front-end/h5/src/components/core/support/shape.js
... ... @@ -136,11 +136,12 @@ export default {
136 136 }
137 137 },
138 138 render (h) {
  139 + const style = this.element.getStyle('absolute'/** position */)
139 140 return (
140 141 <div
141 142 onClick={this.handleWrapperClick}
142 143 onMousedown={this.handleMousedown}
143   - style={{ ...this.element.getStyle(), position: 'absolute' }}
  144 + style={style}
144 145 >
145 146 {
146 147 this.active &&
... ...