forked from Gitlink/forgeplus-react
资源库部分接口调试
This commit is contained in:
parent
8903363695
commit
f9f79e0365
|
@ -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){
|
|||
</Menu>
|
||||
)
|
||||
|
||||
const listmenu=(
|
||||
<Menu>
|
||||
<Menu.Item>更新版本</Menu.Item>
|
||||
<Menu.Item>设为私有</Menu.Item>
|
||||
<Menu.Item>删除资源</Menu.Item>
|
||||
</Menu>
|
||||
)
|
||||
function listmenu(id,attachments){
|
||||
return(
|
||||
<Menu>
|
||||
<Menu.Item onClick={()=>{setId(id);setVisible(true);setAttachments(attachments)}}>更新版本</Menu.Item>
|
||||
<Menu.Item>设为私有</Menu.Item>
|
||||
<Menu.Item onClick={()=>deleteSourceFunc(id)}>删除资源</Menu.Item>
|
||||
</Menu>
|
||||
)
|
||||
}
|
||||
|
||||
// 删除资源方法
|
||||
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(
|
||||
<div className="sourcePanel">
|
||||
<UploadSource
|
||||
|
@ -100,11 +136,15 @@ function Index(props){
|
|||
showNotification={props.showNotification}
|
||||
owner={owner}
|
||||
projectsId={repo_id}
|
||||
id={id}
|
||||
attachments={attachments}
|
||||
/>
|
||||
<div className="headtitle">
|
||||
<FlexAJ>
|
||||
<span className="font-18">资源库(18)</span>
|
||||
<Blueback onClick={()=>setVisible(true)}>上传资源</Blueback>
|
||||
{ current_user && current_user.login &&
|
||||
<Blueback onClick={()=>{setId(undefined);setVisible(true);}}>上传资源</Blueback>
|
||||
}
|
||||
</FlexAJ>
|
||||
</div>
|
||||
<FlexAJ className="subHeadtitle">
|
||||
|
@ -119,43 +159,59 @@ function Index(props){
|
|||
<span className="color-grey-9">{sort[sortValue]}<i className="iconfont icon-sanjiaoxing-down font-16 color-grey-9 ml3"></i></span>
|
||||
</Dropdown>
|
||||
</FlexAJ>
|
||||
<div className="bodycontent">
|
||||
<ul className="bodycontentul">
|
||||
{
|
||||
data && data.length> 0 && data.map((item,key)=>{
|
||||
return(
|
||||
<li>
|
||||
<Link to= {`/users/${item.login}`} className="infoImg"><img src={getImageUrl(`${item.imageUrl}`)} alt="" /></Link>
|
||||
<div style={{flex:'1',width:"0"}}>
|
||||
<FlexAJ>
|
||||
<a href={``} className="infoname">{item.fileName}</a>
|
||||
<Dropdown overlay={listmenu} placement={'bottomRight'}>
|
||||
<i className="iconfont icon-gengduo1 color-grey-6"></i>
|
||||
</Dropdown>
|
||||
</FlexAJ>
|
||||
<p className="infos">
|
||||
<span>上传时间:<span>{item.uploadTime}</span></span>
|
||||
<span>文件大小:<span>{item.fileSize}</span></span>
|
||||
<span>下载:<span>{item.download}</span></span>
|
||||
</p>
|
||||
<p className="infodesc task-hide-2">{item.remark}</p>
|
||||
{ item.tags && item.tags.length>0 &&
|
||||
<div className="infotag">
|
||||
{
|
||||
item.tags.map((i,k)=>{
|
||||
return(
|
||||
<span>{i}<i className="iconfont icon-guanbi font-12 ml2" onClick={removeTagFunc}></i></span>
|
||||
)
|
||||
})
|
||||
<Spin spinning={isSpin}>
|
||||
<div className="bodycontent">
|
||||
{
|
||||
data && data.length> 0 &&
|
||||
<ul className="bodycontentul">
|
||||
{
|
||||
data.map((item,key)=>{
|
||||
return(
|
||||
<li>
|
||||
<Link to= {`/users/${item.login}`} className="infoImg"><img src={getImageUrl(`${item.imageUrl}`)} alt="" /></Link>
|
||||
<div style={{flex:'1',width:"0"}}>
|
||||
<FlexAJ>
|
||||
<a href={``} className="infoname">{item.fileName}</a>
|
||||
{ current_user && current_user.login &&
|
||||
<Dropdown overlay={()=>listmenu(item.id,item.attachments)} placement={'bottomRight'}>
|
||||
<i className="iconfont icon-gengduo1 color-grey-6"></i>
|
||||
</Dropdown>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
}
|
||||
</ul>
|
||||
</FlexAJ>
|
||||
<p className="infos">
|
||||
<span>上传时间:<span>{item.uploadTime}</span></span>
|
||||
<span>文件大小:<span>{item.fileSize}</span></span>
|
||||
<span>下载:<span>{item.download}</span></span>
|
||||
</p>
|
||||
<p className="infodesc task-hide-2">{item.remark}</p>
|
||||
{ item.tags && item.tags.length>0 &&
|
||||
<div className="infotag">
|
||||
{
|
||||
item.tags.map((i,k)=>{
|
||||
return(
|
||||
<span>{i}
|
||||
{
|
||||
current_user && (current_user.login === item.login) ?
|
||||
<Popconfirm title="确定要删除当前标签?" onConfirm={()=>removeTagFunc(item.id,i)} okText="是" cancelText="否">
|
||||
<i className="iconfont icon-guanbi font-12 ml2"></i>
|
||||
</Popconfirm>:""
|
||||
}
|
||||
</span>
|
||||
)
|
||||
})
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
{
|
||||
((data && data.length === 0) || error) && <Nodata _html="暂无数据"/>
|
||||
}
|
||||
{
|
||||
total > limit &&
|
||||
<div className="pt20 pb20 edu-txt-center">
|
||||
|
@ -169,6 +225,7 @@ function Index(props){
|
|||
</div>
|
||||
}
|
||||
</div>
|
||||
</Spin>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
}
|
||||
.bodycontent{
|
||||
padding:0px 20px;
|
||||
min-height: 500px;
|
||||
& > ul.bodycontentul > li{
|
||||
display: flex;
|
||||
border-bottom: 1px solid #eee;
|
||||
|
|
|
@ -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 <AlignCenter>
|
||||
<div className="task-hide" style={{maxWidth:key===0 ? "250px":"100%"}}>{value}</div>
|
||||
<div className="task-hide" style={{maxWidth:key===0 ? "240px":"100%"}}>{value}</div>
|
||||
{ key === 0 && <span className="currentTip">当前版本</span> }
|
||||
</AlignCenter>
|
||||
}
|
||||
},
|
||||
{
|
||||
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(
|
||||
<Modal
|
||||
title={"上传资源"}
|
||||
title={id?"更新资源版本":"上传资源"}
|
||||
closable={false}
|
||||
visible={visible}
|
||||
onCancel={onCancel}
|
||||
|
@ -101,8 +118,8 @@ function UploadSource({ form , visible , onCancel , onOk , showNotification ,own
|
|||
>
|
||||
<div>
|
||||
<Form>
|
||||
<Table className="versionTable" columns={columns} dataSource={tableData} pagination={false} size={"small"}/>
|
||||
<Form.Item>
|
||||
{id && <Table className="versionTable mb20" columns={columns} dataSource={tableData} pagination={false} size={"small"}/> }
|
||||
<Form.Item style={{display:id?"none":"block"}}>
|
||||
{getFieldDecorator("tagNames",{
|
||||
rules:[]
|
||||
})(
|
||||
|
|
Loading…
Reference in New Issue