From fa381753ef2a2b25b1c0722549ac17e333da79be Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 06 九月 2022 22:50:54 +0800 Subject: [PATCH] 2022-09-06 --- src/menu/stylecontroller/index.jsx | 171 ++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 110 insertions(+), 61 deletions(-) diff --git a/src/menu/stylecontroller/index.jsx b/src/menu/stylecontroller/index.jsx index 4c50043..b2bb476 100644 --- a/src/menu/stylecontroller/index.jsx +++ b/src/menu/stylecontroller/index.jsx @@ -1,7 +1,7 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Collapse, Form, Col, InputNumber, Select, Radio, Drawer, Button } from 'antd' +import { Collapse, Form, Col, InputNumber, Input, Select, Radio, Drawer, Button } from 'antd' import { ColumnHeightOutlined, FontSizeOutlined, @@ -29,6 +29,7 @@ ArrowLeftOutlined, ArrowRightOutlined, SwapOutlined, + EnterOutlined, } from '@ant-design/icons' import MKEmitter from '@/utils/events.js' @@ -49,11 +50,13 @@ state = { card: null, - comIds: [], + fonts: null, backgroundImage: '', options: [], borposition: 'outer' } + + callback = null shouldComponentUpdate (nextProps, nextState) { return !is(fromJS(this.state), fromJS(nextState)) @@ -73,20 +76,37 @@ MKEmitter.removeListener('changeStyle', this.initStyle) } - initStyle = (comIds, options, style = {}) => { + initStyle = (options, style = {}, callback) => { let backgroundImage = '' if (style.backgroundImage && /^url/ig.test(style.backgroundImage)) { backgroundImage = style.backgroundImage.replace(/^url\(/ig, '').replace(/\)$/ig, '') } + let fonts = null + if (options.includes('font')) { + fonts = ['fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'color', 'fontStyle', 'textAlign', 'textDecoration'] + } else if (options.includes('font1')) { + fonts = ['fontSize', 'fontWeight', 'color'] + if (options[0] === 'font1') { + options[0] = 'font' + } + } else if (options.includes('font2')) { + fonts = ['fontSize', 'fontWeight', 'lineHeight', 'letterSpacing', 'color', 'fontStyle', 'textAlign', 'textDecoration', 'textIndent', 'wordBreak'] + if (options[0] === 'font2') { + options[0] = 'font' + } + } + + this.callback = callback this.setState({ visible: true, - comIds: comIds, + fonts: fonts, card: fromJS(style).toJS(), options: options, borposition: 'outer', backgroundImage }) + window.GLOB.styling = true } onCloseDrawer = () => { @@ -116,20 +136,21 @@ } if (check) { - MKEmitter.emit('submitStyle', this.state.comIds, card) + this.callback && this.callback(card) } this.setState({ visible: false, - comIds: [], card: null, options: [], backgroundImage: '' }) + window.GLOB.styling = false + this.callback = null } updateStyle = (style) => { - const { comIds, card } = this.state + const { card } = this.state let _style = { ...card, @@ -140,7 +161,7 @@ card: _style, }) - MKEmitter.emit('submitStyle', comIds, _style) + this.callback && this.callback(_style) } /** @@ -183,10 +204,28 @@ } /** + * @description 棣栬缂╄繘 + */ + changeTextIndent = (val) => { + let value = parseFloat(val) + + if (isNaN(value) || value < 0 || value > 100) return + + this.updateStyle({textIndent: `${value}px`}) + } + + /** * @description 淇敼瀛椾綋绮楃粏 */ boldChange = (val) => { this.updateStyle({fontWeight: val}) + } + + /** + * @description 鑷姩鎹㈣ + */ + wordBreakChange = (val) => { + this.updateStyle({wordBreak: val}) } /** @@ -222,6 +261,29 @@ */ changeBackgroundColor = (val) => { this.updateStyle({backgroundColor: val}) + } + + changeBackground = (val) => { + const { card } = this.state + + let _style = { ...card } + + _style.background = val + + delete _style.backgroundColor + delete _style.backgroundImage + + if (!val) { + delete _style.background + } + + this.setState({ + card: _style, + }) + + if (!val || /(^linear-gradient|^radial-gradient)\(.*\)$/.test(val)) { + this.callback && this.callback(_style) + } } /** @@ -380,7 +442,7 @@ } render () { - const { card, options, backgroundImage, borposition } = this.state + const { card, options, backgroundImage, borposition, fonts } = this.state const formItemLayout = { labelCol: { xs: { span: 24 }, @@ -433,13 +495,13 @@ </Form.Item> </Col> </Panel> : null} - {options.includes('font') ? <Panel header="瀛椾綋" key="font"> - <Col span={12}> + {fonts ? <Panel header="瀛椾綋" key="font"> + {fonts.includes('fontSize') ? <Col span={12}> <Form.Item colon={false} label={<FontSizeOutlined title="瀛椾綋澶у皬"/>}> <InputNumber defaultValue={card.fontSize || 14} min={12} max={300} precision={0} onChange={this.changeFontSize} /> </Form.Item> - </Col> - <Col span={12}> + </Col> : null} + {fonts.includes('fontWeight') ? <Col span={12}> <Form.Item colon={false} label={<BoldOutlined title="瀛椾綋绮楃粏"/>}> <Select defaultValue={card.fontWeight || 'normal'} onChange={this.boldChange}> <Option value="normal">normal</Option> @@ -457,18 +519,31 @@ <Option value="900">900</Option> </Select> </Form.Item> - </Col> - <Col span={12}> + </Col> : null} + {fonts.includes('lineHeight') ? <Col span={12}> <Form.Item colon={false} label={<LineHeightOutlined title="琛岄珮"/>}> <InputNumber defaultValue={card.lineHeight || 1.5} min={1} max={10} precision={1} onChange={this.changeLineHeight} /> </Form.Item> - </Col> - <Col span={12}> + </Col> : null} + {fonts.includes('letterSpacing') ? <Col span={12}> <Form.Item colon={false} label={<ColumnWidthOutlined title="瀛楅棿璺�"/>}> <InputNumber defaultValue={card.letterSpacing || 0} min={0} max={100} precision={0} onChange={this.changeLetterSpacing}/> </Form.Item> - </Col> - <Col span={24}> + </Col> : null} + {fonts.includes('textIndent') ? <Col span={12}> + <Form.Item colon={false} label={<AlignRightOutlined title="棣栬缂╄繘"/>}> + <InputNumber defaultValue={card.textIndent || 0} min={0} max={100} precision={0} onChange={this.changeTextIndent}/> + </Form.Item> + </Col> : null} + {fonts.includes('wordBreak') ? <Col span={12}> + <Form.Item colon={false} label={<EnterOutlined title="鑷姩鎹㈣"/>}> + <Select defaultValue={card.wordBreak || 'normal'} onChange={this.wordBreakChange}> + <Option value="normal">normal</Option> + <Option value="break-all">break-all</Option> + </Select> + </Form.Item> + </Col> : null} + {fonts.includes('color') ? <Col span={24}> <Form.Item colon={false} label={<FontColorsOutlined title="瀛椾綋棰滆壊"/>} @@ -476,8 +551,8 @@ > <ColorSketch value={card.color || 'rgba(0, 0, 0, 0.85)'} onChange={this.changeFontColor} /> </Form.Item> - </Col> - <Col span={24}> + </Col> : null} + {fonts.includes('fontStyle') ? <Col span={24}> <Form.Item colon={false} label={' '} @@ -489,8 +564,8 @@ <Radio.Button value="oblique" style={{fontStyle: 'oblique'}}><span title="鍊炬枩">B</span></Radio.Button> </Radio.Group> </Form.Item> - </Col> - <Col span={24}> + </Col> : null} + {fonts.includes('textAlign') ? <Col span={24}> <Form.Item colon={false} label={' '} @@ -502,8 +577,8 @@ <Radio.Button value="right"><AlignRightOutlined title="鍙冲榻�"/></Radio.Button> </Radio.Group> </Form.Item> - </Col> - <Col span={24}> + </Col> : null} + {fonts.includes('textDecoration') ? <Col span={24}> <Form.Item colon={false} label={' '} @@ -516,42 +591,7 @@ <Radio.Button value="overline" style={{textDecoration: 'overline'}}><span title="涓婂垝绾�">O</span></Radio.Button> </Radio.Group> </Form.Item> - </Col> - </Panel> : null} - {options.includes('font1') ? <Panel header="瀛椾綋" key="font1"> - <Col span={12}> - <Form.Item colon={false} label={<FontSizeOutlined title="瀛椾綋澶у皬"/>}> - <InputNumber defaultValue={card.fontSize || 14} min={12} max={300} precision={0} onChange={this.changeFontSize} /> - </Form.Item> - </Col> - <Col span={12}> - <Form.Item colon={false} label={<BoldOutlined title="瀛椾綋绮楃粏"/>}> - <Select defaultValue={card.fontWeight || 'normal'} onChange={this.boldChange}> - <Option value="normal">normal</Option> - <Option value="bold">bold</Option> - <Option value="bolder">bolder</Option> - <Option value="lighter">lighter</Option> - <Option value="100">100</Option> - <Option value="200">200</Option> - <Option value="300">300</Option> - <Option value="400">400</Option> - <Option value="500">500</Option> - <Option value="600">600</Option> - <Option value="700">700</Option> - <Option value="800">800</Option> - <Option value="900">900</Option> - </Select> - </Form.Item> - </Col> - <Col span={24}> - <Form.Item - colon={false} - label={<FontColorsOutlined title="瀛椾綋棰滆壊"/>} - labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} } - > - <ColorSketch value={card.color || 'rgba(0, 0, 0, 0.85)'} onChange={this.changeFontColor} /> - </Form.Item> - </Col> + </Col> : null} </Panel> : null} {options.includes('background') || options.includes('backgroundColor') ? <Panel header="鑳屾櫙" key="background"> <Col span={24}> @@ -563,6 +603,15 @@ <ColorSketch value={card.backgroundColor || '#ffffff'} onChange={this.changeBackgroundColor} /> </Form.Item> </Col> + {window.develop === true ? <Col span={24}> + <Form.Item + colon={false} + label={<BgColorsOutlined title="鑳屾櫙棰滆壊"/>} + labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} } + > + <Input value={card.background || ''} onChange={(e) => this.changeBackground(e.target.value)} /> + </Form.Item> + </Col> : null} {!options.includes('backgroundColor') ? <Col span={24}> <Form.Item colon={false} -- Gitblit v1.8.0