king
2020-07-09 89ee68c59cdcaa4b7fa0178be42d58bec651ee73
src/mob/controller/index.jsx
@@ -6,6 +6,7 @@
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 './index.scss'
const { Panel } = Collapse
@@ -21,7 +22,8 @@
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    card: null,
    fontColor: '#000000',
    backgroundColor: '#ffffff'
    backgroundColor: '#ffffff',
    bgimages: []
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
@@ -31,11 +33,21 @@
      }, () => {
        if (!nextProps.editElem) return
        let _card = fromJS(nextProps.editElem).toJS()
        let bgImg = _card.backgroundImage || ''
        if (bgImg && /^linear-gradient/.test(bgImg)) {
          bgImg = bgImg.replace('linear-gradient(', '')
          bgImg = bgImg.replace(')', '')
        } else if (bgImg && /^url/.test(bgImg)) {
          bgImg = bgImg.replace('url(', '')
          bgImg = bgImg.replace(')', '')
        }
        this.setState({
          card: _card,
          fontColor: _card.color || '#000000',
          backgroundColor: _card.backgroundColor || '#ffffff'
          backgroundColor: _card.backgroundColor || '#ffffff',
          backgroundImage: bgImg,
        })
      })
    }
@@ -159,8 +171,42 @@
    })
  }
  imgChange = (list) => {
    const { card } = this.state
    if (list[0] && list[0].response) {
      this.setState({
        bgimages: [],
        backgroundImage: list[0].response
      })
      this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {backgroundImage: `url(${list[0].response})`}})
    } else {
      this.setState({bgimages: list})
    }
  }
  changeBackgroundImageInput = (e) => {
    this.setState({
      backgroundImage: e.target.value
    })
  }
  submitBackgroundImage = (e) => {
    const { card } = this.state
    let val = e.target.value
    val = val.replace(/^\s*|\s*$/ig, '')
    if (/^http|^\/\//.test(val)) {
      val = `url(${val})`
    } else if (/^#|,/ig.test(val)) {
      val = `linear-gradient(${val})`
    }
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {backgroundImage: val}})
  }
  render () {
    const { card, fontColor, backgroundColor } = this.state
    const { card, fontColor, backgroundColor, backgroundImage, bgimages } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -262,7 +308,7 @@
                </Form.Item>
              </Col>
            </Panel> : null}
            {card.items.includes('background') ? <Panel header="背景" key="1">
            {card.items.includes('background') ? <Panel header="背景" key="background">
              <Col span={24}>
                <Form.Item
                  colon={false}
@@ -279,14 +325,18 @@
                  label={<Icon title="背景图片" type="picture" />}
                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                >
                  <ColorSketch color={card.backgroundColor || '#ffffff'} changeColor={this.changeBackgroundColor} />
                  <Input value={backgroundColor} onChange={this.changeBackgroundColorInput} />
                  <FileUpload value={bgimages} maxFile={2} fileType="text" onChange={this.imgChange}/>
                  <Input placeholder="" value={backgroundImage} autoComplete="off" onBlur={this.submitBackgroundImage} onPressEnter={this.submitBackgroundImage} onChange={this.changeBackgroundImageInput} />
                </Form.Item>
              </Col>
            </Panel> : null}
            <Panel header="边距" key="2">
              边距
            </Panel>
            {card.items.includes('border') ? <Panel header="边框" key="border">
              <Col span={12}>
                <Form.Item colon={false} label={<Icon title="字体大小" type="font-size" />}>
                  <InputNumber defaultValue={card.fontSize || 14} min={12} max={100} precision={0} onChange={this.changeFontSize} />
                </Form.Item>
              </Col>
            </Panel> : null}
            <Panel header="其他" key="3">
              其他
            </Panel>