Commit a16b9091f69cc09d3318faa0debdc42d04968ee0
1 parent
9b2eec4b
feat(plugin) support background image or color(#37)
Showing
6 changed files
with
104 additions
and
14 deletions
front-end/h5/src/components/core/editor/canvas/edit.js
| ... | ... | @@ -165,6 +165,11 @@ export default { |
| 165 | 165 | > |
| 166 | 166 | { |
| 167 | 167 | elements.map((element, index) => { |
| 168 | + if (element.name === 'lbp-background') { | |
| 169 | + return h('lbp-background', { | |
| 170 | + props: element.getProps() | |
| 171 | + }) | |
| 172 | + } | |
| 168 | 173 | const data = { |
| 169 | 174 | style: { |
| 170 | 175 | width: '100%', | ... | ... |
front-end/h5/src/components/core/models/element.js
| ... | ... | @@ -53,6 +53,12 @@ class Element { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | getStyle ({ position = 'static', isRem = false } = {}) { |
| 56 | + if (this.name === 'lbp-background') { | |
| 57 | + return { | |
| 58 | + width: '100%', | |
| 59 | + height: '100%' | |
| 60 | + } | |
| 61 | + } | |
| 56 | 62 | const pluginProps = this.pluginProps |
| 57 | 63 | const commonStyle = this.commonStyle |
| 58 | 64 | let style = { | ... | ... |
front-end/h5/src/components/plugins/lbp-background.js
0 → 100644
| 1 | +export default { | |
| 2 | + name: 'lbp-background', | |
| 3 | + render () { | |
| 4 | + let style = { | |
| 5 | + width: '100%', | |
| 6 | + height: '100%' | |
| 7 | + } | |
| 8 | + | |
| 9 | + if (this.imgSrc) { | |
| 10 | + style = { | |
| 11 | + ...style, | |
| 12 | + 'background-size': 'cover', | |
| 13 | + 'background-position': '50% 50%', | |
| 14 | + 'background-origin': 'content-box', | |
| 15 | + 'background-image': `url(${this.imgSrc})` | |
| 16 | + } | |
| 17 | + } else { | |
| 18 | + style = { | |
| 19 | + ...style, | |
| 20 | + backgroundColor: this.backgroundColor | |
| 21 | + } | |
| 22 | + } | |
| 23 | + | |
| 24 | + return ( | |
| 25 | + <div style="width: 100%; height: 100%; overflow: hidden; position: absolute; z-index: -1; opacity: 1;"> | |
| 26 | + <div style={style}></div> | |
| 27 | + </div> | |
| 28 | + ) | |
| 29 | + }, | |
| 30 | + props: { | |
| 31 | + imgSrc: { | |
| 32 | + type: String, | |
| 33 | + default: '' | |
| 34 | + }, | |
| 35 | + backgroundColor: { | |
| 36 | + type: String, | |
| 37 | + default: 'transparent' | |
| 38 | + } | |
| 39 | + }, | |
| 40 | + editorConfig: { | |
| 41 | + propsConfig: { | |
| 42 | + imgSrc: { | |
| 43 | + // type: 'picture-picker', | |
| 44 | + type: 'a-input', | |
| 45 | + label: '图片url', | |
| 46 | + prop: { | |
| 47 | + type: 'textarea' | |
| 48 | + }, | |
| 49 | + defaultPropValue: '' | |
| 50 | + }, | |
| 51 | + backgroundColor: { | |
| 52 | + type: 'a-input', // lbs-color-picker | |
| 53 | + label: '背景颜色', | |
| 54 | + prop: { | |
| 55 | + type: 'color' | |
| 56 | + }, | |
| 57 | + require: true, | |
| 58 | + defaultPropValue: '#ffffff' // TODO why logogram for color does't work? | |
| 59 | + } | |
| 60 | + }, | |
| 61 | + components: { | |
| 62 | + // 'picture-picker': PicturePicker, | |
| 63 | + } | |
| 64 | + } | |
| 65 | +} | ... | ... |
front-end/h5/src/locales/lang/en-US.js
front-end/h5/src/locales/lang/zh-CN.js
front-end/h5/src/mixins/load-plugins.js
| ... | ... | @@ -5,6 +5,7 @@ import LbpText from '../components/plugins/lbp-text' |
| 5 | 5 | import LbpFormInput from '../components/plugins/lbp-form-input' |
| 6 | 6 | import LbpFormButton from '../components/plugins/lbp-form-button' |
| 7 | 7 | import LbpFormRadioGroup from '../components/plugins/lbp-form-radio-group' |
| 8 | +import LbpBackground from '../components/plugins/lbp-background' | |
| 8 | 9 | |
| 9 | 10 | export const pluginsList = [ |
| 10 | 11 | { |
| ... | ... | @@ -40,18 +41,18 @@ export const pluginsList = [ |
| 40 | 41 | visible: true, |
| 41 | 42 | name: LbpButton.name |
| 42 | 43 | }, |
| 43 | - { | |
| 44 | - i18nTitle: { | |
| 45 | - 'en-US': 'Carousel', | |
| 46 | - 'zh-CN': '轮播图' | |
| 47 | - }, | |
| 48 | - title: '轮播图', | |
| 49 | - icon: 'photo', | |
| 50 | - component: LbpFormRadioGroup, | |
| 51 | - visible: true, | |
| 52 | - name: LbpFormRadioGroup.name, | |
| 53 | - disabled: true | |
| 54 | - }, | |
| 44 | + // { | |
| 45 | + // i18nTitle: { | |
| 46 | + // 'en-US': 'Carousel', | |
| 47 | + // 'zh-CN': '轮播图' | |
| 48 | + // }, | |
| 49 | + // title: '轮播图', | |
| 50 | + // icon: 'photo', | |
| 51 | + // component: LbpFormRadioGroup, | |
| 52 | + // visible: true, | |
| 53 | + // name: LbpFormRadioGroup.name, | |
| 54 | + // disabled: true | |
| 55 | + // }, | |
| 55 | 56 | { |
| 56 | 57 | i18nTitle: { |
| 57 | 58 | 'en-US': 'Map', |
| ... | ... | @@ -133,6 +134,17 @@ export const pluginsList = [ |
| 133 | 134 | component: LbpFormRadioGroup, |
| 134 | 135 | visible: true, |
| 135 | 136 | name: LbpFormRadioGroup.name |
| 137 | + }, | |
| 138 | + { | |
| 139 | + i18nTitle: { | |
| 140 | + 'en-US': 'Background', | |
| 141 | + 'zh-CN': '背景' | |
| 142 | + }, | |
| 143 | + title: '背景', | |
| 144 | + icon: 'dot-circle-o', | |
| 145 | + component: LbpBackground, | |
| 146 | + visible: false, | |
| 147 | + name: LbpBackground.name | |
| 136 | 148 | } |
| 137 | 149 | ] |
| 138 | 150 | ... | ... |