Commit de5d1977098fc29483780557713c98ecae12a76a
1 parent
8b45dfe6
[feature] 根据输入框内容判断使用 px 或者 % 单位
Showing
1 changed file
with
11 additions
and
5 deletions
front-end/h5/src/components/core/models/element.js
| ... | ... | @@ -75,7 +75,13 @@ class Element { |
| 75 | 75 | |
| 76 | 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 | 85 | getStyle ({ position = 'static', isRem = false } = {}) { |
| 80 | 86 | if (this.name === 'lbp-background') { |
| 81 | 87 | return { |
| ... | ... | @@ -86,10 +92,10 @@ class Element { |
| 86 | 92 | const pluginProps = this.pluginProps |
| 87 | 93 | const commonStyle = this.commonStyle |
| 88 | 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 | 99 | fontSize: parsePx(pluginProps.fontSize || commonStyle.fontSize, isRem), |
| 94 | 100 | color: pluginProps.color || commonStyle.color, |
| 95 | 101 | // backgroundColor: pluginProps.backgroundColor || commonStyle.backgroundColor, | ... | ... |