本地版:replaceAll无替换时报错

This commit is contained in:
caishi 2021-07-08 15:24:56 +08:00
parent 967ff385aa
commit ee1217e171
7 changed files with 87 additions and 21 deletions

View File

@ -4,6 +4,12 @@ import './Component.scss';
import axios from 'axios'; import axios from 'axios';
const { TreeNode , DirectoryTree } = Tree; const { TreeNode , DirectoryTree } = Tree;
function turnbar(str){
if(str && str.length>0 && str.indexOf("/")>-1){
return str.replaceAll('/','%2F');
}
return str;
}
function DrawerPanel({visible,onClose,branch,owner,projectsId,history, name , list}){ function DrawerPanel({visible,onClose,branch,owner,projectsId,history, name , list}){
const [ treeData , setTreeData ] = useState(undefined); const [ treeData , setTreeData ] = useState(undefined);
const [ isSpin , setIsSpin ] = useState(true); const [ isSpin , setIsSpin ] = useState(true);
@ -71,7 +77,8 @@ function DrawerPanel({visible,onClose,branch,owner,projectsId,history, name , li
let dataref = event.node.props.dataRef; let dataref = event.node.props.dataRef;
if(dataref.type==="file"){ if(dataref.type==="file"){
onClose(); onClose();
history.push(`/projects/${owner}/${projectsId}/tree/${branch.replaceAll("/","%2F")}/${dataref.path}`); let value = turnbar(branch);
history.push(`/projects/${owner}/${projectsId}/tree/${value}/${dataref.path}`);
} }
} }

View File

@ -10,6 +10,12 @@ import { Link } from 'react-router-dom';
// killed:"", // killed:"",
// pending:"" // pending:""
// } // }
function turnbar(str){
if(str && str.length>0 && str.indexOf("/")>-1){
return str.replaceAll('/','%2F');
}
return str;
}
function renderTableStatus(status) { function renderTableStatus(status) {
switch (status) { switch (status) {
case "running": case "running":
@ -65,8 +71,9 @@ function List({ list, operate , projectsId , owner , showModal , deleteFunc }){
width:"15%", width:"15%",
ellipsis:true, ellipsis:true,
render:(value,item)=>{ render:(value,item)=>{
let v = turnbar(item.branch);
return( return(
<Link to={`/projects/${owner}/${projectsId}/tree/${item.branch.replaceAll("/","%2F")}/${value}`} className="color-blue">{value}</Link> <Link to={`/projects/${owner}/${projectsId}/tree/${v}/${value}`} className="color-blue">{value}</Link>
) )
} }
}, },

View File

@ -23,6 +23,20 @@ import Nodata from '../Nodata';
/** /**
* projectDetail.type:0是托管项目1是镜像项目2是同步镜像项目(为2时不支持在线创建在线上传在线修改在线删除创建合并请求等功能) * projectDetail.type:0是托管项目1是镜像项目2是同步镜像项目(为2时不支持在线创建在线上传在线修改在线删除创建合并请求等功能)
*/ */
function turnbar(str){
if(str && str.length>0 && str.indexOf("/")>-1){
return str.replaceAll('/','%2F');
}
return str;
}
function returnbar(str){
if(str && str.length>0 && str.indexOf("%2F")>-1){
return str.replaceAll('%2F','/');
}
return str;
}
function CoderDepot(props){ function CoderDepot(props){
const [ projectDetail , setProjectDetail ]= useState(undefined); const [ projectDetail , setProjectDetail ]= useState(undefined);
const [ treeValue , setTreeValue ] = useState(undefined); const [ treeValue , setTreeValue ] = useState(undefined);
@ -52,7 +66,7 @@ function CoderDepot(props){
const owner = props.match.params.owner; const owner = props.match.params.owner;
const projectsId = props.match.params.projectsId; const projectsId = props.match.params.projectsId;
let branchName = props.match.params.branchName; let branchName = props.match.params.branchName;
branchName = branchName && branchName.replaceAll("%2F",'/'); branchName = returnbar(branchName);
const details = props.projectDetail; const details = props.projectDetail;
let pathname = props.history.location.pathname; let pathname = props.history.location.pathname;
@ -77,7 +91,7 @@ function CoderDepot(props){
useEffect(()=>{ useEffect(()=>{
if (projectsId && owner && defaultBranch){ if (projectsId && owner && defaultBranch){
let b = branchName && branchName.replaceAll("/","%2F"); let b = turnbar(branchName) ;
if(pathname.indexOf(`/projects/${owner}/${projectsId}`) > -1 && pathname.indexOf(`/tree/${b}/`) > -1) { if(pathname.indexOf(`/projects/${owner}/${projectsId}`) > -1 && pathname.indexOf(`/tree/${b}/`) > -1) {
let url = pathname.split(`/tree/${b}/`)[1]; let url = pathname.split(`/tree/${b}/`)[1];
setTreeValue(url); setTreeValue(url);
@ -163,17 +177,19 @@ function CoderDepot(props){
// //
function changeBranch(value){ function changeBranch(value){
let url = `/projects/${owner}/${projectsId}${value && `/tree/${value.replaceAll("/","%2F")}`}${treeValue ? `/${treeValue}`:""}`; let checkvalue = turnbar(value);
let url = `/projects/${owner}/${projectsId}${value && `/tree/${checkvalue}`}${treeValue ? `/${treeValue}`:""}`;
props.history.push(url); props.history.push(url);
} }
// //
function fileMenu(){ function fileMenu(){
let b = branchName || defaultBranch; let b = branchName || defaultBranch;
let checkvalue = turnbar(b);
return ( return (
<Menu> <Menu>
<Menu.Item><a onClick={()=>urlLink(`/projects/${owner}/${projectsId}/${b.replaceAll("/","%2F")}/uploadfile${treeValue === undefined ? "" : `/${treeValue}`}`)}>上传文件</a></Menu.Item> <Menu.Item><a onClick={()=>urlLink(`/projects/${owner}/${projectsId}/${checkvalue}/uploadfile${treeValue === undefined ? "" : `/${treeValue}`}`)}>上传文件</a></Menu.Item>
<Menu.Item><a onClick={()=>urlLink(`/projects/${owner}/${projectsId}/${b.replaceAll("/","%2F")}/newfile${treeValue === undefined ? "" : `/${treeValue}`}`)}>新建文件</a></Menu.Item> <Menu.Item><a onClick={()=>urlLink(`/projects/${owner}/${projectsId}/${checkvalue}/newfile${treeValue === undefined ? "" : `/${treeValue}`}`)}>新建文件</a></Menu.Item>
</Menu> </Menu>
) )
} }
@ -191,18 +207,20 @@ function CoderDepot(props){
function returnMain(){ function returnMain(){
setTreeValue(undefined); setTreeValue(undefined);
let branch = branchName || defaultBranch; let branch = branchName || defaultBranch;
props.history.push(`/projects/${owner}/${projectsId}/tree/${branch.replaceAll("/","%2F")}`); let checkvalue = turnbar(branch);
props.history.push(`/projects/${owner}/${projectsId}/tree/${checkvalue}`);
}; };
// //
function returnUlr(url){ function returnUlr(url){
let enBranch = branchName && branchName.replaceAll("/","%2F"); let enBranch = turnbar(branchName);
props.history.push(`/projects/${owner}/${projectsId}/tree${enBranch?`/${enBranch}`:""}/${url}`); props.history.push(`/projects/${owner}/${projectsId}/tree${enBranch?`/${enBranch}`:""}/${url}`);
} }
// //
function goToSubRoot(path,type,filename){ function goToSubRoot(path,type,filename){
let enBranch = branchName || defaultBranch; let enBranch = branchName || defaultBranch;
let checkvalue = turnbar(enBranch);
setType(type); setType(type);
props.history.push(`/projects/${owner}/${projectsId}${`/tree/${enBranch.replaceAll("/","%2F")}`}${path?`/${path}`:""}`); props.history.push(`/projects/${owner}/${projectsId}${`/tree/${checkvalue}`}${path?`/${path}`:""}`);
} }
function onEdit(readOnly){ function onEdit(readOnly){
@ -211,7 +229,9 @@ function CoderDepot(props){
} }
function ChangeFile(path, readOnly){ function ChangeFile(path, readOnly){
// //
props.history.push(`/projects/${owner}/${projectsId}/tree/${branchName || defaultBranch}/${path}`); let enBranch = branchName || defaultBranch;
let checkvalue = turnbar(enBranch);
props.history.push(`/projects/${owner}/${projectsId}/tree/${checkvalue}/${path}`);
setType("file"); setType("file");
setEditReadme(true); setEditReadme(true);
}; };

View File

@ -6,6 +6,12 @@ import { getBranch } from '../GetData/getData';
import Nodata from '../Nodata'; import Nodata from '../Nodata';
import './list.css'; import './list.css';
function turnbar(str){
if(str && str.length>0 && str.indexOf("/")>-1){
return str.replaceAll('/','%2F');
}
return str;
}
export default ((props)=>{ export default ((props)=>{
const [ data , setData ] =useState(undefined); const [ data , setData ] =useState(undefined);
const [ isSpin , setIsSpin ] =useState(true); const [ isSpin , setIsSpin ] =useState(true);
@ -32,7 +38,7 @@ export default ((props)=>{
return( return(
<li key={key}> <li key={key}>
<div> <div>
<Link to={`/projects/${owner}/${projectsId}/tree/${item.name.replaceAll("/","%2F")}`} className="color-blue font-15" style={{"maxWidth":"100px"}}>{item.name}</Link> <Link to={`/projects/${owner}/${projectsId}/tree/${turnbar(item.name)}`} className="color-blue font-15" style={{"maxWidth":"100px"}}>{item.name}</Link>
<p className="f-wrap-alignCenter mt15"> <p className="f-wrap-alignCenter mt15">
<Link to={`/projects/${owner}/${projectsId}/commits/${truncateCommitId(`${item.last_commit.sha}`)}`} className="mr5 commitKey" style={{marginLeft:0}}>{item.last_commit && truncateCommitId(item.last_commit.sha)}</Link> <Link to={`/projects/${owner}/${projectsId}/commits/${truncateCommitId(`${item.last_commit.sha}`)}`} className="mr5 commitKey" style={{marginLeft:0}}>{item.last_commit && truncateCommitId(item.last_commit.sha)}</Link>
<span className="color-grey-3 hide-1 messages leftPoint">{item.last_commit && item.last_commit.message}</span> <span className="color-grey-3 hide-1 messages leftPoint">{item.last_commit && item.last_commit.message}</span>

View File

@ -5,6 +5,12 @@ import { AlignCenter } from '../Component/layout';
import { getImageUrl } from "educoder"; import { getImageUrl } from "educoder";
import "./merge.css"; import "./merge.css";
function turnbar(str){
if(str && str.length>0 && str.indexOf("/")>-1){
return str.replaceAll('/','%2F');
}
return str;
}
class MergeItem extends Component { class MergeItem extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -103,7 +109,7 @@ class MergeItem extends Component {
item.pull_request_head && item.pull_request_head &&
<Tag className="pr-branch-tag"> <Tag className="pr-branch-tag">
<Link <Link
to={`/projects/${item.is_original ? item.fork_project_user : owner}/${ item.is_original ? item.fork_project_identifier : projectsId }/tree/${item.pull_request_head.replaceAll("/","%2F")}`} to={`/projects/${item.is_original ? item.fork_project_user : owner}/${ item.is_original ? item.fork_project_identifier : projectsId }/tree/${turnbar(item.pull_request_head)}`}
className="maxW200px hide-1 ver-middle" className="maxW200px hide-1 ver-middle"
> >
{item.is_original {item.is_original
@ -127,7 +133,7 @@ class MergeItem extends Component {
item.pull_request_base && item.pull_request_base &&
<Tag className="pr-branch-tag"> <Tag className="pr-branch-tag">
<Link <Link
to={`/projects/${owner}/${projectsId}/tree/${item.pull_request_base.replaceAll("/","%2F")}`} to={`/projects/${owner}/${projectsId}/tree/${turnbar(item.pull_request_base)}`}
className="maxW200px hide-1 ver-middle" className="maxW200px hide-1 ver-middle"
> >
{/* {item.is_fork ? item.pull_request_base : `${item.author_name}:${item.pull_request_base}`} */} {/* {item.is_fork ? item.pull_request_base : `${item.author_name}:${item.pull_request_base}`} */}

View File

@ -24,6 +24,12 @@ import MergeFooter from "./merge_footer";
const Option = Select.Option; const Option = Select.Option;
const TextArea = Input.TextArea; const TextArea = Input.TextArea;
function turnbar(str){
if(str && str.length>0 && str.indexOf("/")>-1){
return str.replaceAll('/','%2F');
}
return str;
}
class MessageCount extends Component { class MessageCount extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -355,10 +361,10 @@ class MessageCount extends Component {
<div className="mt15"> <div className="mt15">
<Tag className="pr-branch-tag"> <Tag className="pr-branch-tag">
<Link <Link
to={`/projects/${data.pull_request.is_original ? data.pull_request.fork_project_user : data.issue.project_author_name}/${data.pull_request.is_original?data.project_identifier:projectsId}/tree/${data.pull_request.head && data.pull_request.head.replaceAll("/","%2F")}`} to={`/projects/${data.pull_request.is_original ? data.pull_request.fork_project_user : data.issue.project_author_name}/${data.pull_request.is_original?data.project_identifier:projectsId}/tree/${turnbar(data.pull_request && data.pull_request.head)}`}
className="ver-middle" className="ver-middle"
> >
{data.pull_request.is_original ? data.pull_request.fork_project_user : data.issue.project_author_name}:{data.pull_request.head && data.pull_request.head.replaceAll("/","%2F")} {data.pull_request.is_original ? data.pull_request.fork_project_user : data.issue.project_author_name}: {turnbar(data.pull_request && data.pull_request.head)}
</Link> </Link>
</Tag> </Tag>
<span className="mr8 ver-middle"> <span className="mr8 ver-middle">

View File

@ -6,6 +6,20 @@ import "./index.css";
import axios from "axios"; import axios from "axios";
const TextArea = Input.TextArea; const TextArea = Input.TextArea;
function turnbar(str){
if(str && str.length>0 && str.indexOf("/")>-1){
return str.replaceAll('/','%2F');
}
return str;
}
function returnbar(str){
if(str && str.length>0 && str.indexOf("%2F")>-1){
return str.replaceAll('%2F','/');
}
return str;
}
class UserSubmitComponent extends Component { class UserSubmitComponent extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -59,7 +73,7 @@ class UserSubmitComponent extends Component {
const url = `/${owner}/${projectsId}/create_file.json`; const url = `/${owner}/${projectsId}/create_file.json`;
axios.post(url, { axios.post(url, {
filepath: filename ? filename : path, filepath: filename ? filename : path,
branch: branch && branch.replaceAll("%2F","/"), branch: returnbar(branch),
new_branch: submitType === "1" ? values.branchname : undefined, new_branch: submitType === "1" ? values.branchname : undefined,
content, content,
message: values.desc, message: values.desc,
@ -72,7 +86,7 @@ class UserSubmitComponent extends Component {
const { getTopCount } = this.props; const { getTopCount } = this.props;
getTopCount && getTopCount(values.branchname); getTopCount && getTopCount(values.branchname);
} }
let url = `/projects/${owner}/${projectsId}${values.branchname ? `/tree/${values.branchname.replaceAll('/',"%2F")}`: (branch ? `/tree/${branch.replaceAll('/',"%2F")}` : "")}`; let url = `/projects/${owner}/${projectsId}${values.branchname ? `/tree/${turnbar(values.branchname)}`: (branch ? `/tree/${turnbar(branch)}` : "")}`;
this.props.history.push(url); this.props.history.push(url);
} }
}) })
@ -99,7 +113,7 @@ class UserSubmitComponent extends Component {
axios axios
.put(url, { .put(url, {
filepath: detail.path, filepath: detail.path,
branch: submitType === "1" ? undefined : b.replaceAll('%2F',"/"), branch: submitType === "1" ? undefined : returnbar(b),
new_branch: submitType === "1" ? values.branchname : undefined, new_branch: submitType === "1" ? values.branchname : undefined,
content: content, content: content,
sha: detail.sha, sha: detail.sha,
@ -109,7 +123,7 @@ class UserSubmitComponent extends Component {
this.setState({ isSpin: false }); this.setState({ isSpin: false });
if (result.data && result.data.status === 1) { if (result.data && result.data.status === 1) {
let b = currentBranch || branch; let b = currentBranch || branch;
let url = `/projects/${owner}/${projectsId}${(values.branchname ? `/tree/${values.branchname.replaceAll('/',"%2F")}` : (b ? `/tree/${b.replaceAll('/',"%2F")}`:""))}`; let url = `/projects/${owner}/${projectsId}${(values.branchname ? `/tree/${turnbar(values.branchname)}` : (b ? `/tree/${turnbar(b)}`:""))}`;
this.props.history.push(url); this.props.history.push(url);
this.props.showNotification("文件修改成功!"); this.props.showNotification("文件修改成功!");
} }
@ -191,7 +205,7 @@ class UserSubmitComponent extends Component {
> >
<Radio value="0" className="mb10"> <Radio value="0" className="mb10">
<i className="iconfont icon-banbenku font-16 mr5"></i> <i className="iconfont icon-banbenku font-16 mr5"></i>
直接提交至<span className="color-orange">{b.replaceAll('%2F',"/")}</span> 直接提交至<span className="color-orange">{returnbar(b)}</span>
</Radio> </Radio>
<Radio value="1"> <Radio value="1">
<Icon type="pull-request" className="mr5" /> <Icon type="pull-request" className="mr5" />