Commit 6f665b8d33af0f994078db285a8d0faeb40986f1
1 parent
67c4845b
refactor: add getPluginProps && getCommonStyle function
Showing
1 changed file
with
21 additions
and
2 deletions
front-end/h5/src/components/core/models/element.js
| @@ -31,12 +31,31 @@ class Element { | @@ -31,12 +31,31 @@ class Element { | ||
| 31 | * 3. 为何需要 clone,因为会有 element.clone() 以及 page.clone(), | 31 | * 3. 为何需要 clone,因为会有 element.clone() 以及 page.clone(), |
| 32 | * element.pluginProps 和 elementcommonStyle 是引用类型,如果不做 deep_clone 可能会出现意外错误 | 32 | * element.pluginProps 和 elementcommonStyle 是引用类型,如果不做 deep_clone 可能会出现意外错误 |
| 33 | */ | 33 | */ |
| 34 | - this.pluginProps = (typeof ele.pluginProps === 'object' && cloneObj({ ...ele.pluginProps, uuid: this.uuid })) || this.getDefaultPluginProps(ele.props || {}) | ||
| 35 | - this.commonStyle = (typeof ele.commonStyle === 'object' && cloneObj(ele.commonStyle)) || { ...defaultStyle, zindex: ele.zindex, ...ele.defaultStyle } | 34 | + this.pluginProps = this.getPluginProps(ele) |
| 35 | + this.commonStyle = this.getCommonStyle(ele) | ||
| 36 | this.events = [] | 36 | this.events = [] |
| 37 | this.animations = ele.animations || [] | 37 | this.animations = ele.animations || [] |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | + getCommonStyle (ele) { | ||
| 41 | + if (typeof ele.commonStyle === 'object') { | ||
| 42 | + return cloneObj(ele.commonStyle) | ||
| 43 | + } | ||
| 44 | + return { | ||
| 45 | + ...defaultStyle, | ||
| 46 | + zindex: ele.zindex, | ||
| 47 | + ...ele.defaultStyle, | ||
| 48 | + ...ele.customStyle | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + getPluginProps (ele) { | ||
| 53 | + if (typeof ele.pluginProps === 'object') { | ||
| 54 | + return cloneObj({ ...ele.pluginProps, uuid: this.uuid }) | ||
| 55 | + } | ||
| 56 | + return this.getDefaultPluginProps(ele.props || {}) | ||
| 57 | + } | ||
| 58 | + | ||
| 40 | // init prop of plugin | 59 | // init prop of plugin |
| 41 | getDefaultPluginProps (props) { | 60 | getDefaultPluginProps (props) { |
| 42 | const pluginProps = { | 61 | const pluginProps = { |