forked from Gitlink/forgeplus-react
This commit is contained in:
parent
898ad15343
commit
2fcd2fd066
|
|
@ -42,7 +42,7 @@ function Collaborator(props){
|
|||
<div>
|
||||
{
|
||||
nav === "1" ?
|
||||
<Member newId={newId} projectsId={projectsId} owner={owner} project_id={props.project_id} author={props.author} showNotification={props.showNotification}/>
|
||||
<Member newId={newId} projectsId={projectsId} owner={owner} project_id={props.project_id} author={props.projectDetail && props.projectDetail.author} showNotification={props.showNotification}/>
|
||||
:
|
||||
<Group owner={owner} projectsId={projectsId} newGroupId={newGroupId}/>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ function CollaboratorMember({projectsId,owner,project_id,author,showNotification
|
|||
const [ role , setRole ] = useState(undefined);
|
||||
const [ listData , setListData ] = useState(undefined);
|
||||
const [ total , setTotal ] = useState(0);
|
||||
|
||||
|
||||
useEffect(()=>{
|
||||
if(newId){
|
||||
addCollaborator(newId);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
import React, { useEffect, useState } from "react";
|
||||
import { Upload, Icon , Button } from 'antd';
|
||||
import { appendFileSizeToUploadFileAll } from 'educoder';
|
||||
|
||||
import axios from 'axios';
|
||||
const { Dragger } = Upload;
|
||||
function Upload({isComplete, icon , btn , className , size , actionUrl,fileList}) {
|
||||
const [ files , setFiles ] = useState(undefined);
|
||||
|
||||
useEffect(()=>{
|
||||
init();
|
||||
},[fileList]);
|
||||
|
||||
function init(){
|
||||
let f = appendFileSizeToUploadFileAll(fileList);
|
||||
setFiles(f);
|
||||
}
|
||||
function onAttachmentRemove(file){
|
||||
if (!file.percent || file.percent === 100) {
|
||||
deleteAttachment(file);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function deleteAttachment(file){
|
||||
const url = `/attachments/${file.response ? file.response.id : file.uid}.json`
|
||||
axios.delete(url, {
|
||||
}).then((response) => {
|
||||
if (response.data) {
|
||||
if (response.data.status === 0) {
|
||||
let index = files.indexOf(file);
|
||||
let newFileList = files.slice();
|
||||
let nf = newFileList.splice(index, 1);
|
||||
setFiles(nf);
|
||||
fileIdList(nf);
|
||||
} else {
|
||||
showNotification(response.data.message)
|
||||
}
|
||||
}
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function handleChange (info) {
|
||||
if (info.file.status === 'uploading' || info.file.status === 'done' || info.file.status === 'removed') {
|
||||
let fileList = info.fileList;
|
||||
|
||||
setFiles(appendFileSizeToUploadFileAll(fileList));
|
||||
fileIdList(fileList);
|
||||
}
|
||||
}
|
||||
|
||||
function fileIdList (fileList) {
|
||||
let array = [];
|
||||
fileList && fileList.length > 0 && fileList.map((item) => {
|
||||
return array.push(item.response && (item.response.id || (item.response.data && item.response.data.id)));
|
||||
})
|
||||
array && load && load(array);
|
||||
}
|
||||
|
||||
function beforeUpload(file){
|
||||
const isLt100M = file.size / 1024 / 1024 < size;
|
||||
if (!isLt100M) {
|
||||
showNotification(`文件大小必须小于${size}MB!`);
|
||||
}
|
||||
return isLt100M;
|
||||
}
|
||||
|
||||
//判断是否已经提交,如已提交评论则上一条评论数据清除
|
||||
|
||||
const upload = {
|
||||
name: 'file',
|
||||
fileList: files,
|
||||
action: actionUrl,
|
||||
onChange:handleChange,
|
||||
onRemove:onAttachmentRemove,
|
||||
beforeUpload:beforeUpload
|
||||
};
|
||||
|
||||
return (
|
||||
btn ?
|
||||
<Upload {...upload} className={className}>
|
||||
<Button type={"default"}>上传文件</Button>
|
||||
<span className="ml10 color-grey-9">(你可以上传小于<span className="color-red">{size}MB</span>的文件)</span>
|
||||
</Upload>
|
||||
:
|
||||
<Dragger {...upload} className={className}>
|
||||
{icon || <Icon type="inbox" />}
|
||||
<p className="ant-upload-text font-14">拖动文件或<span className="color-blue">点击此处上传</span></p>
|
||||
</Dragger>
|
||||
)
|
||||
}
|
||||
}
|
||||
export default Upload;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import React, { Component } from "react";
|
||||
import { Upload, Button, Icon } from 'antd';
|
||||
import { Upload, Icon , Button } from 'antd';
|
||||
import { getUploadActionUrl, appendFileSizeToUploadFileAll } from 'educoder';
|
||||
import { AlignCenter } from '../Component/layout';
|
||||
|
||||
import axios from 'axios';
|
||||
const { Dragger } = Upload;
|
||||
|
|
@ -28,22 +29,12 @@ class Index extends Component {
|
|||
|
||||
onAttachmentRemove = (file) => {
|
||||
if (!file.percent || file.percent === 100) {
|
||||
// this.props.confirm({
|
||||
// content: '是否确认删除?',
|
||||
// onOk: () => {
|
||||
// this.deleteAttachment(file)
|
||||
// },
|
||||
// onCancel() {
|
||||
// console.log('Cancel');
|
||||
// },
|
||||
// });
|
||||
this.deleteAttachment(file)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
deleteAttachment = (file) => {
|
||||
|
||||
const url = `/attachments/${file.response ? file.response.id : file.uid}.json`
|
||||
axios.delete(url, {
|
||||
}).then((response) => {
|
||||
|
|
@ -82,7 +73,7 @@ class Index extends Component {
|
|||
fileIdList = (fileList) => {
|
||||
let array = [];
|
||||
fileList && fileList.length > 0 && fileList.map((item) => {
|
||||
return array.push(item.response && item.response.id);
|
||||
return array.push(item.response && (item.response.id || (item.response.data && item.response.data.id)));
|
||||
})
|
||||
array && this.props.load && this.props.load(array);
|
||||
}
|
||||
|
|
@ -98,21 +89,27 @@ class Index extends Component {
|
|||
|
||||
render() {
|
||||
//判断是否已经提交,如已提交评论则上一条评论数据清除
|
||||
const { isComplete, icon } = this.props;
|
||||
const { isComplete, icon , btn , className , size , actionUrl } = this.props;
|
||||
const { fileList } = this.state;
|
||||
|
||||
let list = isComplete === true ? fileList : undefined;
|
||||
const upload = {
|
||||
name: 'file',
|
||||
fileList: list,
|
||||
action: `${getUploadActionUrl()}`,
|
||||
action: actionUrl || `${getUploadActionUrl()}`,
|
||||
onChange: this.handleChange,
|
||||
onRemove: this.onAttachmentRemove,
|
||||
beforeUpload: this.beforeUpload
|
||||
};
|
||||
|
||||
return (
|
||||
<Dragger {...upload} className={this.props.className}>
|
||||
btn ?
|
||||
<Upload {...upload} className={className}>
|
||||
<Button type={"default"}>上传文件</Button>
|
||||
<span className="ml10 color-grey-9">(你可以上传小于<span className="color-red">{size}MB</span>的文件)</span>
|
||||
</Upload>
|
||||
:
|
||||
<Dragger {...upload} className={className}>
|
||||
{icon || <Icon type="inbox" />}
|
||||
<p className="ant-upload-text font-14">拖动文件或<span className="color-blue">点击此处上传</span></p>
|
||||
</Dragger>
|
||||
|
|
|
|||
Loading…
Reference in New Issue