From 89ee68c59cdcaa4b7fa0178be42d58bec651ee73 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 09 七月 2020 12:15:03 +0800 Subject: [PATCH] 2020-07-09 --- src/mob/controller/index.jsx | 68 +++++++++++++++++++++++++++++---- 1 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/mob/controller/index.jsx b/src/mob/controller/index.jsx index 6e9ebc0..c6f5e17 100644 --- a/src/mob/controller/index.jsx +++ b/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> -- Gitblit v1.8.0