| | |
| | | class FileUpload extends Component { |
| | | static propTpyes = { |
| | | value: PropTypes.array, // 文件数组 |
| | | accept: PropTypes.any, // 文件格式 |
| | | maxFile: PropTypes.any, // 最大文件数 |
| | | fileType: PropTypes.string // 文件显示类型 |
| | | } |
| | |
| | | } |
| | | |
| | | beforeUpload = (file) => { |
| | | const { accept } = this.props |
| | | |
| | | if (accept && file.name) { |
| | | let types = accept.split(',') |
| | | let pass = false |
| | | types.forEach(type => { |
| | | if (new RegExp(type + '$', 'ig').test(file.name)) { |
| | | pass = true |
| | | } |
| | | }) |
| | | |
| | | if (!pass) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '文件格式错误!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | } |
| | | |
| | | this.setState({ |
| | | showprogress: true, |
| | | percent: 0 |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { value, maxFile, fileType } = this.props |
| | | const { value, maxFile, fileType, accept } = this.props |
| | | const { showprogress, percent } = this.state |
| | | |
| | | let uploadable = 'fileupload-form-container ' |
| | |
| | | listType: fileType, |
| | | fileList: value, |
| | | action: null, |
| | | accept: accept || '', |
| | | method: 'post', |
| | | multiple: false, |
| | | onChange: this.onChange, |