From 316877c1d9e5b6d92334f30b03d97d7e833cd934 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 02 二月 2021 16:01:57 +0800 Subject: [PATCH] 2021-02-02 --- src/menu/bgcontroller/index.jsx | 51 +++++++++++++-------------------------------------- 1 files changed, 13 insertions(+), 38 deletions(-) diff --git a/src/menu/bgcontroller/index.jsx b/src/menu/bgcontroller/index.jsx index bb8b043..ab2155c 100644 --- a/src/menu/bgcontroller/index.jsx +++ b/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> -- Gitblit v1.8.0