king
2021-05-31 ce70be666bcd78a7e16e739040488cf7e7256cc2
src/menu/picturecontroller/editform/index.jsx
@@ -1,6 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Radio, notification } from 'antd'
import { Form, Row, Col, Input, Radio } from 'antd'
import FileUpload from '@/tabviews/zshare/fileupload'
import './index.scss'
@@ -14,7 +14,6 @@
  }
  state = {
    urls: [],
    linkurl: '',
    plusType: 'upload'
  }
@@ -24,29 +23,8 @@
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          if (values.urls && values.urls[0].status === 'error') {
            notification.warning({
              top: 92,
              message: '请重新上传文件!',
              duration: 5
            })
            return
          } else if (values.urls && values.urls[0] && values.urls[0].status !== 'done') {
            notification.warning({
              top: 92,
              message: '文件上传中,请稍后!',
              duration: 5
            })
            return
          } else if (values.urls && values.urls[0] && values.urls[0].response) {
            values.linkurl = values.urls[0].response
          } else {
            notification.warning({
              top: 92,
              message: '未获取到文件路径!',
              duration: 5
            })
            return
          if (values.urls) {
            values.linkurl = values.urls
          }
          resolve(values)
        } else {
@@ -57,28 +35,19 @@
  }
  changeType = (val) => {
    const { linkurl, urls } = this.state
    let _urls = this.props.form.getFieldValue('urls') || ''
    let _url = this.props.form.getFieldValue('linkurl') || ''
    let _url = ''
    if (val === 'input') {
      if (_urls && _urls[0] && _urls[0].status === 'done' && (_urls[0].url || _urls[0].response)) {
        _url = _urls[0].url || _urls[0].response
      } else {
        _url = linkurl || ''
      }
    } else {
      _urls = urls.filter(item => item.status === 'done')
      _url = linkurl
      _url = this.props.form.getFieldValue('urls') || ''
    }
    
    this.setState({plusType: val, urls: _urls, linkurl: _url})
    this.setState({plusType: val, linkurl: _url})
  }
  render() {
    const { getFieldDecorator } = this.props.form
    const { card } = this.props
    const { urls, linkurl, plusType } = this.state
    const { linkurl, plusType } = this.state
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
@@ -103,7 +72,7 @@
          {!card.id && card.typecharone === 'image' && plusType === 'upload' ? <Col span={24}>
            <Form.Item label="图片上传">
              {getFieldDecorator('urls', {
                initialValue: urls,
                initialValue: '',
                rules: [
                  {
                    required: true,
@@ -111,14 +80,19 @@
                  }
                ]
              })(
                <FileUpload accept=".jpg,.png,.gif,.pjp,.pjpeg,.jpeg,.jfif,.webp" maxFile={1} fileType={'picture'} />
                <FileUpload config={{
                  initval: '',
                  suffix: '.jpg,.png,.gif,.pjp,.pjpeg,.jpeg,.jfif,.webp',
                  maxfile: 1,
                  fileType: 'picture'
                }} />
              )}
            </Form.Item>
          </Col> : null}
          {!card.id && card.typecharone === 'video' && plusType === 'upload' ? <Col span={24}>
            <Form.Item label="视频上传">
              {getFieldDecorator('urls', {
                initialValue: urls,
                initialValue: '',
                rules: [
                  {
                    required: true,
@@ -126,7 +100,12 @@
                  }
                ]
              })(
                <FileUpload accept=".mp4,.webm,.ogg" maxFile={1} fileType={'text'} />
                <FileUpload config={{
                  initval: '',
                  suffix: '.mp4,.webm,.ogg',
                  maxfile: 1,
                  fileType: 'text'
                }}/>
              )}
            </Form.Item>
          </Col> : null}