处理页面刷新之后创建合并请求报错问题

This commit is contained in:
谢思 2021-11-22 15:25:24 +08:00
parent eff12234fa
commit 4b1bccd1cd
3 changed files with 1041 additions and 1776 deletions

2773
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
"antd": "^3.26.15",
"array-flatten": "^2.1.2",
"autoprefixer": "7.1.6",
"axios": "^0.18.1",
"axios": "^0.24.0",
"babel-eslint": "7.2.3",
"babel-jest": "20.0.3",
"babel-loader": "7.1.2",
@ -24,11 +24,11 @@
"classnames": "^2.2.5",
"clipboard": "^2.0.8",
"code-prettify": "^0.1.0",
"codemirror": "^5.53.0",
"codemirror": "^5.64.0",
"connected-react-router": "4.4.1",
"cross-env": "^7.0.3",
"css-loader": "^3.5.2",
"dompurify": "^2.0.15",
"dompurify": "^2.3.3",
"dotenv": "4.0.0",
"dotenv-expand": "4.2.0",
"echarts": "^4.9.0",
@ -51,7 +51,7 @@
"js-base64": "^2.5.2",
"js2wordcloud": "^1.1.12",
"katex": "^0.11.1",
"lodash": "^4.17.15",
"lodash": "^4.17.21",
"loglevel": "^1.6.8",
"marked": "^1.0.0",
"material-ui": "^1.0.0-beta.40",

View File

@ -97,6 +97,11 @@ class CreateMerge extends Component {
// 再调用比较接口
const branchParams = getBranchParams(this.props.location.pathname);
this.getMergeInfo(branchParams);
//页面初始化时调用selectProjectName给is_original、fork_project_id、merge_user_login赋值
setTimeout(()=>{
const init = this.state.projects_names && this.state.projects_names.filter((item)=>item.project_user_login === branchParams.mergeOwner);
init && init[0] && this.selectProjectName(init[0].id,false);
},500)
};
componentDidUpdate = (preProps) => {
@ -175,8 +180,7 @@ class CreateMerge extends Component {
compareProject = (sameProject, branchParams) => {
// const { project } = this.props;
// const { owner, projectsId } = this.props.match.params;
const { pullOwner, pullBranch, mergeOwner, mergeBranch, projectId } =
branchParams;
const { pullOwner, pullBranch, mergeOwner, mergeBranch, projectId } = branchParams;
let url = `/${mergeOwner}/${projectId}/compare`;
if (sameProject) {
@ -262,7 +266,7 @@ class CreateMerge extends Component {
};
// 切换仓库响应事件,目前仅目标分支可切换仓库
selectProjectName = (value) => {
selectProjectName = (value, isChangeProject) => {
const { projects_names, id } = this.state;
const { pullOwner, pullBranch } = getBranchParams(
this.props.location.pathname
@ -274,7 +278,8 @@ class CreateMerge extends Component {
// 目标仓库与源仓库不是一个仓库
let is_fork = parseInt(value, 10) !== parseInt(id, 10);
this.setState({
isSpin: true,
// 切换目标仓库时url会发生变化即有spin效果
// isSpin: true,
// merge_head: is_fork,
data: {
is_original: is_fork,
@ -284,15 +289,18 @@ class CreateMerge extends Component {
: undefined,
},
});
if (login === pullOwner) {
// 如果切换后, 仓库与源仓库一致了
this.props.history.push(
`/${login}/${identifier}/compare/master...${pullBranch}`
);
} else {
this.props.history.push(
`/${login}/${identifier}/compare/master...${pullOwner}:${pullBranch}`
);
// 加上是否需要切换url判断
if(isChangeProject){
if (login === pullOwner) {
// 如果切换后, 仓库与源仓库一致了
this.props.history.push(
`/${login}/${identifier}/compare/master...${pullBranch}`
);
} else {
this.props.history.push(
`/${login}/${identifier}/compare/master...${pullOwner}:${pullBranch}`
);
}
}
// this.newMergelist(login, identifier);
};
@ -387,7 +395,7 @@ class CreateMerge extends Component {
<Select
value={project && project.id}
className="hide-1 task-hide flex1"
onSelect={(e) => this.selectProjectName(e)}
onSelect={(e) => this.selectProjectName(e, true)}
>
{this.renderProjectNames(mergeProjects)}
</Select>