Commit f3dbebb5 by end

上传多个文件

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