From 5d6b95ab8ff5fe7e8a89dff550a181ff8c391f3d Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Tue, 6 Apr 2021 11:36:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=BA=93=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/forge/Source/Index.jsx | 155 ++++++++++++++++++++---------- src/forge/Source/Index.scss | 1 + src/forge/Source/UploadSource.jsx | 77 +++++++++------ 3 files changed, 154 insertions(+), 79 deletions(-) diff --git a/src/forge/Source/Index.jsx b/src/forge/Source/Index.jsx index 777c9103a..d32e447e6 100644 --- a/src/forge/Source/Index.jsx +++ b/src/forge/Source/Index.jsx @@ -1,10 +1,11 @@ import React, { useEffect, useState } from 'react'; import './Index.scss'; import { Blueback , FlexAJ } from '../Component/layout'; -import { Dropdown, Input , Menu , Pagination } from 'antd'; +import { Dropdown, Input , Menu , Pagination, Spin , Popconfirm } from 'antd'; import { Link } from 'react-router-dom'; import UploadSource from './UploadSource'; import { getImageUrl } from 'educoder'; +import Nodata from '../Nodata'; import axios from 'axios'; const { Search } = Input; @@ -21,13 +22,20 @@ function Index(props){ const [ total , setTotal ] = useState(0); const [ search , setSearch ] = useState(undefined); const [ data , setData ] = useState(undefined); + const [ isSpin , setIsSpin ] = useState(true); + const [ error , setError ] = useState(false); + const [ attachments , setAttachments ] = useState(undefined); + + const [ id , setId ] = useState(undefined); const [ visible , setVisible ] = useState(false); const repo_id = props.projectDetail && props.projectDetail.repo_id; const owner = props.match.params.owner; + const current_user = props.current_user; useEffect(()=>{ if(owner && repo_id){ + setIsSpin(true); getData(); } },[repo_id,owner,search,sortValue,page]) @@ -46,8 +54,10 @@ function Index(props){ if(result && result.data){ setData(result.data.data.rows); setTotal(result.data.data.total); + setIsSpin(false); + setError(false); } - }).catch(error=>{}) + }).catch(error=>{setIsSpin(false);setError(true);}) } // 搜索 @@ -73,24 +83,50 @@ function Index(props){ ) - const listmenu=( - - 更新版本 - 设为私有 - 删除资源 - - ) + function listmenu(id,attachments){ + return( + + {setId(id);setVisible(true);setAttachments(attachments)}}>更新版本 + 设为私有 + deleteSourceFunc(id)}>删除资源 + + ) + } + + // 删除资源方法 + function deleteSourceFunc(id){ + const url = https + `/api/project/achievement/${id}`; + axios.delete(url).then(result=>{ + if(result && result.data && result.data.code === "1"){ + props.showNotification("资源删除成功"); + setIsSpin(true); + getData(); + } + }) + } + // 上传资源成功 function onOk(){ + setVisible(false); getData(); } - // 删除标签 - function removeTagFunc(){ - + // 确认删除标签 + function removeTagFunc(id,tag){ + const url = https + `/api/project/achievement/deleteTag`; + axios.delete(url,{ + params:{id,tagName:tag} + }).then(result=>{ + if(result && result.data){ + props.showNotification("标签删除成功"); + setIsSpin(true); + getData(); + } + }).then(error=>{}) } + return(
资源库(18) - setVisible(true)}>上传资源 + { current_user && current_user.login && + {setId(undefined);setVisible(true);}}>上传资源 + }
@@ -119,43 +159,59 @@ function Index(props){ {sort[sortValue]} -
-
    - { - data && data.length> 0 && data.map((item,key)=>{ - return( -
  • - -
    - - {item.fileName} - - - - -

    - 上传时间:{item.uploadTime} - 文件大小:{item.fileSize} - 下载:{item.download} -

    -

    {item.remark}

    - { item.tags && item.tags.length>0 && -
    - { - item.tags.map((i,k)=>{ - return( - {i} - ) - }) + +
    + { + data && data.length> 0 && +
      + { + data.map((item,key)=>{ + return( +
    • + +
      + + {item.fileName} + { current_user && current_user.login && + listmenu(item.id,item.attachments)} placement={'bottomRight'}> + + } -
      - } -
    -
  • - ) - }) - } -
+ +

+ 上传时间:{item.uploadTime} + 文件大小:{item.fileSize} + 下载:{item.download} +

+

{item.remark}

+ { item.tags && item.tags.length>0 && +
+ { + item.tags.map((i,k)=>{ + return( + {i} + { + current_user && (current_user.login === item.login) ? + removeTagFunc(item.id,i)} okText="是" cancelText="否"> + + :"" + } + + ) + }) + } +
+ } +
+ + ) + }) + } + + } + { + ((data && data.length === 0) || error) && + } { total > limit &&
@@ -169,6 +225,7 @@ function Index(props){
}
+ ) } diff --git a/src/forge/Source/Index.scss b/src/forge/Source/Index.scss index c3ea90cf9..97a964975 100644 --- a/src/forge/Source/Index.scss +++ b/src/forge/Source/Index.scss @@ -21,6 +21,7 @@ } .bodycontent{ padding:0px 20px; + min-height: 500px; & > ul.bodycontentul > li{ display: flex; border-bottom: 1px solid #eee; diff --git a/src/forge/Source/UploadSource.jsx b/src/forge/Source/UploadSource.jsx index 450f1eaef..d521206ef 100644 --- a/src/forge/Source/UploadSource.jsx +++ b/src/forge/Source/UploadSource.jsx @@ -11,12 +11,17 @@ const data = [ {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 ,owner,projectsId}){ - const [ tableData , setTableData ] = useState(data); +function UploadSource({ form , visible , onCancel , onOk , showNotification , attachments , id ,owner,projectsId}){ + const [ tableData , setTableData ] = useState(undefined); const [ fileId , setFilesId ] = useState(undefined); const [ fileName , setFileName ] = useState(undefined); const { getFieldDecorator, validateFields , setFieldsValue } = form; + useEffect(()=>{ + if(id && attachments){ + setTableData(attachments); + } + },[id,attachments]) // 上传附件后得到的文件id数组 function UploadFunc(id,name){ setFilesId(id); @@ -25,37 +30,36 @@ function UploadSource({ form , visible , onCancel , onOk , showNotification ,own const columns = [ { - dataIndex:"name", - key:"name", + dataIndex:"fileName", + key:"fileName", title:"资源名称", - width:"45%", + width:"42%", ellipsis:true, render:(value,item,key)=>{ return -
{value}
+
{value}
{ key === 0 && 当前版本 }
} }, { - dataIndex:"loadNum", - key:"loadNum", + dataIndex:"downloads", + key:"downloads", title:"下载数", - width:"15%", + width:"14%", className:"edu-txt-center" }, { - dataIndex:"citeNum", - key:"citeNum", - title:"引用数", - width:"15%", + dataIndex:"fileSizeString", + key:"fileSizeString", + title:"文件大小", + width:"16%", className:"edu-txt-center" }, { - dataIndex:"time", - key:"time", + dataIndex:"createdAt", + key:"createdAt", title:"上传时间", - width:"25%" } ] @@ -74,22 +78,35 @@ function UploadSource({ form , visible , onCancel , onOk , showNotification ,own function postInfo(values){ const url = https+`/api/project/achievement/`; + if(id){ + // 修改 + axios.put(url,{ + id,fileName,fileId:`${fileId}`, + remark:values.remark + }).then(result=>{ + if(result && result.data){ + onOk(); + } + }).catch(error=>{}) + }else{ + // 上传 + axios.post(url,{ + fileId:`${fileId}`, + fileName, + login:owner, + projectId:projectsId, + ...values + }).then(result=>{ + if(result && result.data){ + onOk(); + } + }).catch(error=>{}) + } - axios.post(url,{ - fileId:`${fileId}`, - fileName, - login:owner, - projectId:projectsId, - ...values - }).then(result=>{ - if(result && result.data){ - onOk(); - } - }).catch(error=>{}) } return(
- - + {id &&
} + {getFieldDecorator("tagNames",{ rules:[] })(