修改websocket问题

This commit is contained in:
何童崇 2021-08-25 11:34:46 +08:00
parent fb872f3a3d
commit 52e08e77e5
2 changed files with 407 additions and 353 deletions

View File

@ -233,6 +233,8 @@ class Detail extends Component {
secondSync: false secondSync: false
}) })
} }
} else if (result.data.mirror_status === 2) {
this.deleteProjectBack();
} else { } else {
this.getDetail(); this.getDetail();
this.setState({ this.setState({
@ -265,7 +267,11 @@ class Detail extends Component {
disconnected: () => { }, disconnected: () => { },
received: data => { received: data => {
console.log(`###### ---received data--- ######`); console.log(`###### ---received data--- ######`);
console.log(data);
if (data) { if (data) {
if ( data.project && data.project.mirror_status === 2) {
this.deleteProjectBack();
}
this.getDetail(); this.getDetail();
this.setState({ this.setState({
firstSync: false, firstSync: false,
@ -277,6 +283,23 @@ class Detail extends Component {
}) })
} }
deleteProjectBack = () => {
const { history } = this.props;
const { projectsId, owner } = this.props.match.params;
axios.delete(`/${owner}/${projectsId}.json`).then(res => {
let hash = '/projects/mirror/new';
if (res && res.data) {
history.push({
pathname: hash,
mirror_status: 2
});
}
else {
window.location.hash = hash;
}
});
}
getDetail = () => { getDetail = () => {
const { projectsId, owner } = this.props.match.params; const { projectsId, owner } = this.props.match.params;
this.getBanner(); this.getBanner();

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import { Input , Form , Select , Checkbox , Button , Spin , AutoComplete } from 'antd'; import { Input , Form , Select , Checkbox , Button , Spin , AutoComplete, Modal } from 'antd';
import { Base64 } from 'js-base64'; import { Base64 } from 'js-base64';
import '../css/index.scss'; import '../css/index.scss';
@ -58,6 +58,8 @@ class Index extends Component {
this.getGitignore(); this.getGitignore();
// 获取开源许可证 // 获取开源许可证
this.getLicenses(); this.getLicenses();
//判断是否为删除新建项目失败后返回,并执行对应逻辑
this.isDeleteProjectBack();
} }
componentDidUpdate=(prevPros)=>{ componentDidUpdate=(prevPros)=>{
if(prevPros && this.props && !this.props.checkIfLogin()){ if(prevPros && this.props && !this.props.checkIfLogin()){
@ -144,6 +146,31 @@ class Index extends Component {
}).catch((error) => { }) }).catch((error) => { })
} }
isDeleteProjectBack = () => {
let mirror_status = this.props.history.location.mirror_status;
if (mirror_status === 2 && sessionStorage.newProjectValue) {
Modal.warning({
title: '警告',
content: '镜像项目创建失败!请按操作规范重新创建项目!',
});
let newProjectValue = JSON.parse(sessionStorage.newProjectValue);
if (newProjectValue) {
this.setState({
project_language_id: newProjectValue.project_language_id,
project_category_id: newProjectValue.project_category_id,
license_id: newProjectValue.license_id,
ignore_id: newProjectValue.ignore_id
});
delete newProjectValue.project_language_id;
delete newProjectValue.project_category_id;
delete newProjectValue.license_id;
delete newProjectValue.ignore_id;
this.props.form.setFieldsValue(newProjectValue);
}
}
}
// 设置option // 设置option
setOptionsList = (data, _head, name) => { setOptionsList = (data, _head, name) => {
if (data && data.length > 0) { if (data && data.length > 0) {
@ -172,6 +199,8 @@ class Index extends Component {
const { project_language_id, project_category_id, license_id, ignore_id , owners_id , owners_name } = this.state; const { project_language_id, project_category_id, license_id, ignore_id , owners_id , owners_name } = this.state;
const decoderPass = Base64.encode(values.password); const decoderPass = Base64.encode(values.password);
const url = (projectsType && projectsType === "mirror") ? "/projects/migrate.json" : "/projects.json"; const url = (projectsType && projectsType === "mirror") ? "/projects/migrate.json" : "/projects.json";
// 新建项目的时候,暂存数据,如果失败,返回的时候可以重新赋值
sessionStorage.newProjectValue=JSON.stringify({...values,project_language_id,project_category_id,license_id,ignore_id});
axios.post(url, { axios.post(url, {
...values, ...values,
auth_password:decoderPass, auth_password:decoderPass,
@ -185,7 +214,7 @@ class Index extends Component {
this.setState({ this.setState({
isSpin: false isSpin: false
}) })
this.props.showNotification(`${projectsType && projectsType === "mirror" ? "镜像" : "托管"}项目创建成功!`); projectsType && projectsType !== "mirror" && this.props.showNotification(`托管项目创建成功!`);
this.props.history.push(`/projects/${result.data.login}/${result.data.identifier}`); this.props.history.push(`/projects/${result.data.login}/${result.data.identifier}`);
} }
}).catch((error) => { }).catch((error) => {
@ -337,7 +366,9 @@ class Index extends Component {
{ {
projectsType && projectsType === "mirror" && projectsType && projectsType === "mirror" &&
<React.Fragment> <React.Fragment>
<p className="mt10 mb10 color-grey-3 pointer" onClick={this.changeMirrorCheck}>需要授权验证<i className={mirrorCheck?"iconfont icon-xiajiantou font-13 ml10 color-grey-8":"iconfont icon-youjiantou font-13 ml10 color-grey-8"}></i></p> <p className="mt10 mb10 color-grey-3 pointer" onClick={this.changeMirrorCheck}>
需要授权验证<i className={mirrorCheck?"iconfont icon-xiajiantou font-13 ml10 color-grey-8":"iconfont icon-youjiantou font-13 ml10 color-grey-8"}></i>
<span className="ml20 font-12 color-red">如果源项目为公有仓库禁止填写用户名密码如果源项目为私有仓库则必须填写正确的用户名和密码!</span></p>
{ {
mirrorCheck && mirrorCheck &&
<div className="df mb20" style={{alignItems:'center'}}> <div className="df mb20" style={{alignItems:'center'}}>