Commit f3dbebb5 by end

上传多个文件

parent 5609cc28
No preview for this file type
......@@ -13,9 +13,10 @@ class UploadUtil extends Component {
this.state = {
uploadParams: {},
uploadAction: {},
originalFile: "",
originalFileName: "",
originalFileUrl: "",
fileList: [],
newFileList: [],
key: "",
processNum: 0, //进度条--liyuan
};
......@@ -53,16 +54,11 @@ class UploadUtil extends Component {
} else {
this.props.gupList([]);
}
if (fileList.length > 1) {
message.error("一次只能导入一个文件");
this.setState({ fileList: [] });
return;
}
//判断类型 学习营销名片只用上传图片`
let reg = ""; //正则匹配格式
this.props.extra === "markeCardExtra"
? (reg = /(png|jpg|gif|jpeg|doc|docx|pdf|PDF|wps)$/g)
: (reg = /(mp4|png|jpg|gif|mp3|pdf|jpeg|doc|docx|pdf|PDF|wps)$/g);
? (reg = /(mp4|png|jpg|gif|mp3|pdf|jpeg|doc|docx|pdf|PDF|wps)$/g)
: (reg = /(png|jpg|gif|jpeg|doc|docx|pdf|PDF|xls|xlsx)$/g);
if (!reg.test(file.name)) {
message.error("文件类型不对");
return false;
......@@ -74,7 +70,7 @@ class UploadUtil extends Component {
{
uploadParams: {},
uploadAction: `${services.uploadApi}`,
originalFile: file.name,
originalFileName: file.name,
originalFileUrl: "",
},
() => {
......@@ -88,33 +84,39 @@ class UploadUtil extends Component {
//上传
handleChange = info => {
let fileList = info.fileList;
fileList = fileList.slice(-1);
//因为6378 注释
// if(fileList.status==="done") {
// this.setState({fileList});
// }
//6378 【UAT】【管理端】-名片配置-上传新图片修改时-名片预览未显示
this.setState({
//进度条--liyuan
processNum: info.file.percent ? info.file.percent : 0,
});
if (fileList[0] && fileList[0].status === "done") {
if (this.props.getUrl) {
this.props.getUrl(fileList[0].response.data, this.state.originalFile);
}
console.log("检测打印变量=fileList ", fileList);
this.setState({ fileList });
message.success("上传成功"); //进度条--liyuan
}
//6378 【UAT】【管理端】-名片配置-上传新图片修改时-名片预览未显示
if (fileList[0] && fileList[0].status === "error") {
if (info.file.status === "done") {
fileList.map(item => {
if (item.status === "done") {
if (this.state.newFileList.indexOf(item.response.data) == -1) {
this.state.newFileList.push(item.response.data);
}
console.log("11111111111111", this.state.newFileList);
}
});
message.success("上传成功");
} else if (info.file.status === "error") {
message.error("上传失败,请重新尝试");
this.setState({ fileList: [] });
}
//因为6378 注释
// if(fileList.status==="error") {
// message.error("上传失败,请重新尝试");
// this.setState({fileList:[]});
if (this.props.getUrl) {
this.props.getUrl(this.state.newFileList);
}
this.setState({ fileList });
// if (fileList[0] && fileList[0].status === "done") {
// if (this.props.getUrl) {
// this.props.getUrl(fileList[0].response.data, this.state.originalFileName);
// }
// console.log("检测打印变量=fileList ", fileList);
// this.setState({ fileList });
// message.success("上传成功");
// }
// if (fileList[0] && fileList[0].status === "error") {
// message.error("上传失败,请重新尝试");
// this.setState({ fileList: [] });
// }
};
......@@ -125,9 +127,12 @@ class UploadUtil extends Component {
return e && this.state.fileList;
};
fnRemove = () => {
this.setState({ fileList: [] });
this.props.getUrl("");
fnRemove = e => {
this.state.newFileList.splice(
this.state.newFileList.indexOf(e.response.data),
1
);
this.props.getUrl(this.state.newFileList);
};
render() {
......@@ -139,8 +144,8 @@ class UploadUtil extends Component {
<FormItem
extra={
this.props.extra === "markeCardExtra"
? "请上传资源附件(附件格式:png、jpg、jpeg、gif、word、pdf)"
: "请上传资源附件(附件格式:mp4、png、jpg、jpeg、gif、mp3、word、pdf)"
? "请上传资源附件(附件格式:mp4、png、jpg、jpeg、gif、mp3、word、pdf)"
: "请上传资源附件(附件格式:png、jpg、jpeg、gif、word、pdf、xls、xlsx)"
}
>
{getFieldDecorator("upload", {
......
......@@ -243,11 +243,12 @@ class AddTest extends Component {
type: values.type,
content: values.content,
//bug-9797-liyuan 附件回显
contentAppendixUrl: this.state.fileUrl
contentAppendixUrl: "",
attachmentUrl: this.state.fileUrl
? this.state.fileUrl
: this.state.testItem.contentAppendixUrl
? this.state.testItem.contentAppendixUrl
: "",
: this.state.testItem.attachmentUrl
? this.state.testItem.attachmentUrl
: [],
needAnswer: values.needAnswer ? 1 : 0,
questionOptions: objs,
maxSelectItem: values.needAnswer2 ? values.maxSelectItem : "",
......@@ -272,13 +273,13 @@ class AddTest extends Component {
keywords: this.addother.state.keywords,
type: values.type,
content: values.content,
contentAppendixUrl: this.state.fileUrl ? this.state.fileUrl : "",
contentAppendixUrl: "",
attachmentUrl: this.state.fileUrl ? this.state.fileUrl : [],
needAnswer: values.needAnswer ? 1 : 0,
questionOptions: objs,
maxSelectItem: values.needAnswer2 ? values.maxSelectItem : "",
minSelectItem: values.needAnswer1 ? values.minSelectItem : "",
reseachId: surid,
//no:tlist.list[0]?tlist.list[0].no+1:order,
hasOther: this.addother.state.addother ? 1 : 0,
otherOption: {
content: this.addother.state.other,
......@@ -286,17 +287,9 @@ class AddTest extends Component {
required: this.addother.state.ismust ? 1 : 0,
},
};
// 判断最大可选
// if( param.maxSelectItem !== '' && param.maxSelectItem > param.questionOptions.length){
// message.error('最多项错误')
// this.setState({
// confirmLoading: false,
// });
// return
// }
console.log(this.state.fileUrl, "查看文件上传");
this.props.insert(param, this.state.pageNo, this.state.pageSize);
this.setState({ fileUrl: "" });
this.setState({ fileUrl: [] });
}
setTimeout(() => {
this.setState({
......@@ -432,22 +425,12 @@ class AddTest extends Component {
const { visible, confirmLoading, selectedRowKeys, testItem } = this.state;
const uploadProps = {
uploadUtilName: "上传图片/文件",
getUrl: (fileUrl, fileName) => {
getUrl: fileUrl => {
this.setState({
fileUrl,
fileName,
});
},
defaultUrl: this.state.testItem.contentAppendixUrl
? [
{
uid: 1,
status: "done",
url: this.state.testItem.contentAppendixUrl,
name: this.state.testItem.contentAppendixUrl.split('prefix=')[1],
},
]
: [],
defaultUrl: this.state.testItem.attachmentUrl,
};
// console.log('检测打印变量1 ',this.state.fileUrl,'检测打印变量2 ',this.state.fileName);
......@@ -574,7 +557,7 @@ class AddTest extends Component {
</div>
{visible && (
<Modal
title="添加问题"
title="编辑问题"
visible
onOk={this.handleOk}
confirmLoading={confirmLoading}
......
......@@ -67,6 +67,7 @@ class TestModal extends Component {
}
componentDidMount() {
const { defaultValue } = this.props;
console.log(defaultValue,'22222222')
if (defaultValue.options && defaultValue.options.length) {
let cach = defaultValue.options;
uuid1 = cach[cach.length - 1]["no"] + 1;
......@@ -281,7 +282,7 @@ class TestModal extends Component {
style={{ marginLeft: 85, marginTop: -15 }}
>
{getFieldDecorator(
"contentAppendixUrl",
"attachmentUrl",
{}
)(<UploadUtil {...this.props.uploadProps} />)}
</FormItem>
......
......@@ -353,11 +353,12 @@ class Details extends Component {
const param = {
type: values.type,
content: values.content,
contentAppendixUrl: this.state.fileUrl
contentAppendixUrl: "",
attachmentUrl: this.state.fileUrl
? this.state.fileUrl
: this.state.testItem.contentAppendixUrl
? this.state.testItem.contentAppendixUrl
: "",
: this.state.testItem.attachmentUrl
? this.state.testItem.attachmentUrl
: [],
needAnswer: values.needAnswer ? 1 : 0,
questionOptions: objs,
maxSelectItem: values.needAnswer2 ? values.maxSelectItem : "",
......@@ -381,7 +382,8 @@ class Details extends Component {
keywords: this.addother.state.keywords,
type: values.type,
content: values.content,
contentAppendixUrl: this.state.fileUrl ? this.state.fileUrl : "",
contentAppendixUrl: "",
attachmentUrl: this.state.fileUrl ? this.state.fileUrl : [],
needAnswer: values.needAnswer ? 1 : 0,
questionOptions: objs,
maxSelectItem: values.needAnswer2 ? values.maxSelectItem : "",
......@@ -436,16 +438,7 @@ class Details extends Component {
fileName,
});
},
defaultUrl: this.state.testItem.contentAppendixUrl
? [
{
uid: 1,
status: "done",
url: this.state.testItem.contentAppendixUrl,
name: this.state.testItem.contentAppendixUrl,
},
]
: [],
defaultUrl: this.state.testItem.attachmentUrl,
};
const children = [];
......@@ -845,7 +838,7 @@ class Details extends Component {
</Modal>
{visibleQuestion && (
<Modal
title="添加问题"
title="编辑问题"
visible
onOk={this.handleOk}
confirmLoading={confirmLoading}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment