资源库模块测试版第一次上线

This commit is contained in:
caishi 2021-04-06 17:17:01 +08:00
parent f0858e7ecc
commit b6dc01b0be
4 changed files with 146 additions and 38 deletions

View File

@ -0,0 +1,47 @@
import React , { forwardRef, useEffect } from 'react';
import { Modal , Form , Input } from 'antd';
function AddTag({form , visible , onCancel ,onOk}){
const { getFieldDecorator, validateFields , setFieldsValue } = form;
useEffect(()=>{
setFieldsValue({tagName:undefined})
},[visible])
function submit(){
validateFields((error,values)=>{
if(!error){
onOk(values);
}
})
}
const layout = {
labelCol: { span: 5 },
wrapperCol: { span: 18 },
};
return(
<Modal
title={"新增标签"}
closable={false}
visible={visible}
onCancel={onCancel}
onOk={submit}
cancelText="取消"
okText="确定"
width="400px"
centered
>
<Form {...layout}>
<Form.Item label="标签名">
{getFieldDecorator("tagName",{
rules:[{required:true,message:"请输入标签名"}]
})(
<Input placeholder="请输入标签名" width="200px" autoComplete="off" />
)}
</Form.Item>
</Form>
</Modal>
)
}
export default Form.create()(forwardRef(AddTag));

View File

@ -1,9 +1,10 @@
import React, { useEffect, useState } from 'react';
import './Index.scss';
import { Blueback , FlexAJ } from '../Component/layout';
import { Dropdown, Input , Menu , Pagination, Spin , Popconfirm } 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';
@ -29,6 +30,8 @@ function Index(props){
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;
@ -83,18 +86,34 @@ function Index(props){
</Menu>
)
function listmenu(id,attachments){
function listmenu(id,attachments,isPublic){
return(
<Menu>
<Menu.Item onClick={()=>{setId(id);setVisible(true);setAttachments(attachments)}}>更新版本</Menu.Item>
<Menu.Item>设为私有</Menu.Item>
<Menu.Item onClick={()=>changeStatus(id,isPublic===1?0:1)}>{isPublic === 1 ? "设为私有":"设为公开"}</Menu.Item>
<Menu.Item onClick={()=>deleteSourceFunc(id)}>删除资源</Menu.Item>
</Menu>
)
}
//
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"){
@ -104,11 +123,15 @@ function Index(props){
}
})
}
})
}
//
function onOk(){
setVisible(false);
setIsSpin(true);
getData();
}
@ -126,9 +149,36 @@ function Index(props){
}).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(
<div className="sourcePanel">
<AddTag
visible={addVisible}
onCancel={onCancelAdd}
onOk={sureAddTag}
/>
<UploadSource
visible={visible}
onCancel={()=>setVisible(false)}
@ -142,8 +192,8 @@ function Index(props){
<div className="headtitle">
<FlexAJ>
<span className="font-18">资源库(18)</span>
{ current_user && current_user.login &&
<Blueback onClick={()=>{setId(undefined);setVisible(true);}}>上传资源</Blueback>
{ current_user && current_user.login && (props.projectDetail && props.projectDetail.permission) ?
<Blueback onClick={()=>{setId(undefined);setVisible(true);}}>上传资源</Blueback>:""
}
</FlexAJ>
</div>
@ -171,9 +221,13 @@ function Index(props){
<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>
<AlignCenter>
<a href={https+`/busiAttachments/download/${item.attachId}`} download className="infoname">{item.fileName}</a>
<a href={https + `/busiAttachments/view/${item.attachId}`}><i className="iconfont icon-shenqinggongkai font-15 ml10 color-grey-9"></i></a>
{item.isPublic === 0 && <span className="privateTip">私有</span>}
</AlignCenter>
{ current_user && current_user.login &&
<Dropdown overlay={()=>listmenu(item.id,item.attachments)} placement={'bottomRight'}>
<Dropdown overlay={()=>listmenu(item.id,item.attachments,item.isPublic)} placement={'bottomRight'}>
<i className="iconfont icon-gengduo1 color-grey-6"></i>
</Dropdown>
}
@ -184,10 +238,9 @@ function Index(props){
<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)=>{
item.tags && item.tags.length>0 && item.tags.map((i,k)=>{
return(
<span>{i}
{
@ -200,9 +253,12 @@ function Index(props){
)
})
}
</div>
{
current_user && (current_user.login === item.login) &&
<a className="color-blue font-12" onClick={()=>addPanel(item.id)} style={{height:"20px",lineHeight:"20px"}}>+新增标签</a>
}
</div>
</div>
</li>
)
})

View File

@ -41,6 +41,16 @@
.infoname{
font-size: 16px;
}
.privateTip{
display: block;
font-size: 12px;
margin-left: 10px;
background-color: orange;
height: 18px;
line-height: 18px;
padding:0px 3px;
color: #fff;
}
.infos{
& > span{
margin-right: 20px;

View File

@ -5,11 +5,6 @@ import { AlignCenter } from '../Component/layout';
import axios from 'axios';
const { TextArea } = Input;
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"},
{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 , attachments , id ,owner,projectsId}){
const [ tableData , setTableData ] = useState(undefined);