From cb9ade2afd2a367ad767bc605ab7086c695dd010 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 09 十二月 2022 15:53:32 +0800 Subject: [PATCH] 2022-12-09 --- src/pc/bgcontroller/index.jsx | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/pc/bgcontroller/index.jsx b/src/pc/bgcontroller/index.jsx index 88fdafa..35def8d 100644 --- a/src/pc/bgcontroller/index.jsx +++ b/src/pc/bgcontroller/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Form, Select } from 'antd' +import { Form, Select, Input } from 'antd' import { ArrowUpOutlined, ArrowDownOutlined, ArrowLeftOutlined, ArrowRightOutlined } from '@ant-design/icons' import asyncComponent from '@/utils/asyncComponent' @@ -19,6 +19,7 @@ } state = { + background: '', backgroundColor: '', backgroundImage: '', backgroundSize: '', @@ -38,6 +39,7 @@ } this.setState({ + background: config.style.background || '', backgroundColor: config.style.backgroundColor, backgroundImage: bgImg, backgroundSize: config.style.backgroundSize || '100%', @@ -123,9 +125,34 @@ this.props.updateConfig(config) } + changeBackground = (val) => { + this.setState({ + background: val, + }) + + if (!val || /(^linear-gradient|^radial-gradient)\(.*\)$/.test(val)) { + let config = fromJS(this.props.config).toJS() + config.style.background = val + + delete config.style.backgroundColor + delete config.style.backgroundImage + + if (!val) { + delete config.style.background + } + + this.setState({ + backgroundImage: '', + backgroundColor: '' + }) + + this.props.updateConfig(config) + } + } + render () { const { config } = this.props - const { backgroundColor, backgroundImage, backgroundSize, backgroundRepeat, backgroundPosition } = this.state + const { backgroundColor, backgroundImage, backgroundSize, backgroundRepeat, backgroundPosition, background } = this.state const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -140,16 +167,19 @@ return ( <div className="pc-style-controller"> <Form {...formItemLayout}> - <Form.Item + {/* <Form.Item colon={false} label="瀹藉害" className="normal-view" > <StyleInput defaultValue={config.style.width || '100%'} options={['px', '%', 'vw']} onChange={(val) => this.changePadding(val, 'width')}/> - </Form.Item> + </Form.Item> */} <Form.Item className="color-control" colon={false} label="鑳屾櫙鑹�"> <ColorSketch value={backgroundColor} onChange={this.changeBackgroundColor} /> </Form.Item> + {window.develop === true ? <Form.Item colon={false} label="棰滆壊"> + <Input value={background} onChange={(e) => this.changeBackground(e.target.value)} /> + </Form.Item> : null} <Form.Item colon={false} label="鑳屾櫙鍥�"> <SourceComponent value={backgroundImage} type="" placement="right" onChange={this.imgChange}/> </Form.Item> @@ -185,28 +215,28 @@ className="normal-view" label={<ArrowUpOutlined title="涓婅竟璺�"/>} > - <StyleInput defaultValue={config.style.paddingTop || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'paddingTop')}/> + <StyleInput defaultValue={config.style.paddingTop || '0px'} options={['px', '%', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'paddingTop')}/> </Form.Item> <Form.Item colon={false} className="normal-view" label={<ArrowDownOutlined title="涓嬭竟璺�"/>} > - <StyleInput defaultValue={config.style.paddingBottom || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'paddingBottom')}/> + <StyleInput defaultValue={config.style.paddingBottom || '0px'} options={['px', '%', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'paddingBottom')}/> </Form.Item> <Form.Item colon={false} className="normal-view" label={<ArrowLeftOutlined title="宸﹁竟璺�"/>} > - <StyleInput defaultValue={config.style.paddingLeft || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'paddingLeft')}/> + <StyleInput defaultValue={config.style.paddingLeft || '0px'} options={['px', '%', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'paddingLeft')}/> </Form.Item> <Form.Item colon={false} className="normal-view" label={<ArrowRightOutlined title="鍙宠竟璺�"/>} > - <StyleInput defaultValue={config.style.paddingRight || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'paddingRight')}/> + <StyleInput defaultValue={config.style.paddingRight || '0px'} options={['px', '%', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'paddingRight')}/> </Form.Item> <p className="normal-view" style={{borderBottom: '1px solid #eaeaea', color: '#40a9ff'}}>澶栬竟璺�</p> <Form.Item @@ -214,28 +244,28 @@ className="normal-view" label={<ArrowUpOutlined title="涓婅竟璺�"/>} > - <StyleInput defaultValue={config.style.marginTop || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'marginTop')}/> + <StyleInput defaultValue={config.style.marginTop || '0px'} options={['px', '%', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'marginTop')}/> </Form.Item> <Form.Item colon={false} className="normal-view" label={<ArrowDownOutlined title="涓嬭竟璺�"/>} > - <StyleInput defaultValue={config.style.marginBottom || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'marginBottom')}/> + <StyleInput defaultValue={config.style.marginBottom || '0px'} options={['px', '%', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'marginBottom')}/> </Form.Item> <Form.Item colon={false} className="normal-view" label={<ArrowLeftOutlined title="宸﹁竟璺�"/>} > - <StyleInput defaultValue={config.style.marginLeft || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'marginLeft')}/> + <StyleInput defaultValue={config.style.marginLeft || '0px'} options={['px', '%', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'marginLeft')}/> </Form.Item> <Form.Item colon={false} className="normal-view" label={<ArrowRightOutlined title="鍙宠竟璺�"/>} > - <StyleInput defaultValue={config.style.marginRight || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'marginRight')}/> + <StyleInput defaultValue={config.style.marginRight || '0px'} options={['px', '%', 'vh', 'vw']} onChange={(val) => this.changePadding(val, 'marginRight')}/> </Form.Item> </Form> </div> -- Gitblit v1.8.0