Commit 25155a7402f5bec48d9005b0f5d079e8c22ff776

Authored by 宋远桥
Committed by 小小鲁班
1 parent b14a1ade

[feature] 根据输入框内容判断使用 px 或者 % 单位

front-end/h5/src/components/core/models/element.js
@@ -75,7 +75,13 @@ class Element { @@ -75,7 +75,13 @@ class Element {
75 75
76 return pluginProps 76 return pluginProps
77 } 77 }
78 - 78 + getPositionValue (key, isRem = false) {
  79 + const pluginProps = this.pluginProps
  80 + const commonStyle = this.commonStyle
  81 + const value = pluginProps[key] || commonStyle[key]
  82 + const isPercent = /^\d+%$/.test(value)
  83 + return isPercent ? value : parsePx(value, isRem)
  84 + }
79 getStyle ({ position = 'static', isRem = false } = {}) { 85 getStyle ({ position = 'static', isRem = false } = {}) {
80 if (this.name === 'lbp-background') { 86 if (this.name === 'lbp-background') {
81 return { 87 return {
@@ -86,10 +92,10 @@ class Element { @@ -86,10 +92,10 @@ class Element {
86 const pluginProps = this.pluginProps 92 const pluginProps = this.pluginProps
87 const commonStyle = this.commonStyle 93 const commonStyle = this.commonStyle
88 let style = { 94 let style = {
89 - top: parsePx(pluginProps.top || commonStyle.top, isRem),  
90 - left: parsePx(pluginProps.left || commonStyle.left, isRem),  
91 - width: parsePx(pluginProps.width || commonStyle.width, isRem),  
92 - height: parsePx(pluginProps.height || commonStyle.height, isRem), 95 + top: this.getPositionValue('top', isRem),
  96 + left: this.getPositionValue('left', isRem),
  97 + width: this.getPositionValue('width', isRem),
  98 + height: this.getPositionValue('height', isRem),
93 fontSize: parsePx(pluginProps.fontSize || commonStyle.fontSize, isRem), 99 fontSize: parsePx(pluginProps.fontSize || commonStyle.fontSize, isRem),
94 color: pluginProps.color || commonStyle.color, 100 color: pluginProps.color || commonStyle.color,
95 // backgroundColor: pluginProps.backgroundColor || commonStyle.backgroundColor, 101 // backgroundColor: pluginProps.backgroundColor || commonStyle.backgroundColor,