king
2021-07-28 137fb8ea6af2789b3238b22bac31d80bced41dfe
src/pc/bgcontroller/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Form, Icon } from 'antd'
import { Form, Icon, Select } from 'antd'
import zhCN from '@/locales/zh-CN/mob.js'
import enUS from '@/locales/en-US/mob.js'
@@ -11,6 +11,7 @@
const ColorSketch = asyncComponent(() => import('@/mob/colorsketch'))
const StyleInput = asyncComponent(() => import('@/menu/stylecontroller/styleInput'))
const SourceComponent = asyncComponent(() => import('@/menu/components/share/sourcecomponent'))
const { Option } = Select
class MobController extends Component {
  static propTpyes = {
@@ -22,6 +23,10 @@
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    backgroundColor: '',
    backgroundImage: '',
    backgroundSize: '',
    backgroundRepeat: '',
    backgroundPositon: '',
    opacity: '',
  }
  UNSAFE_componentWillMount () {
@@ -36,7 +41,10 @@
    this.setState({
      backgroundColor: config.style.backgroundColor,
      backgroundImage: bgImg
      backgroundImage: bgImg,
      backgroundSize: config.style.backgroundSize || '100%',
      backgroundRepeat: config.style.backgroundRepeat || 'repeat',
      backgroundPositon: config.style.backgroundPositon || 'center'
    })
  }
@@ -84,9 +92,42 @@
    this.props.updateConfig(config)
  }
  backgroundSizeChange = (val) => {
    this.setState({
      backgroundSize: val
    })
    let config = fromJS(this.props.config).toJS()
    config.style.backgroundSize = val
    this.props.updateConfig(config)
  }
  backgroundRepeatChange = (val) => {
    this.setState({
      backgroundRepeat: val
    })
    let config = fromJS(this.props.config).toJS()
    config.style.backgroundRepeat = val
    this.props.updateConfig(config)
  }
  backgroundPositonChange = (val) => {
    this.setState({
      backgroundPositon: val
    })
    let config = fromJS(this.props.config).toJS()
    config.style.backgroundPositon = val
    this.props.updateConfig(config)
  }
  render () {
    const { config } = this.props
    const { backgroundColor, backgroundImage } = this.state
    const { backgroundColor, backgroundImage, backgroundSize, backgroundRepeat, backgroundPositon } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -113,6 +154,30 @@
          <Form.Item colon={false} label="背景图">
            <SourceComponent value={backgroundImage} type="" placement="right" onChange={this.imgChange}/>
          </Form.Item>
          <Form.Item colon={false} label="比例">
            <Select defaultValue={backgroundSize} onChange={this.backgroundSizeChange}>
              <Option value="100%">100%</Option>
              <Option value="100% 100%">100% 100%</Option>
              <Option value="auto 100%">auto 100%</Option>
              <Option value="contain">contain</Option>
              <Option value="cover">cover</Option>
            </Select>
          </Form.Item>
          <Form.Item colon={false} label="重复">
            <Select defaultValue={backgroundRepeat} onChange={this.backgroundRepeatChange}>
              <Option value="repeat">repeat</Option>
              <Option value="no-repeat">no-repeat</Option>
              <Option value="repeat-x">repeat-x</Option>
              <Option value="repeat-y">repeat-y</Option>
            </Select>
          </Form.Item>
          <Form.Item colon={false} label="位置">
            <Select defaultValue={backgroundPositon} onChange={this.backgroundPositonChange}>
              <Option value="center">center</Option>
              <Option value="top">top</Option>
              <Option value="bottom">bottom</Option>
            </Select>
          </Form.Item>
          <p style={{borderBottom: '1px solid #eaeaea', color: '#40a9ff'}}>内边距</p>
          <Form.Item
            colon={false}