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)=>{
// }
// function sendgetfilepath() {
// }
// return (
// <Modal
// keyboard={false}
// title="文件路径"
// visible={modalVisible}
// closable={false}
// footer={false}
// >
// <div className="task_popup_con">
// <div className="newupload_conbox clearfix">
// <ul id="directory_file">
// {/*文件导航*/}
// {
// pathArray.length===0?"":pathArray.map((item,key)=>{
// return(
// <a className="f14 fb" onClick={()=>goblakepath(item.path,key,item)}>{item.val}</a>
// )
// }) // })
} // }
// {/*文件*/}
} // {trees === undefined || trees === null ? "" : trees.map((item, key) => {
const goblakepath=(path,key)=>{ // return(
// <li className="entry" key={key}>
} // <div className="filename_no_report hidden">{
function sendgetfilepath() { // 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>
} // {path+item.name}</a>:<a data-remote="true">
return ( // <i className="iconfont icon-zuoye color-blue mr2"></i>
<Modal // <span onClick={()=>savegetfilepath(path+item.name,item.type)}>{path+item.name}</span>
keyboard={false} // </a>
title="文件路径" // }
visible={modalVisible} // </div>
closable={false} // </li>
footer={false}
> // )
<div className="task_popup_con"> // })}
<div className="newupload_conbox clearfix">
<ul id="directory_file"> // </ul>
{/*文件导航*/} // <div className="clearfix mt20">
{ // <label className="fl mt5 directory_filepath">选中的文件路径:</label>
pathArray.length===0?"":pathArray.map((item,key)=>{ // <Input id="points_tusi" placeholder="选中的文件路径" className="fl input-60-40"
return( // style={{width:"400px"}}
<a className="f14 fb" onClick={()=>goblakepath(item.path,key,item)}>{item.val}</a> // onInput={(e)=>saveselectpath(e)}
) // value={path}/>
}) // </div>
}
{/*文件*/} // <a className="task-btn task-btn-orange fr"
{trees === undefined || trees === null ? "" : trees.map((item, key) => { // style={{marginTop: '20px',marginLeft:'20px'}} id="add_path" onClick={()=>onOk()}>确定</a>
return( // <a className="pop_close task-btn mb10 fr"
<li className="entry" key={key}> // style={{marginTop: '20px'}} id="back_page" onClick={()=>onCancel()}>取消</a>
<div className="filename_no_report hidden">{ // </div>
item.type==="tree"?<a onClick={()=>sendgetfilepath(item.name,item.type,path+item.name)} data-remote="true"> // </div>
<i className="iconfont icon-wenjianjia color-blue mr2"></i> // </Modal>
{path+item.name}</a>:<a data-remote="true"> // )
<i className="iconfont icon-zuoye color-blue mr2"></i>
<span onClick={()=>savegetfilepath(path+item.name,item.type)}>{path+item.name}</span> // }
</a>
} // export default RepositoryChooseModal
</div>
</li>
)
})}
</ul>
<div className="clearfix mt20">
<label className="fl mt5 directory_filepath">选中的文件路径</label>
<Input id="points_tusi" placeholder="选中的文件路径" className="fl input-60-40"
style={{width:"400px"}}
onInput={(e)=>saveselectpath(e)}
value={path}/>
</div>
<a className="task-btn task-btn-orange fr"
style={{marginTop: '20px',marginLeft:'20px'}} id="add_path" onClick={()=>onOk()}>确定</a>
<a className="pop_close task-btn mb10 fr"
style={{marginTop: '20px'}} id="back_page" onClick={()=>onCancel()}>取消</a>
</div>
</div>
</Modal>
)
}
export default RepositoryChooseModal
Loading…
Cancel
Save