king
2021-01-29 d62c168d0656fac4242581609c3c5c0d88cf6a48
src/menu/bgcontroller/index.jsx
@@ -1,13 +1,15 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Form, Input } from 'antd'
import { Form } from 'antd'
import zhCN from '@/locales/zh-CN/mob.js'
import enUS from '@/locales/en-US/mob.js'
import ColorSketch from '@/mob/colorsketch'
import FileUpload from '@/tabviews/zshare/fileupload'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
const ColorSketch = asyncComponent(() => import('@/mob/colorsketch'))
const SourceComponent = asyncComponent(() => import('@/menu/components/share/sourcecomponent'))
class MobController extends Component {
  static propTpyes = {
@@ -19,7 +21,6 @@
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    backgroundColor: '',
    backgroundImage: '',
    bgimages: [],
  }
  UNSAFE_componentWillMount () {
@@ -27,10 +28,7 @@
    let bgImg = config.style.backgroundImage || ''
    if (bgImg && /^linear-gradient/.test(bgImg)) {
      bgImg = bgImg.replace('linear-gradient(', '')
      bgImg = bgImg.replace(')', '')
    } else if (bgImg && /^url/.test(bgImg)) {
    if (bgImg && /^url/.test(bgImg)) {
      bgImg = bgImg.replace('url(', '')
      bgImg = bgImg.replace(')', '')
    }
@@ -59,45 +57,23 @@
    this.props.updateConfig(config)
  }
  /**
   * @description 手动修改路径
   */
  changeImage = (e) => {
    let val = e.target.value
  imgChange = (val) => {
    this.setState({
      backgroundImage: val
    })
    let config = fromJS(this.props.config).toJS()
    val = val.replace(/^\s*|\s*$/ig, '')
    if (/^http|^\/\//.test(val)) {
      val = `url(${val})`
    } else if (/,/ig.test(val) && !/^(radial-gradient|linear-gradient)/ig.test(val)) {
      val = `linear-gradient(${val})`
    if (val) {
      config.style.backgroundImage = `url(${val})`
    } else {
      delete config.style.backgroundImage
    }
    config.style.backgroundImage = val
    this.props.updateConfig(config)
  }
  imgChange = (list) => {
    if (list[0] && list[0].response) {
      this.setState({
        bgimages: [],
        backgroundImage: list[0].response
      })
      let config = fromJS(this.props.config).toJS()
      config.style.backgroundImage = `url(${list[0].response})`
      this.props.updateConfig(config)
    } else {
      this.setState({bgimages: list})
    }
  }
  render () {
    const { backgroundColor, backgroundImage, bgimages } = this.state
    const { backgroundColor, backgroundImage } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -116,8 +92,7 @@
            <ColorSketch value={backgroundColor} onChange={this.changeBackgroundColor} />
          </Form.Item>
          <Form.Item colon={false} label="图片">
            <FileUpload accept=".jpg,.png,.gif,.svg" value={bgimages} maxFile={2} fileType="text" onChange={this.imgChange}/>
            <Input placeholder="" value={backgroundImage} autoComplete="off" onChange={this.changeImage}/>
            <SourceComponent value={backgroundImage} type="" placement="right" onChange={this.imgChange}/>
          </Form.Item>
        </Form>
      </div>