Commit 7b14d7c26952c386ef303852063235fe32b12243

Authored by ly525
1 parent 9b55148b

fix: preview margin&padding; #!zh:预览margin&padding

front-end/h5/src/components/core/editor/canvas/preview.js
@@ -11,19 +11,12 @@ export default { @@ -11,19 +11,12 @@ export default {
11 methods: { 11 methods: {
12 renderPreview (h, elements) { 12 renderPreview (h, elements) {
13 const pageWrapperStyle = { height: this.height || '100%', position: 'relative' } 13 const pageWrapperStyle = { height: this.height || '100%', position: 'relative' }
14 - // 与 edit 组件保持样式一致  
15 - const data = {  
16 - style: {  
17 - width: '100%',  
18 - height: '100%'  
19 - }  
20 - }  
21 return ( 14 return (
22 <div style={pageWrapperStyle}> 15 <div style={pageWrapperStyle}>
23 { 16 {
24 elements.map((element, index) => { 17 elements.map((element, index) => {
25 return <node-wrapper element={element}> 18 return <node-wrapper element={element}>
26 - {h(element.name, data)} 19 + {h(element.name, element.getPreviewData({ position: 'static', isNodeWrapper: false }))}
27 </node-wrapper> 20 </node-wrapper>
28 }) 21 })
29 } 22 }
front-end/h5/src/components/core/models/element.js
@@ -78,7 +78,7 @@ const defaultStyle = { @@ -78,7 +78,7 @@ const defaultStyle = {
78 boxModelPart: '' // 可选值 margin、padding、border 78 boxModelPart: '' // 可选值 margin、padding、border
79 } 79 }
80 80
81 -class Element { 81 +export default class Element {
82 constructor (ele) { 82 constructor (ele) {
83 this.name = ele.name 83 this.name = ele.name
84 this.uuid = ele.uuid || guid() 84 this.uuid = ele.uuid || guid()
@@ -156,8 +156,8 @@ class Element { @@ -156,8 +156,8 @@ class Element {
156 'border-color': color.value 156 'border-color': color.value
157 } 157 }
158 } 158 }
159 - getStyle ({ position = 'static', isRem = false } = {}) {  
160 - if (this.name === 'lbp-background') { 159 + getStyle ({ position = 'static', isRem = false, isNodeWrapper = true } = {}) {
  160 + if (this.name === 'lbp-background' || !isNodeWrapper) {
161 return { 161 return {
162 width: '100%', 162 width: '100%',
163 height: '100%' 163 height: '100%'
@@ -217,10 +217,9 @@ class Element { @@ -217,10 +217,9 @@ class Element {
217 return attrs 217 return attrs
218 } 218 }
219 219
220 - getPreviewData ({ position = 'static', isRem = false, mode = 'preview' } = {}) {  
221 - const style = this.getStyle({ position }) 220 + getPreviewData ({ position = 'static', isRem = false, mode = 'preview', isNodeWrapper = true } = {}) {
222 const data = { 221 const data = {
223 - style, 222 + style: this.getStyle({ position, isNodeWrapper }),
224 props: this.getProps({ mode }), 223 props: this.getProps({ mode }),
225 attrs: this.getAttrs() 224 attrs: this.getAttrs()
226 } 225 }
@@ -240,5 +239,3 @@ class Element { @@ -240,5 +239,3 @@ class Element {
240 }) 239 })
241 } 240 }
242 } 241 }
243 -  
244 -export default Element