Commit 8bd78f37ba6e9ce3855ca1b4326c8d7e476a6eea
1 parent
c7cd5a54
chore: move Element to core/models folder
Showing
2 changed files
with
64 additions
and
60 deletions
front-end/h5/src/components/core/models/element.js
0 → 100644
| 1 | + | ||
| 2 | +const defaultProps = { | ||
| 3 | + top: 100, | ||
| 4 | + left: 100, | ||
| 5 | + width: 100, | ||
| 6 | + height: 40, | ||
| 7 | + zindex: 1, | ||
| 8 | + textAlign: 'center', | ||
| 9 | + color: '#000000', | ||
| 10 | + backgroundColor: '#ffffff', | ||
| 11 | + fontSize: 14 | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +class Element { | ||
| 15 | + constructor (ele) { | ||
| 16 | + this.name = ele.name | ||
| 17 | + this.editorConfig = ele.editorConfig || {} | ||
| 18 | + this.pluginProps = {} | ||
| 19 | + this.init() | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + init () { | ||
| 23 | + // init common props | ||
| 24 | + Object.keys(defaultProps).forEach(key => { | ||
| 25 | + this[key] = defaultProps[key] | ||
| 26 | + }) | ||
| 27 | + | ||
| 28 | + // init prop of plugin | ||
| 29 | + const propConf = this.editorConfig.propsConfig | ||
| 30 | + Object.keys(propConf).forEach(key => { | ||
| 31 | + // #6 | ||
| 32 | + if (key === 'name') { | ||
| 33 | + console.warn('Please do not use {name} as plugin prop') | ||
| 34 | + return | ||
| 35 | + } | ||
| 36 | + this.pluginProps[key] = propConf[key].defaultPropValue | ||
| 37 | + }) | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + getStyle () { | ||
| 41 | + return { | ||
| 42 | + top: `${this.top}px`, | ||
| 43 | + left: `${this.left}px`, | ||
| 44 | + width: `${this.width}px`, | ||
| 45 | + height: `${this.height}px`, | ||
| 46 | + fontSize: `${this.fontSize}px`, | ||
| 47 | + color: this.color, | ||
| 48 | + backgroundColor: this.backgroundColor, | ||
| 49 | + textAlign: this.textAlign | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + getClass () { | ||
| 54 | + | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + getData () { | ||
| 58 | + | ||
| 59 | + } | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +export default Element |
front-end/h5/src/views/Editor.vue
| @@ -3,6 +3,8 @@ import Vue from 'vue' | @@ -3,6 +3,8 @@ import Vue from 'vue' | ||
| 3 | 3 | ||
| 4 | import LbpButton from '../components/plugins/lbp-button' | 4 | import LbpButton from '../components/plugins/lbp-button' |
| 5 | 5 | ||
| 6 | +import Element from '../components/core/models/element' | ||
| 7 | + | ||
| 6 | const PluginList = [ | 8 | const PluginList = [ |
| 7 | { | 9 | { |
| 8 | title: '按钮', | 10 | title: '按钮', |
| @@ -13,66 +15,6 @@ const PluginList = [ | @@ -13,66 +15,6 @@ const PluginList = [ | ||
| 13 | } | 15 | } |
| 14 | ] | 16 | ] |
| 15 | 17 | ||
| 16 | -const defaultProps = { | ||
| 17 | - top: 100, | ||
| 18 | - left: 100, | ||
| 19 | - width: 100, | ||
| 20 | - height: 40, | ||
| 21 | - zindex: 1, | ||
| 22 | - textAlign: 'center', | ||
| 23 | - color: '#000000', | ||
| 24 | - backgroundColor: '#ffffff', | ||
| 25 | - fontSize: 14 | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -class Element { | ||
| 29 | - constructor (ele) { | ||
| 30 | - this.name = ele.name | ||
| 31 | - this.editorConfig = ele.editorConfig || {} | ||
| 32 | - this.init() | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - init () { | ||
| 36 | - // init common props | ||
| 37 | - Object.keys(defaultProps).forEach(key => { | ||
| 38 | - this[key] = defaultProps[key] | ||
| 39 | - }) | ||
| 40 | - | ||
| 41 | - // init prop of plugin | ||
| 42 | - this.pluginProps = {} | ||
| 43 | - const propConf = this.editorConfig.propsConfig | ||
| 44 | - Object.keys(propConf).forEach(key => { | ||
| 45 | - // #6 | ||
| 46 | - if (key === 'name') { | ||
| 47 | - console.warn('Please do not use {name} as plugin prop') | ||
| 48 | - return | ||
| 49 | - } | ||
| 50 | - this.pluginProps[key] = propConf[key].defaultPropValue | ||
| 51 | - }) | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | - getStyle () { | ||
| 55 | - return { | ||
| 56 | - top: `${this.top}px`, | ||
| 57 | - left: `${this.left}px`, | ||
| 58 | - width: `${this.width}px`, | ||
| 59 | - height: `${this.height}px`, | ||
| 60 | - fontSize: `${this.fontSize}px`, | ||
| 61 | - color: this.color, | ||
| 62 | - backgroundColor: this.backgroundColor, | ||
| 63 | - textAlign: this.textAlign | ||
| 64 | - } | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - getClass () { | ||
| 68 | - | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - getData () { | ||
| 72 | - | ||
| 73 | - } | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | const Editor = { | 18 | const Editor = { |
| 77 | name: 'Editor', | 19 | name: 'Editor', |
| 78 | components: { | 20 | components: { |