king
2021-09-17 c95918fb0fffb61b1117fbf4cd429e291b9594d0
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Radio } from 'antd'
 
import FileUpload from '@/tabviews/zshare/fileupload'
import './index.scss'
 
const { TextArea } = Input
 
class MainSearch extends Component {
  static propTpyes = {
    card: PropTypes.object,
    inputSubmit: PropTypes.func // 回车事件
  }
 
  state = {
    linkurl: '',
    plusType: 'upload'
  }
 
  handleConfirm = () => {
    const { card } = this.props
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          if (values.urls) {
            values.linkurl = values.urls
          } else if (card.typecharone === 'color' && /^[0-9a-f]{6}$/.test(values.linkurl)) {
            values.linkurl = '#' + values.linkurl
          }
          resolve(values)
        } else {
          reject(err)
        }
      })
    })
  }
 
  changeType = (val) => {
    let _url = ''
 
    if (val === 'input') {
      _url = this.props.form.getFieldValue('urls') || ''
    }
    
    this.setState({plusType: val, linkurl: _url})
  }
 
  render() {
    const { getFieldDecorator } = this.props.form
    const { card } = this.props
    const { linkurl, plusType } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      }
    }
    return (
      <Form {...formItemLayout} className="picture-edit-model-form">
        <Row gutter={24}>
          {!card.id && card.typecharone !== 'color' ? <Col span={24}>
            <Form.Item label="添加方式">
              <Radio.Group value={plusType} onChange={(e) => {this.changeType(e.target.value)}} disabled={false}>
                <Radio value="upload">上传</Radio>
                <Radio value="input">地址输入</Radio>
              </Radio.Group>
            </Form.Item>
          </Col> : null}
          {!card.id && card.typecharone === 'image' && plusType === 'upload' ? <Col span={24}>
            <Form.Item label="图片上传">
              {getFieldDecorator('urls', {
                initialValue: '',
                rules: [
                  {
                    required: true,
                    message: '请上传图片!'
                  }
                ]
              })(
                <FileUpload config={{
                  initval: '',
                  suffix: '.jpg,.png,.gif,.pjp,.pjpeg,.jpeg,.jfif,.webp,.ico',
                  maxfile: 1,
                  fileType: 'picture'
                }} />
              )}
            </Form.Item>
          </Col> : null}
          {!card.id && card.typecharone === 'video' && plusType === 'upload' ? <Col span={24}>
            <Form.Item label="视频上传">
              {getFieldDecorator('urls', {
                initialValue: '',
                rules: [
                  {
                    required: true,
                    message: '请上传视频!'
                  }
                ]
              })(
                <FileUpload config={{
                  initval: '',
                  suffix: '.mp4,.webm,.ogg',
                  maxfile: 1,
                  fileType: 'text'
                }}/>
              )}
            </Form.Item>
          </Col> : null}
          {!card.id && card.typecharone !== 'color' && plusType === 'input' ? <Col span={24}>
            <Form.Item label="地址">
              {getFieldDecorator('linkurl', {
                initialValue: linkurl,
                rules: [
                  {
                    required: true,
                    message: '请添加地址信息!'
                  },
                  {
                    max: 1024,
                    message: '地址最多1024个字符!'
                  }
                ]
              })(<TextArea autoSize={{ minRows: 3 }} onPressEnter={() => this.props.inputSubmit()}/>)}
            </Form.Item>
          </Col> : null}
          {card.id && card.typecharone !== 'color' ? <Col span={24}>
            <Form.Item label="地址">
              <TextArea value={card.linkurl} readOnly={true} autoSize={{ minRows: 3 }} />
            </Form.Item>
          </Col> : null}
          {card.typecharone === 'color' ? <Col span={24}>
            <Form.Item label="色值">
              {getFieldDecorator('linkurl', {
                initialValue: '',
                rules: [
                  {
                    required: true,
                    message: '请填写色值!'
                  },
                  {
                    max: 100,
                    message: '色值最多100个字符!'
                  }
                ]
              })(<Input onPressEnter={() => this.props.inputSubmit()}/>)}
            </Form.Item>
          </Col> : null}
          <Col span={24}>
            <Form.Item label="备注">
              {getFieldDecorator('remark', {
                initialValue: card.remark || '',
                rules: [
                  {
                    max: 50,
                    message: '备注最多50个字符!'
                  }
                ]
              })(<TextArea autoSize={{ minRows: 4 }} onPressEnter={() => this.props.inputSubmit()}/>)}
            </Form.Item>
          </Col>
        </Row>
      </Form>
    )
  }
}
 
export default Form.create()(MainSearch)