diff --git a/src/forge/Source/Index.jsx b/src/forge/Source/Index.jsx index 3ba406782..815f52b6c 100644 --- a/src/forge/Source/Index.jsx +++ b/src/forge/Source/Index.jsx @@ -1,9 +1,13 @@ import React, { useEffect, useState } from 'react'; import './Index.scss'; -import { Blueback , FlexAJ } from '../Component/layout'; -import { Dropdown, Input , Menu , Pagination } from 'antd'; +import { AlignCenter, Blueback , FlexAJ } from '../Component/layout'; +import { Dropdown, Input , Menu , Pagination, Spin , Popconfirm, Button } from 'antd'; import { Link } from 'react-router-dom'; import UploadSource from './UploadSource'; +import AddTag from './AddTag'; +import { getImageUrl } from 'educoder'; +import Nodata from '../Nodata'; +import axios from 'axios'; const { Search } = Input; const sort = [ @@ -12,17 +16,52 @@ const sort = [ "按引用排序" ] const limit = 15; +const https = 'https://testfiles.trustie.net'; function Index(props){ const [ sortValue , setSortValue ] = useState(0); const [ page , setPage ] = useState(1); 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 [ addVisible , setAddVisible ] = 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]) - },[search,sort,page]) + function getData(){ + const url = https +`/api/project/achievement/`; + axios.get(url,{ + params:{ + projectId:repo_id, + curPage:page, + pageSize:limit, + name:search, + sort:sortValue+1, + } + }).then(result=>{ + if(result && result.data){ + setData(result.data.data.rows); + setTotal(result.data.data.total); + setIsSpin(false); + setError(false); + } + }).catch(error=>{setIsSpin(false);setError(true);}) + } // 搜索 function onSearch(value){ @@ -40,31 +79,122 @@ function Index(props){ { sort && sort.map((item,key)=>{ return( - changeSort(e,key)} value={key} className={key === sortValue ?"color-blue":""}>{item} + changeSort(e,key)} value={key} className={key=== sortValue ?"color-blue":""}>{item} ) }) } ) - const listmenu=( - - 更新版本 - 设为私有 - 删除资源 - - ) - - function onOk(){ - + function listmenu(id,attachments,isPublic){ + return( + + {setId(id);setVisible(true);setAttachments(attachments)}}>更新版本 + changeStatus(id,isPublic===1?0:1)}>{isPublic === 1 ? "设为私有":"设为公开"} + deleteSourceFunc(id)}>删除资源 + + ) } + // 更细私有状态 + function changeStatus(id,isPublic){ + const url = https+`/api/project/achievement/updateStatus`; + axios.put(url,{ + id,status:isPublic + }).then(result=>{ + if(result && result.data){ + props.showNotification(`资源${isPublic === 1 ? "设为公开":"设为私有"}成功!`); + setIsSpin(true); + getData(); + } + }).catch({}) + } + + // 删除资源方法 + function deleteSourceFunc(id){ + props.confirm({ + content: "是否确认删除所选资源文件?", + onOk: () => { + 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); + setIsSpin(true); + getData(); + } + + // 确认删除标签 + 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=>{}) + } + + function addPanel(id){ + setAddVisible(true); + setId(id); + } + + function onCancelAdd(){ + setId(undefined); + setAddVisible(false); + } + + // 添加标签 + function sureAddTag(values){ + const url = https+`/api/project/achievement/addTag?id=`+id+`&tagName=`+values.tagName; + axios.put(url).then(result=>{ + if(result){ + setId(undefined); + setAddVisible(false); + setIsSpin(true); + getData(); + } + }) + } + return(
- setVisible(false)} onOk={onOk}/> + + setVisible(false)} + onOk={onOk} + showNotification={props.showNotification} + owner={owner} + projectsId={repo_id} + id={id} + attachments={attachments} + />
- 资源库(18) - setVisible(true)}>上传资源 + 资源库{total ? ({total}):""} + { current_user && current_user.login && (props.projectDetail && props.projectDetail.permission) ? + {setId(undefined);setVisible(true);}}>上传资源:"" + }
@@ -79,30 +209,65 @@ function Index(props){ {sort[sortValue]} -
-
    -
  • - -
    - - DaVinci.fdb - - - - -

    - 上传时间:2021-03-30 - 上传类型:软件版本 - 文件大小:10KB - 下载:111 -

    -

    资源描述资源描述资源描述资源描述资源描述资源描述资源描述

    -
    - 软件版本 -
    -
    -
  • -
+ +
+ { + data && data.length> 0 && +
    + { + data.map((item,key)=>{ + return( +
  • + +
    + + + {item.fileName} + + {item.isPublic === 0 && 私有} + + { current_user && current_user.login && + listmenu(item.id,item.attachments,item.isPublic)} 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="否"> + + :"" + } + + ) + }) + } + { + current_user && (current_user.login === item.login) && + addPanel(item.id)} style={{height:"20px",lineHeight:"20px"}}>+新增标签 + } +
    +
    +
  • + ) + }) + } +
+ } + { + ((data && data.length === 0) || error) && + } { total > limit &&
@@ -116,6 +281,7 @@ function Index(props){
}
+
) }