From b23db4e1b9e8bc813b4b3b95d35552e5e2e980c6 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 01 二月 2021 18:51:00 +0800 Subject: [PATCH] 2021-02-01 --- src/tabviews/zshare/fileupload/index.jsx | 62 ++++++++++++++---------------- 1 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/tabviews/zshare/fileupload/index.jsx b/src/tabviews/zshare/fileupload/index.jsx index 428fa2b..e8cf594 100644 --- a/src/tabviews/zshare/fileupload/index.jsx +++ b/src/tabviews/zshare/fileupload/index.jsx @@ -24,12 +24,18 @@ 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 = '' @@ -37,45 +43,35 @@ 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, @@ -269,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' } @@ -282,7 +278,7 @@ name: 'file', disabled: showprogress, listType: fileType, - fileList: value, + fileList: filelist, action: null, accept: accept || '', method: 'post', -- Gitblit v1.8.0