diff --git a/src/AppConfig.js b/src/AppConfig.js index 6283109c..bd24bb7d 100644 --- a/src/AppConfig.js +++ b/src/AppConfig.js @@ -36,7 +36,7 @@ export function initAxiosInterceptors(props) { //响应前的设置 axios.interceptors.request.use( config => { - if (config.url.indexOf(proxy) !== -1 || config.url.indexOf("http") !== -1) { + if(config.url.indexOf("http") !== -1) { return config } requestProxy(config); diff --git a/src/forge/Settings/Collaborator.js b/src/forge/Settings/Collaborator.js index 90b1b6a7..73421917 100644 --- a/src/forge/Settings/Collaborator.js +++ b/src/forge/Settings/Collaborator.js @@ -42,7 +42,7 @@ function Collaborator(props){
{ nav === "1" ? - + : } diff --git a/src/forge/Settings/CollaboratorMember.jsx b/src/forge/Settings/CollaboratorMember.jsx index fa307a97..9c617f11 100644 --- a/src/forge/Settings/CollaboratorMember.jsx +++ b/src/forge/Settings/CollaboratorMember.jsx @@ -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); diff --git a/src/forge/Source/Upload.jsx b/src/forge/Source/Upload.jsx new file mode 100644 index 00000000..1897b959 --- /dev/null +++ b/src/forge/Source/Upload.jsx @@ -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 ? + + + (你可以上传小于{size}MB的文件) + + : + + {icon || } +

拖动文件或点击此处上传

+
+ ) + } +} +export default Upload; \ No newline at end of file diff --git a/src/forge/Source/UploadSource.jsx b/src/forge/Source/UploadSource.jsx index 72baa195..f247b0aa 100644 --- a/src/forge/Source/UploadSource.jsx +++ b/src/forge/Source/UploadSource.jsx @@ -10,12 +10,14 @@ const data = [ {name:"sdfkjsfj.pdf",loadNum:"10",citeNum:"15",time:"2021-04-01 10:45"}, {name:"sdfkjsfj.pdf",loadNum:"10",citeNum:"15",time:"2021-04-01 10:45"} ] +const https = 'https://testfiles.trustie.net'; function UploadSource({ form , visible , onCancel , onOk , showNotification}){ const [ tableData , setTableData ] = useState(data); const { getFieldDecorator, validateFields , setFieldsValue } = form; - function UploadFunc(){ - + // 上传附件后得到的文件id数组 + function UploadFunc(files){ + } const columns = [ @@ -88,6 +90,7 @@ function UploadSource({ form , visible , onCancel , onOk , showNotification}){ load={UploadFunc} size={100} showNotification={showNotification} + actionUrl= {https+`/busiAttachments/upload`} btn /> diff --git a/src/forge/Upload/Index.js b/src/forge/Upload/Index.js index c3d42592..5b09ca07 100644 --- a/src/forge/Upload/Index.js +++ b/src/forge/Upload/Index.js @@ -73,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); } @@ -89,14 +89,14 @@ class Index extends Component { render() { //判断是否已经提交,如已提交评论则上一条评论数据清除 - const { isComplete, icon , btn , className , size} = 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