| | |
| | | import { Upload, Button, Progress, notification } from 'antd' |
| | | import { UploadOutlined } from '@ant-design/icons' |
| | | import SparkMD5 from 'spark-md5' |
| | | |
| | | import Api from '@/api' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | |
| | | class FileUpload extends Component { |
| | |
| | | this.props.onChange(vals.join(',')) |
| | | } |
| | | |
| | | onUpdate = (url) => { |
| | | onUpdate = (url, file_name) => { |
| | | const { config } = this.props |
| | | |
| | | let filelist = fromJS(this.state.filelist).toJS() |
| | | |
| | | if (filelist[filelist.length -1]) { |
| | |
| | | }) |
| | | |
| | | this.setState({filelist}) |
| | | this.props.onChange(vals.join(',')) |
| | | |
| | | if (config.subFields) { |
| | | let other = {} |
| | | config.subFields.forEach((n, i) => { |
| | | other[n.field] = file_name |
| | | setTimeout(() => { |
| | | MKEmitter.emit('mkFC', 'input', n.uuid, file_name) |
| | | }, i * 5) |
| | | }) |
| | | |
| | | this.props.onChange(vals.join(','), other) |
| | | } else { |
| | | this.props.onChange(vals.join(',')) |
| | | } |
| | | } |
| | | |
| | | onFail = (msg) => { |
| | |
| | | }) |
| | | } |
| | | |
| | | shardupload = (param) => { |
| | | shardupload = (param, file_name) => { |
| | | let form = new FormData() |
| | | |
| | | form.append('file', param.binary) |
| | |
| | | Api.getLargeFileUpload(form).then(res => { |
| | | if (res.status) { |
| | | if (res.urlPath) { |
| | | this.onUpdate(res.urlPath) |
| | | this.onUpdate(res.urlPath, file_name) |
| | | } else { |
| | | this.onFail() |
| | | } |
| | |
| | | percent: 0 |
| | | }) |
| | | |
| | | let file_name = file.name.replace(/\.{1}[^.]*$/ig, '') |
| | | |
| | | if (compress === 'true' || compress === 'base64') { |
| | | let reader = new FileReader() |
| | | let fileSize = file.size / 1024 / 1024 |
| | |
| | | let param = {Base64Img: cvs.toDataURL('image/jpeg', compressRate)} |
| | | |
| | | if (this.props.config.compress === 'base64') { |
| | | this.onUpdate(param.Base64Img) |
| | | this.onUpdate(param.Base64Img, file_name) |
| | | |
| | | this.setState({ |
| | | percent: 100 |
| | |
| | | url = rduri.replace(/webapi(.*)$/, '') + result.Images |
| | | } |
| | | |
| | | this.onUpdate(url) |
| | | this.onUpdate(url, file_name) |
| | | |
| | | this.setState({ |
| | | percent: 100 |
| | |
| | | if (res.status) { |
| | | if (res.urlPath) { |
| | | let path = (/^\/\//.test(res.urlPath) ? 'https:' : '') + res.urlPath |
| | | this.onUpdate(path) |
| | | this.onUpdate(path, file_name) |
| | | this.setState({ |
| | | percent: 100 |
| | | }, () => { |
| | |
| | | |
| | | Api.getFilePreUpload(_param).then(res => { |
| | | if (res.status && res.urlPath) { |
| | | this.onUpdate(res.urlPath) |
| | | this.onUpdate(res.urlPath, file_name) |
| | | this.setState({ |
| | | percent: 100 |
| | | }, () => { |
| | |
| | | }, 200) |
| | | }) |
| | | } else { |
| | | this.shardupload(param) |
| | | this.shardupload(param, file_name) |
| | | } |
| | | }) |
| | | } |