资源库部分接口调试

This commit is contained in:
caishi 2021-04-06 11:36:38 +08:00
parent 8903363695
commit f9f79e0365
3 changed files with 154 additions and 79 deletions

View File

@ -1,10 +1,11 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import './Index.scss'; import './Index.scss';
import { Blueback , FlexAJ } from '../Component/layout'; 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 { Link } from 'react-router-dom';
import UploadSource from './UploadSource'; import UploadSource from './UploadSource';
import { getImageUrl } from 'educoder'; import { getImageUrl } from 'educoder';
import Nodata from '../Nodata';
import axios from 'axios'; import axios from 'axios';
const { Search } = Input; const { Search } = Input;
@ -21,13 +22,20 @@ function Index(props){
const [ total , setTotal ] = useState(0); const [ total , setTotal ] = useState(0);
const [ search , setSearch ] = useState(undefined); const [ search , setSearch ] = useState(undefined);
const [ data , setData ] = 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 [ visible , setVisible ] = useState(false);
const repo_id = props.projectDetail && props.projectDetail.repo_id; const repo_id = props.projectDetail && props.projectDetail.repo_id;
const owner = props.match.params.owner; const owner = props.match.params.owner;
const current_user = props.current_user;
useEffect(()=>{ useEffect(()=>{
if(owner && repo_id){ if(owner && repo_id){
setIsSpin(true);
getData(); getData();
} }
},[repo_id,owner,search,sortValue,page]) },[repo_id,owner,search,sortValue,page])
@ -46,8 +54,10 @@ function Index(props){
if(result && result.data){ if(result && result.data){
setData(result.data.data.rows); setData(result.data.data.rows);
setTotal(result.data.data.total); 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> </Menu>
) )
const listmenu=( function listmenu(id,attachments){
<Menu> return(
<Menu.Item>更新版本</Menu.Item> <Menu>
<Menu.Item>设为私有</Menu.Item> <Menu.Item onClick={()=>{setId(id);setVisible(true);setAttachments(attachments)}}>更新版本</Menu.Item>
<Menu.Item>删除资源</Menu.Item> <Menu.Item>设为私有</Menu.Item>
</Menu> <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(){ function onOk(){
setVisible(false);
getData(); 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( return(
<div className="sourcePanel"> <div className="sourcePanel">
<UploadSource <UploadSource
@ -100,11 +136,15 @@ function Index(props){
showNotification={props.showNotification} showNotification={props.showNotification}
owner={owner} owner={owner}
projectsId={repo_id} projectsId={repo_id}
id={id}
attachments={attachments}
/> />
<div className="headtitle"> <div className="headtitle">
<FlexAJ> <FlexAJ>
<span className="font-18">资源库(18)</span> <span className="font-18">资源库(18)</span>
<Blueback onClick={()=>setVisible(true)}>上传资源</Blueback> { current_user && current_user.login &&
<Blueback onClick={()=>{setId(undefined);setVisible(true);}}>上传资源</Blueback>
}
</FlexAJ> </FlexAJ>
</div> </div>
<FlexAJ className="subHeadtitle"> <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> <span className="color-grey-9">{sort[sortValue]}<i className="iconfont icon-sanjiaoxing-down font-16 color-grey-9 ml3"></i></span>
</Dropdown> </Dropdown>
</FlexAJ> </FlexAJ>
<div className="bodycontent"> <Spin spinning={isSpin}>
<ul className="bodycontentul"> <div className="bodycontent">
{ {
data && data.length> 0 && data.map((item,key)=>{ data && data.length> 0 &&
return( <ul className="bodycontentul">
<li> {
<Link to= {`/users/${item.login}`} className="infoImg"><img src={getImageUrl(`${item.imageUrl}`)} alt="" /></Link> data.map((item,key)=>{
<div style={{flex:'1',width:"0"}}> return(
<FlexAJ> <li>
<a href={``} className="infoname">{item.fileName}</a> <Link to= {`/users/${item.login}`} className="infoImg"><img src={getImageUrl(`${item.imageUrl}`)} alt="" /></Link>
<Dropdown overlay={listmenu} placement={'bottomRight'}> <div style={{flex:'1',width:"0"}}>
<i className="iconfont icon-gengduo1 color-grey-6"></i> <FlexAJ>
</Dropdown> <a href={``} className="infoname">{item.fileName}</a>
</FlexAJ> { current_user && current_user.login &&
<p className="infos"> <Dropdown overlay={()=>listmenu(item.id,item.attachments)} placement={'bottomRight'}>
<span>上传时间<span>{item.uploadTime}</span></span> <i className="iconfont icon-gengduo1 color-grey-6"></i>
<span>文件大小<span>{item.fileSize}</span></span> </Dropdown>
<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>
)
})
} }
</div> </FlexAJ>
} <p className="infos">
</div> <span>上传时间<span>{item.uploadTime}</span></span>
</li> <span>文件大小<span>{item.fileSize}</span></span>
) <span>下载<span>{item.download}</span></span>
}) </p>
} <p className="infodesc task-hide-2">{item.remark}</p>
</ul> { 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 && total > limit &&
<div className="pt20 pb20 edu-txt-center"> <div className="pt20 pb20 edu-txt-center">
@ -169,6 +225,7 @@ function Index(props){
</div> </div>
} }
</div> </div>
</Spin>
</div> </div>
) )
} }

View File

@ -21,6 +21,7 @@
} }
.bodycontent{ .bodycontent{
padding:0px 20px; padding:0px 20px;
min-height: 500px;
& > ul.bodycontentul > li{ & > ul.bodycontentul > li{
display: flex; display: flex;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;

View File

@ -11,12 +11,17 @@ 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'; const https = 'https://testfiles.trustie.net';
function UploadSource({ form , visible , onCancel , onOk , showNotification ,owner,projectsId}){ function UploadSource({ form , visible , onCancel , onOk , showNotification , attachments , id ,owner,projectsId}){
const [ tableData , setTableData ] = useState(data); const [ tableData , setTableData ] = useState(undefined);
const [ fileId , setFilesId ] = useState(undefined); const [ fileId , setFilesId ] = useState(undefined);
const [ fileName , setFileName ] = useState(undefined); const [ fileName , setFileName ] = useState(undefined);
const { getFieldDecorator, validateFields , setFieldsValue } = form; const { getFieldDecorator, validateFields , setFieldsValue } = form;
useEffect(()=>{
if(id && attachments){
setTableData(attachments);
}
},[id,attachments])
// id // id
function UploadFunc(id,name){ function UploadFunc(id,name){
setFilesId(id); setFilesId(id);
@ -25,37 +30,36 @@ function UploadSource({ form , visible , onCancel , onOk , showNotification ,own
const columns = [ const columns = [
{ {
dataIndex:"name", dataIndex:"fileName",
key:"name", key:"fileName",
title:"资源名称", title:"资源名称",
width:"45%", width:"42%",
ellipsis:true, ellipsis:true,
render:(value,item,key)=>{ render:(value,item,key)=>{
return <AlignCenter> 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> } { key === 0 && <span className="currentTip">当前版本</span> }
</AlignCenter> </AlignCenter>
} }
}, },
{ {
dataIndex:"loadNum", dataIndex:"downloads",
key:"loadNum", key:"downloads",
title:"下载数", title:"下载数",
width:"15%", width:"14%",
className:"edu-txt-center" className:"edu-txt-center"
}, },
{ {
dataIndex:"citeNum", dataIndex:"fileSizeString",
key:"citeNum", key:"fileSizeString",
title:"引用数", title:"文件大小",
width:"15%", width:"16%",
className:"edu-txt-center" className:"edu-txt-center"
}, },
{ {
dataIndex:"time", dataIndex:"createdAt",
key:"time", key:"createdAt",
title:"上传时间", title:"上传时间",
width:"25%"
} }
] ]
@ -74,22 +78,35 @@ function UploadSource({ form , visible , onCancel , onOk , showNotification ,own
function postInfo(values){ function postInfo(values){
const url = https+`/api/project/achievement/`; 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( return(
<Modal <Modal
title={"上传资源"} title={id?"更新资源版本":"上传资源"}
closable={false} closable={false}
visible={visible} visible={visible}
onCancel={onCancel} onCancel={onCancel}
@ -101,8 +118,8 @@ function UploadSource({ form , visible , onCancel , onOk , showNotification ,own
> >
<div> <div>
<Form> <Form>
<Table className="versionTable" columns={columns} dataSource={tableData} pagination={false} size={"small"}/> {id && <Table className="versionTable mb20" columns={columns} dataSource={tableData} pagination={false} size={"small"}/> }
<Form.Item> <Form.Item style={{display:id?"none":"block"}}>
{getFieldDecorator("tagNames",{ {getFieldDecorator("tagNames",{
rules:[] rules:[]
})( })(