king
2021-06-24 95afd40fc2741ac0ce59c2091f6cfce1f98877d4
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Col, Row } from 'antd'
 
import './index.scss'
 
class CheckCard extends Component {
  static propTpyes = {
    config: PropTypes.object,    // 表单配置信息
    onChange: PropTypes.func,    // 数据切换
  }
 
  state = {}
 
  getCards = () => {
    const { display, width, options, fields, ratio, picratio, backgroundColor, borderColor } = this.props.config
 
    let _ratio = picratio || ratio
    let paddingTop = '100%'
    if (_ratio === '4:3') {
      paddingTop = '75%'
    } else if (_ratio === '3:2') {
      paddingTop = '66.7%'
    } else if (_ratio === '16:9') {
      paddingTop = '56.25%'
    }
 
    let style = {}
    
    if (borderColor) {
      style.borderColor = borderColor
    }
 
    if (display !== 'picture') {
      if (backgroundColor) {
        style.backgroundColor = backgroundColor
      }
      if (!options || options.length === 0) {
        return <Col span={width}>
          <div className="card-cell" style={style}>
            {fields ? fields.map(col => {
              return <span key={col.key} style={{color: col.color, fontSize: col.fontSize + 'px', height: col.fontSize * 1.5 + 'px', textAlign: col.align}}>{col.field}</span>
            }) : null}
            {!fields || fields.length === 0 ? <span style={{color: '#000000', fontSize: '14px', height: '21px'}}>示例</span> : null}
          </div>
        </Col>
      }
      return options.map(item => {
        return <Col span={width} key={item.key}>
          <div className="card-cell" style={style}>
            {fields.map(col => {
              return <span key={col.key} style={{color: col.color, fontSize: col.fontSize + 'px', height: col.fontSize * 1.5 + 'px', textAlign: col.align}}>{item[col.field]}</span>
            })}
          </div>
        </Col>
      })
    } else {
      if (!options || options.length === 0) {
        return <Col span={width}>
          <div className="card-pic-cell" style={{...style, paddingTop, background: '#91d5ff'}}>
          </div>
        </Col>
      }
      return options.map(item => {
        return <Col span={width} key={item.key}>
          <div className="card-pic-cell" style={{...style, paddingTop, backgroundImage: `url(${item.$url})`}}>
          </div>
        </Col>
      })
    }
  }
 
  render() {
    return (
      <div className="check-card-edit-box" style={{marginTop: '10px'}}>
        <Row gutter={12}>{this.getCards()}</Row>
      </div>
    )
  }
}
 
export default CheckCard