king
2023-06-16 e4666c46c685ec7eabff25af9890d54c0ff2952b
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Form, Select, Input } from 'antd'
import { ArrowUpOutlined, ArrowDownOutlined, ArrowLeftOutlined, ArrowRightOutlined, BgColorsOutlined, ColumnWidthOutlined } from '@ant-design/icons'
 
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
 
const ColorSketch = asyncComponent(() => import('@/mob/colorsketch'))
const StyleInput = asyncComponent(() => import('@/menu/stylecontroller/styleInput'))
const SysColorSketch = asyncComponent(() => import('@/menu/stylecontroller/syscolorsketch'))
const SourceComponent = asyncComponent(() => import('@/menu/components/share/sourcecomponent'))
const { Option } = Select
 
class MobController extends Component {
  static propTpyes = {
    config: PropTypes.any,
    updateConfig: PropTypes.func,
  }
 
  state = {
    background: '',
    backgroundColor: '',
    backgroundImage: '',
    backgroundSize: '',
    backgroundRepeat: '',
    backgroundPosition: '',
    opacity: '',
  }
 
  UNSAFE_componentWillMount () {
    const { config } = this.props
 
    let bgImg = config.style.backgroundImage || ''
 
    if (bgImg && /^url/.test(bgImg)) {
      bgImg = bgImg.replace('url(', '')
      bgImg = bgImg.replace(')', '')
    }
 
    this.setState({
      background: config.style.background || '',
      backgroundColor: config.style.backgroundColor,
      backgroundImage: bgImg,
      backgroundSize: config.style.backgroundSize || '100%',
      backgroundRepeat: config.style.backgroundRepeat || 'repeat',
      backgroundPosition: config.style.backgroundPosition || 'center'
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 修改背景颜色 ,颜色控件
   */
  changeBackgroundColor = (val) => {
    let config = fromJS(this.props.config).toJS()
 
    this.setState({
      backgroundColor: val
    })
 
    config.style.backgroundColor = val
    this.props.updateConfig(config)
  }
 
  /**
   * @description 修改背景颜色 ,颜色控件
   */
  changePadding = (val, type) => {
    let config = fromJS(this.props.config).toJS()
 
    config.style[type] = val
    this.props.updateConfig(config)
  }
 
 
  imgChange = (val) => {
    this.setState({
      backgroundImage: val
    })
 
    let config = fromJS(this.props.config).toJS()
 
    if (val) {
      config.style.backgroundImage = `url(${val})`
    } else {
      delete config.style.backgroundImage
    }
    this.props.updateConfig(config)
  }
 
  backgroundSizeChange = (val) => {
    this.setState({
      backgroundSize: val
    })
 
    let config = fromJS(this.props.config).toJS()
    config.style.backgroundSize = val
 
    this.props.updateConfig(config)
  }
 
  backgroundRepeatChange = (val) => {
    this.setState({
      backgroundRepeat: val
    })
 
    let config = fromJS(this.props.config).toJS()
    config.style.backgroundRepeat = val
 
    this.props.updateConfig(config)
  }
 
  backgroundPositonChange = (val) => {
    this.setState({
      backgroundPosition: val
    })
 
    let config = fromJS(this.props.config).toJS()
    config.style.backgroundPosition = val
 
    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)
    }
  }
 
  /**
   * @description 修改阴影颜色 ,颜色控件
   */
  changeShadowColor = (val) => {
    let config = fromJS(this.props.config).toJS()
    config.style.shadowColor = val
    config.style.boxShadow = `${config.style.hShadow || '0px'} ${config.style.vShadow || '0px'} ${config.style.shadowBlur || '0px'} ${config.style.shadowColor || 'transparent'}`
 
    this.props.updateConfig(config)
  }
 
  /**
   * @description 修改阴影颜色 ,颜色控件
   */
  changeShadowBlur = (val) => {
    let config = fromJS(this.props.config).toJS()
    config.style.shadowBlur = val
    config.style.boxShadow = `${config.style.hShadow || '0px'} ${config.style.vShadow || '0px'} ${config.style.shadowBlur || '0px'} ${config.style.shadowColor || 'transparent'}`
 
    this.props.updateConfig(config)
  }
 
  /**
   * @description 修改阴影颜色 ,颜色控件
   */
  changeHShadow = (val) => {
    let config = fromJS(this.props.config).toJS()
    config.style.hShadow = val
    config.style.boxShadow = `${config.style.hShadow || '0px'} ${config.style.vShadow || '0px'} ${config.style.shadowBlur || '0px'} ${config.style.shadowColor || 'transparent'}`
 
    this.props.updateConfig(config)
  }
 
  /**
   * @description 修改阴影颜色 ,颜色控件
   */
  changeVShadow = (val) => {
    let config = fromJS(this.props.config).toJS()
    config.style.vShadow = val
    config.style.boxShadow = `${config.style.hShadow || '0px'} ${config.style.vShadow || '0px'} ${config.style.shadowBlur || '0px'} ${config.style.shadowColor || 'transparent'}`
 
    this.props.updateConfig(config)
  }
 
  render () {
    const { config, type } = this.props
    const { backgroundColor, backgroundImage, backgroundSize, backgroundRepeat, backgroundPosition, background } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 19 }
      }
    }
 
    return (
      <div className="pc-style-controller">
        <Form {...formItemLayout}>
          {/* <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 className="color-control" style={{marginBottom: '0px'}} colon={false} label="背景色">
            <ColorSketch value={backgroundColor} onChange={this.changeBackgroundColor} />
          </Form.Item>
          <Form.Item colon={false} label="系统色">
            <SysColorSketch 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>
          <Form.Item colon={false} label="比例">
            <Select defaultValue={backgroundSize} onChange={this.backgroundSizeChange}>
              <Option value="100%">100%</Option>
              <Option value="100% 100%">100% 100%</Option>
              <Option value="auto 100%">auto 100%</Option>
              <Option value="100% auto">100% auto</Option>
              <Option value="auto">auto</Option>
              <Option value="contain">contain</Option>
              <Option value="cover">cover</Option>
            </Select>
          </Form.Item>
          <Form.Item colon={false} label="重复">
            <Select defaultValue={backgroundRepeat} onChange={this.backgroundRepeatChange}>
              <Option value="repeat">repeat</Option>
              <Option value="no-repeat">no-repeat</Option>
              <Option value="repeat-x">repeat-x</Option>
              <Option value="repeat-y">repeat-y</Option>
            </Select>
          </Form.Item>
          <Form.Item colon={false} label="位置">
            <Select defaultValue={backgroundPosition} onChange={this.backgroundPositonChange}>
              <Option value="center">center</Option>
              <Option value="top">top</Option>
              <Option value="bottom">bottom</Option>
            </Select>
          </Form.Item>
          {type === 'mob_popview' ? <p className="normal-view" style={{borderBottom: '1px solid #eaeaea', color: '#40a9ff'}}>阴影</p> : null}
          {type === 'mob_popview' ? <>
            <Form.Item colon={false} label={<BgColorsOutlined title="阴影颜色"/>}>
              <ColorSketch value={config.style.shadowColor || 'transparent'} onChange={this.changeShadowColor} />
            </Form.Item>
            <Form.Item colon={false} label={<BgColorsOutlined title="系统色"/>}>
              <SysColorSketch onChange={this.changeShadowColor} />
            </Form.Item>
            <Form.Item colon={false} label={<ColumnWidthOutlined title="模糊距离"/>}>
              <StyleInput defaultValue={config.style.shadowBlur || '0px'} options={['px']} onChange={this.changeShadowBlur}/>
            </Form.Item>
            <Form.Item colon={false} label={<ArrowRightOutlined title="水平位置"/>}>
              <StyleInput defaultValue={config.style.hShadow || '0px'} options={['px']} onChange={this.changeHShadow}/>
            </Form.Item>
            <Form.Item colon={false} label={<ArrowDownOutlined title="垂直位置"/>}>
              <StyleInput defaultValue={config.style.vShadow || '0px'} options={['px']} onChange={this.changeVShadow}/>
            </Form.Item>
          </> : null}
          <p className="normal-view" style={{borderBottom: '1px solid #eaeaea', color: '#40a9ff'}}>内边距</p>
          <Form.Item
            colon={false}
            className="normal-view"
            label={<ArrowUpOutlined title="上边距"/>}
          >
            <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')}/>
          </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')}/>
          </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')}/>
          </Form.Item>
          <p className="normal-view" style={{borderBottom: '1px solid #eaeaea', color: '#40a9ff'}}>外边距</p>
          <Form.Item
            colon={false}
            className="normal-view"
            label={<ArrowUpOutlined title="上边距"/>}
          >
            <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')}/>
          </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')}/>
          </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')}/>
          </Form.Item>
        </Form>
      </div>
    )
  }
}
 
export default MobController