From 316877c1d9e5b6d92334f30b03d97d7e833cd934 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 02 二月 2021 16:01:57 +0800 Subject: [PATCH] 2021-02-02 --- src/tabviews/zshare/fileupload/index.jsx | 80 +++++++++++++++++++++++----------------- 1 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/tabviews/zshare/fileupload/index.jsx b/src/tabviews/zshare/fileupload/index.jsx index 925ef09..e8cf594 100644 --- a/src/tabviews/zshare/fileupload/index.jsx +++ b/src/tabviews/zshare/fileupload/index.jsx @@ -5,7 +5,6 @@ import { Upload, Button, Icon, Progress, notification } from 'antd' import SparkMD5 from 'spark-md5' import Api from '@/api' -import Utils from '@/utils/utils.js' import './index.scss' let service = '' @@ -25,51 +24,54 @@ state = { percent: 0, - showprogress: false + showprogress: false, + filelist: [] + } + + UNSAFE_componentWillMount () { + const { value } = this.props + if (!value) return + + this.setState({filelist: fromJS(value).toJS()}) } onChange = ({ fileList }) => { - const { onChange } = this.props + fileList = fileList.map(item => { + if (item.status === 'error' && /^<!DOCTYPE html>/.test(item.response)) { + item.response = '' + } + return item + }) - if (onChange) { - onChange([...fileList]) - } + this.setState({filelist: fileList}) + this.props.onChange(fileList) } onRemove = file => { - const { value, onChange } = this.props + const files = this.state.filelist.filter(v => v.uid !== file.uid) - const files = value.filter(v => v.url !== file.url) - - if (onChange) { - onChange(files) - } + this.setState({filelist: files}) + this.props.onChange(files) } onUpdate = (url) => { - const { value, onChange } = this.props + let filelist = fromJS(this.state.filelist).toJS() - let filelist = fromJS(value).toJS() - filelist[filelist.length -1].status = 'done' - filelist[filelist.length -1].response = url - filelist[filelist.length -1].origin = false - - if (onChange) { - onChange([...filelist]) + if (filelist[filelist.length -1]) { + filelist[filelist.length -1].status = 'done' + filelist[filelist.length -1].response = url + filelist[filelist.length -1].origin = false } + + this.setState({filelist}) + this.props.onChange(filelist) } onDelete = (msg) => { - const { value, onChange } = this.props - let filelist = value.filter(v => !v.url && !v.response) + let filelist = this.state.filelist.filter(v => !v.url && !v.response) - if (onChange) { - onChange([...filelist]) - } - - this.setState({ - showprogress: false - }) + this.setState({filelist, showprogress: false}) + this.props.onChange(filelist) notification.warning({ top: 92, @@ -122,6 +124,16 @@ }) } + getuuid = () => { + let uuid = [] + let _options = '0123456789abcdefghigklmnopqrstuv' + for (let i = 0; i < 19; i++) { + uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1)) + } + uuid = uuid.join('') + return uuid + } + beforeUpload = (file) => { const { accept } = this.props @@ -165,7 +177,7 @@ params.file.fileChunks = chunks // 璁板綍鎵�鏈塩hunks鐨勯暱搴� if (!/^[A-Za-z0-9]+$/.test(params.file.fileName)) { // 鏂囦欢鍚嶇О鍚湁鑻辨枃鍙婃暟瀛椾箣澶栧瓧绗︽椂锛屽悕绉扮郴缁熺敓鎴� - params.file.fileName = moment().format('YYYYMMDDHHmmss') + Utils.getuuid().substr(14) + params.file.fileName = moment().format('YYYYMMDDHHmmss') + this.getuuid() } totalFileReader.readAsArrayBuffer(file) @@ -253,12 +265,12 @@ } render() { - const { value, maxFile, fileType, accept } = this.props - const { showprogress, percent } = this.state + const { maxFile, fileType, accept } = this.props + const { showprogress, percent, filelist } = this.state let uploadable = 'fileupload-form-container ' - if (maxFile && maxFile > 0 && value && value.length >= maxFile) { + if (maxFile && maxFile > 0 && filelist.length >= maxFile) { uploadable += 'limit-fileupload' } @@ -266,7 +278,7 @@ name: 'file', disabled: showprogress, listType: fileType, - fileList: value, + fileList: filelist, action: null, accept: accept || '', method: 'post', -- Gitblit v1.8.0