From 4f597bd257d73bf7ca73d17f294126d7b020daf8 Mon Sep 17 00:00:00 2001 From: caicai8 <1149225589@qq.com> Date: Fri, 17 Apr 2020 17:35:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=BA=93=E6=A8=A1=E5=9D=97-?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=AD=90=E7=9B=AE=E5=BD=95=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E4=BB=A5=E5=8F=8A=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E7=AD=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AppConfig.js | 30 ++-- src/forge/Main/CoderRootDirectory.js | 209 +++++++++++++++----------- src/forge/Main/CoderRootFileDetail.js | 7 - src/forge/Main/Detail.js | 5 + src/forge/Main/IndexItem.js | 2 +- src/modules/tpm/NewHeader.js | 14 +- 6 files changed, 149 insertions(+), 118 deletions(-) diff --git a/src/AppConfig.js b/src/AppConfig.js index fcbd188e..5e9c21fd 100644 --- a/src/AppConfig.js +++ b/src/AppConfig.js @@ -226,26 +226,26 @@ export function initAxiosInterceptors(props) { // let timestamp=railsgettimes(proxy); // console.log(timestamp) // `https://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp` - railsgettimes( `${proxy}/api/main/first_stamp.json`); - let newopens=md5(opens+timestamp) - config.url = `${proxy}${url}`; - if (config.url.indexOf('?') == -1) { - config.url = `${config.url}?debug=${debugType}&randomcode=${timestamp}&client_key=${newopens}`; - } else { - config.url = `${config.url}&debug=${debugType}&randomcode=${timestamp}&client_key=${newopens}`; - } + // railsgettimes( `${proxy}/api/main/first_stamp.json`); + // let newopens=md5(opens+timestamp) + config.url = `${proxy}${url}`; + if (config.url.indexOf('?') == -1) { + config.url = `${config.url}?debug=${debugType}`; + } else { + config.url = `${config.url}&debug=${debugType}`; + } } else { // 加api前缀 // railsgettimes(`http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp`); - railsgettimes( `/api/main/first_stamp.json`); - let newopens=md5(opens+timestamp) + // railsgettimes( `/api/main/first_stamp.json`); + // let newopens=md5(opens+timestamp) config.url = url; - if (config.url.indexOf('?') == -1) { - config.url = `${config.url}?randomcode=${timestamp}&client_key=${newopens}`; - } else { - config.url = `${config.url}&randomcode=${timestamp}&client_key=${newopens}`; - } + // if (config.url.indexOf('?') == -1) { + // config.url = `${config.url}?randomcode=${timestamp}&client_key=${newopens}`; + // } else { + // config.url = `${config.url}&randomcode=${timestamp}&client_key=${newopens}`; + // } } setpostcookie(); } diff --git a/src/forge/Main/CoderRootDirectory.js b/src/forge/Main/CoderRootDirectory.js index a7f63915..4c5f1a2a 100644 --- a/src/forge/Main/CoderRootDirectory.js +++ b/src/forge/Main/CoderRootDirectory.js @@ -28,7 +28,7 @@ class CoderRootDirectory extends Component{ this.state={ address:"http", branch:"master", - filePath:[], + filePath:undefined, http_url:undefined, subFileType:"", readMeContent:undefined, @@ -40,7 +40,7 @@ class CoderRootDirectory extends Component{ fileDetail:undefined, branchLastCommit:undefined, - rootData:undefined, + rootList:undefined, readOnly: true } } @@ -50,18 +50,49 @@ class CoderRootDirectory extends Component{ }) } - componentDidMount=()=>{ + componentDidMount=()=>{ + this.Init(); + } + + componentDidUpdate=(prevState)=>{ + const {location} = this.props; + const prevlocation = prevState && prevState.location; + if(location !== prevlocation){ + this.setState({ + isSpin:true + }) + this.Init(); + } + } + + Init=()=>{ let { search } = this.props.history.location; let branchName = undefined; if(search && search.indexOf("branch")>-1){ - branchName = search.split("=")[1]; + branchName = search.split("branch=")[1]; this.setState({ branch:branchName }) } - const { branch } = this.state; - this.getProjectRoot(branchName || branch); + const { pathname } = this.props.location; + if(pathname && pathname.indexOf("/filesurl/")>-1){ + let url =pathname.split("filesurl/")[1]; + this.setState({ + filePath:url + }) + this.getFileDetail(url); + }else{ + const { branch } = this.state; + this.getProjectRoot( branchName || branch); + } + } + + // 页面地址返回到主目录 + returnMain=(branch)=>{ + const { projectsId } = this.props.match.params; + this.props.history.push(`/projects/${projectsId}/coders`); + this.getProjectRoot(branch); } // 获取根目录 @@ -76,14 +107,14 @@ class CoderRootDirectory extends Component{ if(result){ if(result && result.data && result.data.length > 0){ this.setState({ - filePath:[], + filePath:undefined, fileDetail:undefined, isSpin: false }) this.renderData(result.data); } this.setState({ - rootData:result.data, + rootList:result.data, subFileType: "dir" }) } @@ -92,11 +123,9 @@ class CoderRootDirectory extends Component{ } ChangeFile=(arr,readOnly)=>{ - console.log("atrr", arr) - this.renderUrl(arr.name,arr.path,arr.type); + const { projectsId } = this.props.match.params; //点击直接跳转页面 加载一次路由 - - this.getFileDetail(arr); + this.props.history.push(`/projects/${projectsId}/coders/filesurl/${arr.path}`); this.setState({ subFileType:arr.type, readOnly: readOnly @@ -118,6 +147,9 @@ class CoderRootDirectory extends Component{ type:(filePath && filePath.length>0) ? (filePath[k] ? filePath[k].type : type) : type }) }) + const { projectsId } = this.props.match.params; + //点击直接跳转页面 加载一次路由 + this.props.history.push(`/projects/${projectsId}/coders/filesurl/${str.substr(1)}`); }else{ list.push({ index:0, @@ -130,30 +162,30 @@ class CoderRootDirectory extends Component{ } // 获取子目录 - getFileDetail=(arr)=>{ + getFileDetail=(path)=>{ const { projectsId } = this.props.match.params; const { branch } = this.state; const url =`/repositories/${projectsId}/sub_entries.json`; axios.get(url,{ params:{ - filepath:arr.path, + filepath:path, ref:branch } }).then((result)=>{ if(result && result.data && result.data.length > 0){ - if(arr.type==="file"){ + // 当前返回的子目录只有一条数据,且这条数据返回的是文件类型 + if(result.data.length === 1 && result.data[0].type === "file"){ this.setState({ - fileDetail:result.data[0], - rootList:undefined + fileDetail:result.data, + rootList:undefined, + isSpin:false }) }else{ - if(arr.type===""){ - this.props.showNotification('该文件夹下已无文件') - return - } this.setState({ - fileDetail:undefined + fileDetail:undefined, + rootList:result.data, + isSpin:false }) this.renderData(result.data) } @@ -184,6 +216,12 @@ class CoderRootDirectory extends Component{ }) } + // 点击跳转到子目录 + goToSubRoot=(path)=>{ + const { projectsId } = this.props.match.params; + this.props.history.push(`/projects/${projectsId}/coders/filesurl/${path}`); + } + // readme文件内容 renderReadMeContent=(readMeContent, permission)=>{ const { fileDetail,readMeFile } = this.state; @@ -217,7 +255,6 @@ class CoderRootDirectory extends Component{ changeBranch=(value)=>{ const { branchList } = this.props; - let branchLastCommit = branchList && branchList.length >0 && branchList.filter(item=>item.name === value)[0]; this.setState({ branch:branchLastCommit && branchLastCommit.name, @@ -225,20 +262,21 @@ class CoderRootDirectory extends Component{ http_url:branchLastCommit && branchLastCommit.http_url, isSpin: true }) - this.getProjectRoot(branchLastCommit.name); + this.Init(); } render(){ - const { rootList , branch ,filePath , fileDetail , subFileType , readMeContent, isSpin , rootData } = this.state; + const { rootList , branch ,filePath , fileDetail , subFileType , readMeContent, isSpin } = this.state; const { branchLastCommit , http_url , isManager , isDeveloper } = this.props; const { projectsId } = this.props.match.params; + const columns = [ { dataIndex: 'name', width:"100%", render: (text,item) => ( - this.ChangeFile(item,true)}> + this.goToSubRoot(item.path)}> {text} ), @@ -279,77 +317,72 @@ class CoderRootDirectory extends Component{ } } - const urlRoot = filePath && filePath.length > 0 ? `/${filePath[filePath.length - 1].path}` : ""; + const urlRoot = `/${filePath}`; const { projectDetail } = this.props; + let array = filePath && filePath.split("/"); return( - - { - rootData && - - { - rootData.length > 0 ? - - - - - - { - filePath && filePath.length > 0 && - - this.getProjectRoot(branch)} className="color-blue">{ projectDetail && projectDetail.identifier } - { - filePath.map((item,key)=>{ - return( - - { - key === filePath.length-1 ? - {item.name} - : - this.ChangeFile(item,true)} className="color-blue subFileName" key={key}>{item.name} - } - - ) - }) - } - - - } - - - - { - subFileType !== "file" && (isManager || isDeveloper) && - - 新建文件 - {/* 上传文件 */} - - } - { - filePath && filePath.length === 0 && - } - + + {(rootList && rootList.length > 0) || (fileDetail && fileDetail.length > 0) ? + + + + + + + { + filePath && + + this.returnMain(branch)} className="color-blue">{ projectDetail && projectDetail.identifier } + { + array && array.map((item,key)=>{ + return( + + { + key === array.length-1 ? + {item} + : + key === 0? + {item} + : + {item} + } + + ) + }) + } + + } - - {/* 文件夹-子目录列表 */} + { - rootList && title()}> + subFileType !== "file" && (isManager || isDeveloper) && + + 新建文件 + } - { - fileDetail && - + filePath && filePath.length === 0 && } - - {/* readme.txt */} - { this.renderReadMeContent(readMeContent,(isManager || isDeveloper)) } - + - : - - } - + {/* 主目录列表 */} + { + rootList && + title()}> + + } + {/* 子目录列表、文件 */} + { + fileDetail && fileDetail.length>0 && + + } + {/* readme.txt (isManager || isDeveloper)*/} + { this.renderReadMeContent(readMeContent,(isManager || isDeveloper)) } + + : + } - + ) } } diff --git a/src/forge/Main/CoderRootFileDetail.js b/src/forge/Main/CoderRootFileDetail.js index 728afdb3..2ae12f94 100644 --- a/src/forge/Main/CoderRootFileDetail.js +++ b/src/forge/Main/CoderRootFileDetail.js @@ -152,13 +152,6 @@ class CoderRootFileDetail extends Component{ : - // } diff --git a/src/forge/Main/Detail.js b/src/forge/Main/Detail.js index 438960c2..04ff54c6 100644 --- a/src/forge/Main/Detail.js +++ b/src/forge/Main/Detail.js @@ -505,6 +505,11 @@ class Detail extends Component{ (props) => () } > + () + } + > () diff --git a/src/forge/Main/IndexItem.js b/src/forge/Main/IndexItem.js index 785d3dbf..65ccd1cd 100644 --- a/src/forge/Main/IndexItem.js +++ b/src/forge/Main/IndexItem.js @@ -26,7 +26,7 @@ class IndexItem extends Component{ - + {item.author.name}/{item.name} { item.forked_from_project_id ? diff --git a/src/modules/tpm/NewHeader.js b/src/modules/tpm/NewHeader.js index aca24299..00a1663f 100644 --- a/src/modules/tpm/NewHeader.js +++ b/src/modules/tpm/NewHeader.js @@ -1263,19 +1263,19 @@ submittojoinclass=(value)=>{ { - mygetHelmetapi2 && mygetHelmetapi2.new_course.edit_account && + mygetHelmetapi2 && mygetHelmetapi2.new_course && mygetHelmetapi2.new_course.edit_account && 修改资料 } { - mygetHelmetapi2 && mygetHelmetapi2.new_course.my_courses && + mygetHelmetapi2 && mygetHelmetapi2.new_course && mygetHelmetapi2.new_course.my_courses && 我的课程 } { - mygetHelmetapi2 && mygetHelmetapi2.new_course.my_projects && + mygetHelmetapi2 && mygetHelmetapi2.new_course && mygetHelmetapi2.new_course.my_projects && 我的项目 } { - mygetHelmetapi2 && mygetHelmetapi2.new_course.my_organ && + mygetHelmetapi2 && mygetHelmetapi2.new_course && mygetHelmetapi2.new_course.my_organ && 我的组织 } {/*{user.username}*/} @@ -1344,8 +1344,8 @@ submittojoinclass=(value)=>{ {/*pathstype===true?"":this.props.user&&this.props.user.admin===true||this.props.user&&this.props.user.is_teacher===true||this.props.user&&this.props.user.business===true?this.getUser("/paths/new")} >新建实践课程:""*/} {/*}*/} {/*{this.props.user&&this.props.user.login?this.getUser("/projects/new","projects")} target="_blank">新建开发项目:""}*/} - 新建课程 - 新建班级 + 新建课程 + 新建班级 {coursestypes===true&&this.props.user&&this.props.user.main_site===false?"": 新建镜像项目 @@ -1422,7 +1422,7 @@ submittojoinclass=(value)=>{ {this.props.user&&this.props.user.login? { user===undefined?"":user.login===""?"":
- 新建文件 - {/* 上传文件 */} -
+ 新建文件 +