统一下载

dev_hss
杨树明 6 years ago
parent 2b6e101547
commit 3657c075b1

@ -2,7 +2,7 @@ import React,{Component} from "React";
import { Form, Select, Input, Button,Checkbox,Upload,Icon,message,Modal,Spin,Tooltip} from "antd"; import { Form, Select, Input, Button,Checkbox,Upload,Icon,message,Modal,Spin,Tooltip} from "antd";
import {Link} from 'react-router-dom'; import {Link} from 'react-router-dom';
import TPMMDEditor from '../../../tpm/challengesnew/TPMMDEditor'; import TPMMDEditor from '../../../tpm/challengesnew/TPMMDEditor';
import { WordsBtn,getUrl ,bytesToSize,getImageUrl,appendFileSizeToUploadFileAll} from 'educoder'; import { WordsBtn,getUrl ,bytesToSize,getImageUrl,appendFileSizeToUploadFileAll,appendFileSizeToUploadFile} from 'educoder';
import axios from 'axios'; import axios from 'axios';
import Modals from '../../../modals/Modals'; import Modals from '../../../modals/Modals';
const Search = Input.Search; const Search = Input.Search;
@ -49,13 +49,23 @@ class GraduationTasksSubmitedit extends Component{
if(result){ if(result){
console.log(result.data.description); console.log(result.data.description);
const fileList = result.data.attachments.map(item => {
return {
id: item.id,
uid: item.id,
name: appendFileSizeToUploadFile(item),
url: item.url,
filesize: item.filesize,
status: 'done'
}
})
this.setState({ this.setState({
workslist:result.data, workslist:result.data,
attachments:result.data.attachments, attachments:result.data.attachments,
selectmemberslist:result.data.members, selectmemberslist:result.data.members,
selectobjct:result.data.members, selectobjct:result.data.members,
description:result.data.description, description:result.data.description,
fileList:fileList
}) })
if(result.data.task_type===1){ if(result.data.task_type===1){
@ -134,18 +144,7 @@ class GraduationTasksSubmitedit extends Component{
} }
} }
onAttachmentRemoves = (file) => {
if(!file.percent || file.percent == 100){
this.setState({
Modalstype:true,
Modalstopval:'确定要删除这个附件吗?',
ModalSave: ()=>this.deleteAttachments(file),
ModalCancel:this.cancelAttachment
})
return false;
}
}
cancelAttachment=()=>{ cancelAttachment=()=>{
this.setState({ this.setState({
Modalstype:false, Modalstype:false,
@ -155,49 +154,7 @@ class GraduationTasksSubmitedit extends Component{
}) })
} }
deleteAttachments = (id) => {
let {attachments,fileList}=this.state;
const url = `/attachments/${id}.json`
axios.delete(url, {
})
.then((response) => {
if (response.data) {
// const { status } = response.data;
if (response.data.status === 0) {
console.log('--- success')
let newattachments=attachments;
for(var i=0; i<newattachments.length; i++){
if(newattachments[i].id===id){
newattachments.splice(i, 1);
}
}
this.setState({
attachments:newattachments
})
this.cancelAttachment();
this.setState((state) => {
const index = state.fileList.indexOf(id);
const newFileList = state.fileList.slice();
newFileList.splice(index, 1);
return {
fileList: newFileList
};
});
}
}
})
.catch(function (error) {
console.log(error);
});
}
deleteAttachment = (file) => { deleteAttachment = (file) => {
if(!file.percent || file.percent == 100){ if(!file.percent || file.percent == 100){
let {attachments,fileList}=this.state; let {attachments,fileList}=this.state;
@ -672,34 +629,34 @@ class GraduationTasksSubmitedit extends Component{
</Upload> </Upload>
{attachments&&attachments.map((item,key)=>{ {/*{attachments&&attachments.map((item,key)=>{*/}
return( {/*return(*/}
<div className="color-grey mt5" {/*<div className="color-grey mt5"*/}
key={key} {/*key={key}*/}
> {/*>*/}
<a className="color-grey ml3"> {/*<a className="color-grey ml3">*/}
<i className="font-14 color-green iconfont icon-fujian mr8" aria-hidden="true"></i> {/*<i className="font-14 color-green iconfont icon-fujian mr8" aria-hidden="true"></i>*/}
</a> {/*</a>*/}
<a {/*<a*/}
href={item.url} {/*href={item.url}*/}
className="mr12 color9B9B" length="58"> {/*className="mr12 color9B9B" length="58">*/}
{item.title} {/*{item.title}*/}
</a> {/*</a>*/}
<span className="color656565 mt2 color-grey-6 font-12 mr8"> {/*<span className="color656565 mt2 color-grey-6 font-12 mr8">*/}
{item.filesize} {/*{item.filesize}*/}
</span> {/*</span>*/}
{item.delete===true? {/*{item.delete===true?*/}
<i className="font-14 iconfont icon-guanbi " {/*<i className="font-14 iconfont icon-guanbi "*/}
id={item.id} {/*id={item.id}*/}
onClick={()=>this.onAttachmentRemoves(item.id)} {/*onClick={()=>this.onAttachmentRemoves(item.id)}*/}
aria-hidden="true"> {/*aria-hidden="true">*/}
</i>:""} {/*</i>:""}*/}
</div> {/*</div>*/}
) {/*)*/}
})} {/*})}*/}
{/*<style>*/} {/*<style>*/}
{/*{*/} {/*{*/}

@ -2,7 +2,7 @@ import React,{Component} from "React";
import { Form, Select, Input, Button,Checkbox,Upload,Icon,message,Modal} from "antd"; import { Form, Select, Input, Button,Checkbox,Upload,Icon,message,Modal} from "antd";
import {Link} from 'react-router-dom'; import {Link} from 'react-router-dom';
import TPMMDEditor from '../../../tpm/challengesnew/TPMMDEditor'; import TPMMDEditor from '../../../tpm/challengesnew/TPMMDEditor';
import { WordsBtn,getUrl ,bytesToSize,appendFileSizeToUploadFileAll,AttachmentList} from 'educoder'; import { WordsBtn,getUrl ,bytesToSize,appendFileSizeToUploadFileAll,AttachmentList,appendFileSizeToUploadFile} from 'educoder';
import axios from 'axios'; import axios from 'axios';
import Modals from '../../../modals/Modals'; import Modals from '../../../modals/Modals';
import '../../css/Courses.css'; import '../../css/Courses.css';
@ -54,6 +54,17 @@ class GraduationTasksedit extends Component{
// } // }
let namelength=result.data.task_name.length; let namelength=result.data.task_name.length;
// let sixlength=title_num-namelength // let sixlength=title_num-namelength
const fileList = result.data.attachments.map(item => {
return {
id: item.id,
uid: item.id,
name: appendFileSizeToUploadFile(item),
url: item.url,
filesize: item.filesize,
status: 'done'
}
})
this.setState({ this.setState({
// fileList:newfilelist, // fileList:newfilelist,
description:result.data.description, description:result.data.description,
@ -62,6 +73,7 @@ class GraduationTasksedit extends Component{
data:result.data, data:result.data,
title_num:namelength, title_num:namelength,
attachments:result.data.attachments, attachments:result.data.attachments,
fileList:fileList,
}) })
@ -280,7 +292,7 @@ class GraduationTasksedit extends Component{
} }
render(){ render(){
const { getFieldDecorator } = this.props.form; const { getFieldDecorator } = this.props.form;
let {title_num,pageType,name,description,Loadtype,attachments, let {title_num,pageType,name,description,Loadtype,attachments,fileList,
Modalstype,Modalstopval,ModalCancel,ModalSave,shixunsreplace} =this.state; Modalstype,Modalstopval,ModalCancel,ModalSave,shixunsreplace} =this.state;
let {coursedata}=this.props; let {coursedata}=this.props;
@ -289,6 +301,7 @@ class GraduationTasksedit extends Component{
let category_id=this.props.match.params.category_id; let category_id=this.props.match.params.category_id;
const uploadProps = { const uploadProps = {
width: 600, width: 600,
fileList,
// https://github.com/ant-design/ant-design/issues/15505 // https://github.com/ant-design/ant-design/issues/15505
// showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。
// showUploadList: false, // showUploadList: false,
@ -434,7 +447,7 @@ class GraduationTasksedit extends Component{
)} )}
</Form.Item> </Form.Item>
<input type="hidden" id='descriptiontypes' /> <input type="hidden" id='descriptiontypes' />
<AttachmentList {...this.props} {...this.state} attachments={attachments&&attachments}></AttachmentList> {/*<AttachmentList {...this.props} {...this.state} attachments={attachments&&attachments}></AttachmentList>*/}
{/*{attachments&&attachments.map((item,key)=>{*/} {/*{attachments&&attachments.map((item,key)=>{*/}
{/*return(*/} {/*return(*/}

Loading…
Cancel
Save