king
2020-07-06 e0e5aa28cbd509579c7a83672a93241c9a5ed7e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Collapse, Form, Input, Col, Icon, InputNumber, Select, Radio } from 'antd'
 
import zhCN from '@/locales/zh-CN/mob.js'
import enUS from '@/locales/en-US/mob.js'
import ColorSketch from '@/mob/colorsketch'
import './index.scss'
 
const { Panel } = Collapse
const { Option } = Select
 
class MobController extends Component {
  static propTpyes = {
    editElem: PropTypes.any,
    updateStyle: PropTypes.func,
  }
 
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    card: null,
    fontColor: '#000000',
    backgroundColor: '#ffffff'
  }
 
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (!is(fromJS(this.props.editElem), fromJS(nextProps.editElem))) {
      this.setState({
        card: null
      }, () => {
        if (!nextProps.editElem) return
        let _card = fromJS(nextProps.editElem).toJS()
 
        this.setState({
          card: _card,
          fontColor: _card.color || '#000000',
          backgroundColor: _card.backgroundColor || '#ffffff'
        })
      })
    }
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 字体大小切换,超出范围忽略
   */
  changeFontSize = (val) => {
    const { card } = this.state
    let value = parseInt(val)
 
    if (isNaN(value) || value < 12 || value > 100) return
 
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {fontSize: `${value}px`}})
  }
 
  /**
   * @description 修改行间距,超出范围忽略
   */
  changeLineHeight = (val) => {
    const { card } = this.state
    let value = parseFloat(val)
 
    if (isNaN(value) || value < 1 || value > 10) return
 
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {lineHeight: value}})
  }
 
  /**
   * @description 字体间距修改,超出范围忽略
   */
  changeLetterSpacing = (val) => {
    const { card } = this.state
    let value = parseFloat(val)
 
    if (isNaN(value) || value < 0 || value > 100) return
 
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {letterSpacing: `${value}px`}})
  }
 
  /**
   * @description 修改字体粗细
   */
  boldChange = (val) => {
    const { card } = this.state
 
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {fontWeight: val}})
  }
 
  /**
   * @description 修改字体颜色 ,颜色控件
   */
  changeFontColor = (val) => {
    const { card } = this.state
 
    this.setState({
      fontColor: val
    })
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {color: val}})
  }
 
  /**
   * @description 修改字体颜色 ,手动输入
   */
  changeFontColorInput = (e) => {
    this.setState({
      fontColor: e.target.value
    })
  }
 
  /**
   * @description 字体对齐
   */
  changeTextAlign = (e) => {
    const { card } = this.state
 
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {textAlign: e.target.value}})
  }
 
  /**
   * @description 字体样式,倾斜
   */
  changeFontStyle = (e) => {
    const { card } = this.state
 
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {fontStyle: e.target.value}})
  }
 
  /**
   * @description 字体装饰,下划线、贯穿线、上划线
   */
  changeTextDecoration = (e) => {
    const { card } = this.state
 
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {textDecoration: e.target.value}})
  }
 
  /**
   * @description 修改背景颜色 ,颜色控件
   */
  changeBackgroundColor = (val) => {
    const { card } = this.state
 
    this.setState({
      backgroundColor: val
    })
    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {backgroundColor: val}})
  }
 
  /**
   * @description 修改字体颜色 ,手动输入
   */
  changeBackgroundColorInput = (e) => {
    this.setState({
      backgroundColor: e.target.value
    })
  }
 
  render () {
    const { card, fontColor, backgroundColor } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      }
    }
 
    return (
      <div className="mob-controller">
        <Form {...formItemLayout}>
          {card ? <Collapse expandIconPosition="right" defaultActiveKey={card.items[0]} accordion={true}>
            {card.items.includes('font') ? <Panel header="字体" key="font">
              <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>
              <Col span={12}>
                <Form.Item colon={false} label={<Icon title="字体粗细" type="bold" />}>
                  <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={12}>
                <Form.Item colon={false} label={<Icon title="行间距" type="line-height" />}>
                  <InputNumber defaultValue={card.lineHeight || 1.5} min={1} max={10} precision={1} onChange={this.changeLineHeight} />
                </Form.Item>
              </Col>
              <Col span={12}>
                <Form.Item colon={false} label={<Icon title="字间距" type="column-width" />}>
                  <InputNumber defaultValue={card.letterSpacing || 0} min={0} max={100} precision={0} onChange={this.changeLetterSpacing}/>
                </Form.Item>
              </Col>
              <Col span={24}>
                <Form.Item
                  colon={false}
                  label={<Icon title="字体颜色" type="font-colors" />}
                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                >
                  <ColorSketch color={card.color || '#000000'} changeColor={this.changeFontColor} />
                  <Input value={fontColor} onChange={this.changeFontColorInput} />
                </Form.Item>
              </Col>
              <Col span={24}>
                <Form.Item
                  colon={false}
                  label={' '}
                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                >
                  <Radio.Group defaultValue={card.fontStyle || 'normal'} onChange={this.changeFontStyle}>
                    <Radio.Button value="normal"><span title="标准">N</span></Radio.Button>
                    <Radio.Button value="italic"><Icon title="斜体" type="italic" /></Radio.Button>
                    <Radio.Button value="oblique" style={{fontStyle: 'oblique'}}><span title="倾斜">B</span></Radio.Button>
                  </Radio.Group>
                </Form.Item>
              </Col>
              <Col span={24}>
                <Form.Item
                  colon={false}
                  label={' '}
                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                >
                  <Radio.Group className="text-align" defaultValue={card.textAlign || 'left'} onChange={this.changeTextAlign}>
                    <Radio.Button value="left"><Icon title="左对齐" type="align-left" /></Radio.Button>
                    <Radio.Button value="center"><Icon title="居中对齐" type="align-center" /></Radio.Button>
                    <Radio.Button value="right"><Icon title="右对齐" type="align-right" /></Radio.Button>
                  </Radio.Group>
                </Form.Item>
              </Col>
              <Col span={24}>
                <Form.Item
                  colon={false}
                  label={' '}
                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                >
                  <Radio.Group className="text-decoration" defaultValue={card.textDecoration || 'none'} onChange={this.changeTextDecoration}>
                    <Radio.Button value="none"><span title="标准">N</span></Radio.Button>
                    <Radio.Button value="underline"><Icon title="下划线" type="underline" /></Radio.Button>
                    <Radio.Button value="line-through"><Icon title="中划线" type="strikethrough" /></Radio.Button>
                    <Radio.Button value="overline" style={{textDecoration: 'overline'}}><span title="上划线">O</span></Radio.Button>
                  </Radio.Group>
                </Form.Item>
              </Col>
            </Panel> : null}
            {card.items.includes('background') ? <Panel header="背景" key="1">
              <Col span={24}>
                <Form.Item
                  colon={false}
                  label={<Icon title="背景颜色" type="bg-colors" />}
                  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} />
                </Form.Item>
              </Col>
              <Col span={24}>
                <Form.Item
                  colon={false}
                  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} />
                </Form.Item>
              </Col>
            </Panel> : null}
            <Panel header="边距" key="2">
              边距
            </Panel>
            <Panel header="其他" key="3">
              其他
            </Panel>
          </Collapse> : null}
        </Form>
      </div>
    )
  }
}
 
export default MobController