RepositoryChooseModal

dev_cs
hjm 6 years ago
parent b3c3c0f148
commit 43106e48cf

@ -1,153 +1,153 @@
import React, { useState, useEffect, memo } from 'react'; // import React, { useState, useEffect, memo } from 'react';
import axios from 'axios' // import axios from 'axios'
import { Modal, Input } from 'antd'; // import { Modal, Input } from 'antd';
function RepositoryChooseModal(props) { // function RepositoryChooseModal(props) {
const [trees, setTrees] = useState([]) // const [trees, setTrees] = useState([])
const [path, setPath] = useState('') // const [path, setPath] = useState('')
const [pathArray, setPathArray] = useState([{val: "根目录/", path: ""}]) // const [pathArray, setPathArray] = useState([{val: "根目录/", path: ""}])
const [modalVisible, setModalVisible] = useState(true) // const [modalVisible, setModalVisible] = useState(true)
useEffect(() => { // useEffect(() => {
repository('') // repository('')
}, []) // }, [])
function onOk() { // function onOk() {
} // }
function onCancel() { // function onCancel() {
} // }
/** // /**
点nav 会传入key // 点nav 会传入key
点item 会传入 newPath // 点item 会传入 newPath
item => name, type type tree/leaf // item => name, type type tree/leaf
*/ // */
const repository=(item, key, newPath)=>{ // const repository=(item, key, newPath)=>{
let newPathArray = [] // // let newPathArray = [] //
// // //
if (key) { // if (key) {
for(var i=0; i<=key; i++){ // for(var i=0; i<=key; i++){
newPathArray.push(pathArray[i]) // newPathArray.push(pathArray[i])
} // }
} else if (item) { // } else if (item) {
newPathArray = pathArray.slice(0) // newPathArray = pathArray.slice(0)
newPathArray.push({val: item.name, path: pathArray[pathArray.length - 1] + "/" + item.name}) // newPathArray.push({val: item.name, path: pathArray[pathArray.length - 1] + "/" + item.name})
} // }
const path = item || key ? newPathArray[newPathArray.length - 1] : '' // const path = item || key ? newPathArray[newPathArray.length - 1] : ''
let id = props.match.params.shixunId; // let id = props.match.params.shixunId;
let url ="/shixuns/"+id+"/repository.json"; // let url ="/shixuns/"+id+"/repository.json";
axios.post(url,{ // axios.post(url,{
path: path // path: path
}).then((response) => { // }).then((response) => {
if (response.data.status === 403||response.data.status === 401||response.data.status === 500) { // if (response.data.status === 403||response.data.status === 401||response.data.status === 500) {
}else{ // }else{
setTrees(response.data.trees) // setTrees(response.data.trees)
setPath(path) // setPath(path)
pathArray(newPathArray) // pathArray(newPathArray)
} // }
}).catch((error) => { // }).catch((error) => {
console.log(error) // console.log(error)
}); // });
} // }
const savegetfilepath=(value)=>{ // const savegetfilepath=(value)=>{
const state = {} // const state = {}
let {selectpath,saveshixunfilepath,pathtype} = state // let {selectpath,saveshixunfilepath,pathtype} = state
if(pathtype===1){ // if(pathtype===1){
let newselectpath; // let newselectpath;
if(saveshixunfilepath==="shixunfilepathplay"){ // if(saveshixunfilepath==="shixunfilepathplay"){
newselectpath=value // newselectpath=value
}else{ // }else{
const type = selectpath.split(''); // const type = selectpath.split('');
let types=false; // let types=false;
for(var i=0; i<type.length; i++){ // for(var i=0; i<type.length; i++){
if(type[i]===value){ // if(type[i]===value){
types=true // types=true
return // return
} // }
} // }
if(types===false){ // if(types===false){
newselectpath=selectpath+value+ "" // newselectpath=selectpath+value+ ""
}else{ // }else{
newselectpath=selectpath // newselectpath=selectpath
} // }
} // }
// this.setState({ // // this.setState({
// // selectpatharr:newarr, // // // selectpatharr:newarr,
// selectpath: newselectpath, // // selectpath: newselectpath,
// }) // // })
} // }
} // }
const goblakepath=(path,key)=>{ // const goblakepath=(path,key)=>{
} // }
function sendgetfilepath() { // function sendgetfilepath() {
} // }
return ( // return (
<Modal // <Modal
keyboard={false} // keyboard={false}
title="文件路径" // title="文件路径"
visible={modalVisible} // visible={modalVisible}
closable={false} // closable={false}
footer={false} // footer={false}
> // >
<div className="task_popup_con"> // <div className="task_popup_con">
<div className="newupload_conbox clearfix"> // <div className="newupload_conbox clearfix">
<ul id="directory_file"> // <ul id="directory_file">
{/*文件导航*/} // {/*文件导航*/}
{ // {
pathArray.length===0?"":pathArray.map((item,key)=>{ // pathArray.length===0?"":pathArray.map((item,key)=>{
return( // return(
<a className="f14 fb" onClick={()=>goblakepath(item.path,key,item)}>{item.val}</a> // <a className="f14 fb" onClick={()=>goblakepath(item.path,key,item)}>{item.val}</a>
) // )
}) // })
} // }
{/*文件*/} // {/*文件*/}
{trees === undefined || trees === null ? "" : trees.map((item, key) => { // {trees === undefined || trees === null ? "" : trees.map((item, key) => {
return( // return(
<li className="entry" key={key}> // <li className="entry" key={key}>
<div className="filename_no_report hidden">{ // <div className="filename_no_report hidden">{
item.type==="tree"?<a onClick={()=>sendgetfilepath(item.name,item.type,path+item.name)} data-remote="true"> // item.type==="tree"?<a onClick={()=>sendgetfilepath(item.name,item.type,path+item.name)} data-remote="true">
<i className="iconfont icon-wenjianjia color-blue mr2"></i> // <i className="iconfont icon-wenjianjia color-blue mr2"></i>
{path+item.name}</a>:<a data-remote="true"> // {path+item.name}</a>:<a data-remote="true">
<i className="iconfont icon-zuoye color-blue mr2"></i> // <i className="iconfont icon-zuoye color-blue mr2"></i>
<span onClick={()=>savegetfilepath(path+item.name,item.type)}>{path+item.name}</span> // <span onClick={()=>savegetfilepath(path+item.name,item.type)}>{path+item.name}</span>
</a> // </a>
} // }
</div> // </div>
</li> // </li>
) // )
})} // })}
</ul> // </ul>
<div className="clearfix mt20"> // <div className="clearfix mt20">
<label className="fl mt5 directory_filepath">选中的文件路径</label> // <label className="fl mt5 directory_filepath">选中的文件路径:</label>
<Input id="points_tusi" placeholder="选中的文件路径" className="fl input-60-40" // <Input id="points_tusi" placeholder="选中的文件路径" className="fl input-60-40"
style={{width:"400px"}} // style={{width:"400px"}}
onInput={(e)=>saveselectpath(e)} // onInput={(e)=>saveselectpath(e)}
value={path}/> // value={path}/>
</div> // </div>
<a className="task-btn task-btn-orange fr" // <a className="task-btn task-btn-orange fr"
style={{marginTop: '20px',marginLeft:'20px'}} id="add_path" onClick={()=>onOk()}>确定</a> // style={{marginTop: '20px',marginLeft:'20px'}} id="add_path" onClick={()=>onOk()}>确定</a>
<a className="pop_close task-btn mb10 fr" // <a className="pop_close task-btn mb10 fr"
style={{marginTop: '20px'}} id="back_page" onClick={()=>onCancel()}>取消</a> // style={{marginTop: '20px'}} id="back_page" onClick={()=>onCancel()}>取消</a>
</div> // </div>
</div> // </div>
</Modal> // </Modal>
) // )
} // }
export default RepositoryChooseModal // export default RepositoryChooseModal
Loading…
Cancel
Save