Commit a16b9091f69cc09d3318faa0debdc42d04968ee0

Authored by ly525
1 parent 9b2eec4b

feat(plugin) support background image or color(#37)

front-end/h5/src/components/core/editor/canvas/edit.js
@@ -165,6 +165,11 @@ export default { @@ -165,6 +165,11 @@ export default {
165 > 165 >
166 { 166 {
167 elements.map((element, index) => { 167 elements.map((element, index) => {
  168 + if (element.name === 'lbp-background') {
  169 + return h('lbp-background', {
  170 + props: element.getProps()
  171 + })
  172 + }
168 const data = { 173 const data = {
169 style: { 174 style: {
170 width: '100%', 175 width: '100%',
front-end/h5/src/components/core/models/element.js
@@ -53,6 +53,12 @@ class Element { @@ -53,6 +53,12 @@ class Element {
53 } 53 }
54 54
55 getStyle ({ position = 'static', isRem = false } = {}) { 55 getStyle ({ position = 'static', isRem = false } = {}) {
  56 + if (this.name === 'lbp-background') {
  57 + return {
  58 + width: '100%',
  59 + height: '100%'
  60 + }
  61 + }
56 const pluginProps = this.pluginProps 62 const pluginProps = this.pluginProps
57 const commonStyle = this.commonStyle 63 const commonStyle = this.commonStyle
58 let style = { 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
@@ -76,7 +76,8 @@ export default { @@ -76,7 +76,8 @@ export default {
76 prop: 'Prop', 76 prop: 'Prop',
77 animation: 'Animation', 77 animation: 'Animation',
78 action: 'Action', 78 action: 'Action',
79 - script: 'Script' 79 + script: 'Script',
  80 + background: 'Background'
80 }, 81 },
81 animation: { 82 animation: {
82 add: 'Add', 83 add: 'Add',
front-end/h5/src/locales/lang/zh-CN.js
@@ -75,7 +75,8 @@ export default { @@ -75,7 +75,8 @@ export default {
75 prop: '属性', 75 prop: '属性',
76 animation: '动画', 76 animation: '动画',
77 action: '动作', 77 action: '动作',
78 - script: '脚本' 78 + script: '脚本',
  79 + background: '背景'
79 }, 80 },
80 animation: { 81 animation: {
81 add: '添加动画', 82 add: '添加动画',
front-end/h5/src/mixins/load-plugins.js
@@ -5,6 +5,7 @@ import LbpText from &#39;../components/plugins/lbp-text&#39; @@ -5,6 +5,7 @@ import LbpText from &#39;../components/plugins/lbp-text&#39;
5 import LbpFormInput from '../components/plugins/lbp-form-input' 5 import LbpFormInput from '../components/plugins/lbp-form-input'
6 import LbpFormButton from '../components/plugins/lbp-form-button' 6 import LbpFormButton from '../components/plugins/lbp-form-button'
7 import LbpFormRadioGroup from '../components/plugins/lbp-form-radio-group' 7 import LbpFormRadioGroup from '../components/plugins/lbp-form-radio-group'
  8 +import LbpBackground from '../components/plugins/lbp-background'
8 9
9 export const pluginsList = [ 10 export const pluginsList = [
10 { 11 {
@@ -40,18 +41,18 @@ export const pluginsList = [ @@ -40,18 +41,18 @@ export const pluginsList = [
40 visible: true, 41 visible: true,
41 name: LbpButton.name 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 i18nTitle: { 57 i18nTitle: {
57 'en-US': 'Map', 58 'en-US': 'Map',
@@ -133,6 +134,17 @@ export const pluginsList = [ @@ -133,6 +134,17 @@ export const pluginsList = [
133 component: LbpFormRadioGroup, 134 component: LbpFormRadioGroup,
134 visible: true, 135 visible: true,
135 name: LbpFormRadioGroup.name 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