| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Collapse, Form, Col, InputNumber, Input, Select, Radio, Drawer, Button } from 'antd' |
| | | import { Collapse, Form, Col, InputNumber, Input, Select, Radio, Drawer, Button, message } from 'antd' |
| | | import { |
| | | ColumnHeightOutlined, |
| | | FontSizeOutlined, |
| | |
| | | ArrowLeftOutlined, |
| | | ArrowRightOutlined, |
| | | SwapOutlined, |
| | | EnterOutlined, |
| | | EnterOutlined |
| | | } from '@ant-design/icons' |
| | | |
| | | import MKEmitter from '@/utils/events.js' |
| | |
| | | const { Panel } = Collapse |
| | | const { Option } = Select |
| | | const ColorSketch = asyncComponent(() => import('@/mob/colorsketch')) |
| | | const PasteBoard = asyncComponent(() => import('@/components/pasteboard')) |
| | | const SourceComponent = asyncComponent(() => import('@/menu/components/share/sourcecomponent')) |
| | | |
| | | class MobController extends Component { |
| | |
| | | this.updateStyle({[type]: val}) |
| | | } |
| | | |
| | | copy = () => { |
| | | const { card, options } = this.state |
| | | |
| | | let msg = { copyType: 'style' } |
| | | |
| | | msg.data = card |
| | | msg.options = options |
| | | |
| | | try { |
| | | msg = window.btoa(window.encodeURIComponent(JSON.stringify(msg))) |
| | | } catch (e) { |
| | | console.warn('Stringify Failure') |
| | | msg = '' |
| | | } |
| | | |
| | | if (msg) { |
| | | let oInput = document.createElement('input') |
| | | oInput.value = msg |
| | | document.body.appendChild(oInput) |
| | | oInput.select() |
| | | document.execCommand('Copy') |
| | | document.body.removeChild(oInput) |
| | | message.success('复制成功。') |
| | | } |
| | | } |
| | | |
| | | paste = (res, callback) => { |
| | | const { options } = this.state |
| | | |
| | | if (res.copyType !== 'style') { |
| | | message.warning('配置信息格式错误!', 5) |
| | | return |
| | | } else if (JSON.stringify(res.options) !== JSON.stringify(options)) { |
| | | message.warning('样式选项不一致,不可粘贴!', 5) |
| | | return |
| | | } |
| | | |
| | | let style = res.data || {} |
| | | |
| | | let backgroundImage = '' |
| | | if (style.backgroundImage && /^url/ig.test(style.backgroundImage)) { |
| | | backgroundImage = style.backgroundImage.replace(/^url\(/ig, '').replace(/\)$/ig, '') |
| | | } |
| | | |
| | | let borposition = 'outer' |
| | | |
| | | if (!style.borderWidth) { |
| | | if (style.borderLeftWidth) { |
| | | borposition = 'left' |
| | | } else if (style.borderRightWidth) { |
| | | borposition = 'right' |
| | | } else if (style.borderTopWidth) { |
| | | borposition = 'top' |
| | | } else if (style.borderBottomWidth) { |
| | | borposition = 'bottom' |
| | | } |
| | | } |
| | | |
| | | this.setState({ |
| | | card: style, |
| | | borposition, |
| | | backgroundImage |
| | | }) |
| | | |
| | | this.callback && this.callback(style) |
| | | |
| | | callback() |
| | | |
| | | message.success('粘贴成功。') |
| | | } |
| | | |
| | | render () { |
| | | const { card, options, backgroundImage, borposition, fonts, type } = this.state |
| | | const formItemLayout = { |
| | |
| | | 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} /> |
| | | <ColorSketch value={card.color || ''} onChange={this.changeFontColor} /> |
| | | </Form.Item> |
| | | <Form.Item |
| | | colon={false} |
| | |
| | | label={<BgColorsOutlined title="边框颜色"/>} |
| | | labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} } |
| | | > |
| | | {borposition === 'outer' ? <ColorSketch value={card.borderColor || 'transparent'} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'left' ? <ColorSketch value={card.borderLeftColor || 'transparent'} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'right' ? <ColorSketch value={card.borderRightColor || 'transparent'} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'top' ? <ColorSketch value={card.borderTopColor || 'transparent'} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'bottom' ? <ColorSketch value={card.borderBottomColor || 'transparent'} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'outer' ? <ColorSketch value={card.borderColor || ''} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'left' ? <ColorSketch value={card.borderLeftColor || ''} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'right' ? <ColorSketch value={card.borderRightColor || ''} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'top' ? <ColorSketch value={card.borderTopColor || ''} onChange={this.changeBorderColor} /> : null} |
| | | {borposition === 'bottom' ? <ColorSketch value={card.borderBottomColor || ''} onChange={this.changeBorderColor} /> : null} |
| | | </Form.Item> |
| | | <Form.Item |
| | | colon={false} |
| | |
| | | label={<BgColorsOutlined title="阴影颜色"/>} |
| | | labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} } |
| | | > |
| | | <ColorSketch value={card.shadowColor || 'transparent'} onChange={this.changeShadowColor} /> |
| | | <ColorSketch value={card.shadowColor || ''} onChange={this.changeShadowColor} /> |
| | | </Form.Item> |
| | | <Form.Item |
| | | colon={false} |
| | |
| | | </Panel> : null} |
| | | </Collapse> : null} |
| | | </Form> |
| | | <div style={{textAlign: 'right'}}> |
| | | <Button style={{margin: '30px 10px 30px 0px'}} onClick={this.onCloseDrawer}>关闭</Button> |
| | | <div style={{textAlign: 'right', lineHeight: '60px', marginBottom: '30px'}}> |
| | | <div style={{float: 'left'}}> |
| | | <Button onClick={() => this.copy()} className="mk-border-green" style={{marginRight: '10px'}}>复制</Button> |
| | | <PasteBoard getPasteValue={this.paste}><Button style={{borderColor: 'rgb(64, 169, 255)', color: 'rgb(64, 169, 255)'}}>粘贴</Button></PasteBoard> |
| | | </div> |
| | | <Button style={{marginRight: '10px'}} onClick={this.onCloseDrawer}>关闭</Button> |
| | | </div> |
| | | </div> |
| | | </Drawer> |