| | |
| | | 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 |
| | |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | card: null, |
| | | fontColor: '#000000', |
| | | backgroundColor: '#ffffff' |
| | | backgroundColor: '#ffffff', |
| | | bgimages: [] |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | |
| | | }, () => { |
| | | 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, |
| | | }) |
| | | }) |
| | | } |
| | |
| | | }) |
| | | } |
| | | |
| | | 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 }, |
| | |
| | | </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} |
| | |
| | | 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> |