This commit is contained in:
caishi 2020-08-28 11:58:32 +08:00
parent 3abbaa8899
commit cccdfeab32
3 changed files with 113 additions and 195 deletions

View File

@ -3,8 +3,9 @@ import activate from "../Images/activate.png";
import { Blueback } from "../Component/layout"; import { Blueback } from "../Component/layout";
import styled from "styled-components"; import styled from "styled-components";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { Form, Input, Modal, Button , Spin } from "antd"; import { Form, Input , Spin } from "antd";
import axios from "axios"; import axios from "axios";
import { ceil } from "lodash";
const P = styled.p` const P = styled.p`
{ {
@ -19,22 +20,20 @@ const P = styled.p`
`; `;
function About(props, ref) { function About(props, ref) {
const { form: { getFieldDecorator, validateFields , setFieldsValue } } = props; const { form: { getFieldDecorator, validateFields , setFieldsValue } } = props;
const [isSpining, setIsSpining] = useState(false); const [isSpining, setIsSpining] = useState(true);
//0: devops //0: devops
//1: //1:
//2: CI
//3: ci
const [step, setStep] = useState(undefined); const [step, setStep] = useState(undefined);
// step1
const [visible, setVisible] = useState(false);
// step1true // step1true
const [firstCompleted, setFirstCompleted] = useState(false); const [firstCompleted, setFirstCompleted] = useState(false);
const [ redirectUrl ,setRedirectUrl ] = useState(undefined); const [ redirectUrl ,setRedirectUrl ] = useState(undefined);
const [ cloudAccount , setCloudAccount ] = useState(undefined); const [ cloudAccount , setCloudAccount] = useState(undefined);
const owner = props.match.params.owner; const owner = props.match.params.owner;
const projectsId = props.match.params.projectsId; const projectsId = props.match.params.projectsId;
const AuthorLogin = props.author && props.author.login; const AuthorLogin = props.author && props.author.login;
const CurrentLogin = props.current_user && props.current_user.login; const CurrentLogin = props.current_user && props.current_user.login;
@ -49,21 +48,10 @@ function About(props, ref) {
url url
}).then(result=>{ }).then(result=>{
if(result && result.data ){ if(result && result.data ){
let s = result.data.step; setIsSpining(false);
setStep(s); setStep(result.data.step);
if(s >= 1){ setCloudAccount(result.data.cloud_account);
setFirstCompleted(true); setRedirectUrl(result.data.cloud_account &&result.data.cloud_account.authenticate_url);
if(s===1){
setVisible(true);
}
let cloud_account = result.data.cloud_account;
setCloudAccount(cloud_account);
setRedirectUrl(cloud_account.authenticate_url);
cloud_account && setFieldsValue({
...cloud_account,
ip_num:cloud_account.ip
});
}
} }
}).catch(error=>{ }).catch(error=>{
console.log(error); console.log(error);
@ -83,122 +71,54 @@ function About(props, ref) {
); );
// //
function goStep() { function goStep() {
if (!firstCompleted) { setIsSpining(true);
setIsSpining(true); props.showNotification("服务器连接绑定中,请耐心等候!");
props.showNotification("服务器连接绑定中,请耐心等候!"); validateFields((error, values) => {
validateFields((error, values) => { if (!error) {
if (!error) { const url = `/${owner}/${projectsId}/cloud_accounts.json`;
const url = `/${owner}/${projectsId}/cloud_accounts.json`; axios.post(url, {...values}).then((result) => {
axios.post(url, {...values}) setIsSpining(false);
.then((result) => { if (result && result.data.redirect_url) {
setIsSpining(false); setRedirectUrl(result.data.redirect_url);
if (result && result.data.redirect_url) { setStep(1);
setVisible(true); }
setFirstCompleted(true); })
setRedirectUrl(result.data.redirect_url); .catch((error) => {
} console.log(error);
}) });
.catch((error) => { }
console.log(error); });
setVisible(false);
});
}
});
} else {
setVisible(true);
}
}
//
function sure(){
setVisible(false);
minusPlus(1);
auth('put');
}
function minusPlus(num,flag){
let s = 0;
if(flag){
s=step-num;
}else{
s=step+num;
}
setStep(s);
} }
// //
function startActive(){ function startActive(){
validateFields((error, values) => { setIsSpining(true);
if(!error){ const url = `/${owner}/${projectsId}/cloud_accounts/${cloudAccount && cloudAccount.id}/activate.json`;
setIsSpining(true); axios.post(url).then(result=>{
const url = `/${owner}/${projectsId}/cloud_accounts/${cloudAccount && cloudAccount.id}/activate.json`; setIsSpining(false);
axios.post(url,{ if(result && result.data.status === 0){
...values props.history.push(`/projects/${owner}/${projectsId}/devops/dispose`);
}).then(result=>{ // open_devops
setIsSpining(false); let { changeOpenDevops } = props;
if(result && result.data.status === 0){ changeOpenDevops && changeOpenDevops(true);
props.history.push(`/projects/${owner}/${projectsId}/devops/dispose`);
// open_devops
let { changeOpenDevops } = props;
changeOpenDevops && changeOpenDevops(true);
}else{
props.showNotification('激活失败,请稍后再试!');
}
}).catch(error=>{
console.log(error);
})
} }
}).catch(error=>{
console.log(error);
setIsSpining(false);
}) })
} }
//
function complete(){
props.history.push(`/projects/${owner}/${projectsId}/devops/dispose`);
}
return ( return (
<Spin spinning={isSpining}> <Spin spinning={isSpining}>
<div className="activatePanel"> <div className="activatePanel">
<Modal
title="提示"
visible={visible}
closable={true}
onCancel={() => setVisible(false)}
footer={
<React.Fragment>
<Button onClick={() => setVisible(false)}>取消</Button>
<Button
onClick={sure}
type={"primary"}
className="ml20"
>
确定
</Button>
</React.Fragment>
}
>
<div style={{ display: "flex", justifyContent: "center" }}>
<p style={{ maxWidth: "260px" }}>
初始化配置已完成请前往:
<br />
<a
target="_blank"
href={redirectUrl}
className="color-blue"
>
{redirectUrl}
</a>
<br />
进入认证
</p>
</div>
</Modal>
<img src={activate} alt="" width="250px" /> <img src={activate} alt="" width="250px" />
<P>定义DevOps工作流帮助您检测bug发布代码</P> <P>定义DevOps工作流帮助您检测bug发布代码</P>
<Link to={""} style={{ color: "#5091FF", marginBottom: "20px" }}> <a href={"https://www.trustie.net/forums/82/memos/3080"} target="_blank" style={{ color: "#5091FF", marginBottom: "20px" }}>
了解什么是DevOps 了解什么是DevOps
</Link> </a>
{ {
AuthorLogin === CurrentLogin ? AuthorLogin === CurrentLogin ?
<React.Fragment> <React.Fragment>
{ step <= 1 ? { step === 0 ?
<React.Fragment> <React.Fragment>
<Form> <Form>
<p className="mb20" style={{width:"370px"}}>请仔细核对您的服务器信息一旦确认提交将无法修改</p> <p className="mb20" style={{width:"370px"}}>请仔细核对您的服务器信息一旦确认提交将无法修改</p>
@ -232,32 +152,15 @@ function About(props, ref) {
<Blueback onClick={goStep}>下一步</Blueback> <Blueback onClick={goStep}>下一步</Blueback>
</React.Fragment> </React.Fragment>
:""} :""}
{step >= 2 &&( {step === 1 &&(
<div> <div style={{textAlign:'center'}}>
<Form> <p style={{ maxWidth: "300px",textAlign:"left",color:"#999" }}>初始化配置已完成请前往:<br/><a target="_blank" href={redirectUrl} className="color-blue">{redirectUrl}</a> 进入认证</p>
<p className="mb20" style={{width:"370px"}}>认证成功后请前往<a target="_blank" href={cloudAccount && cloudAccount.get_drone_token_url} className="color-blue">{cloudAccount && cloudAccount.get_drone_token_url}</a>获取token值并将获取的token值填入输入框</p> <Blueback onClick={startActive} className="mt20">开始激活</Blueback>
{helper(
"token值",
"drone_token",
[{ required: true, message: "请输入token值" }],
<Input placeholder="请输入token值" size="large" />,
true
)}
<div style={{ display: "flex", justifyContent: "center" }}>
{
step === 2?
<Blueback onClick={startActive} className="ml20">开始激活</Blueback>
:
<Blueback onClick={complete}>完成</Blueback>
}
</div>
</Form>
</div> </div>
)} )}
</React.Fragment> </React.Fragment>
:"" :""
} }
</div> </div>
</Spin> </Spin>
); );

View File

@ -1,88 +1,105 @@
import React, {useState,useEffect} from "react"; import React, { useState, useEffect } from "react";
import { Spin } from 'antd'; import { Spin } from "antd";
import { FlexAJ, AlignCenter } from "../Component/layout"; import { FlexAJ, AlignCenter } from "../Component/layout";
import axios from 'axios'; import axios from "axios";
export default (({ data , stepN , stageN , projectId , owner , opsId , rightSpin }) => { export default ({
const [ coders , setCoders ] = useState(undefined); data,
const [ empty , setEmpty ] = useState(false); stepN,
const [ spining , setSpining ] = useState(true); stageN,
const [ stage , setStage]= useState(undefined); projectId,
const [ step , setStep]= useState(undefined); owner,
useEffect(()=>{ opsId,
rightSpin,
}) => {
const [coders, setCoders] = useState(undefined);
const [empty, setEmpty] = useState(false);
const [spining, setSpining] = useState(true);
const [stage, setStage] = useState(undefined);
const [step, setStep] = useState(undefined);
useEffect(() => {
setSpining(rightSpin); setSpining(rightSpin);
},[rightSpin]) }, [rightSpin]);
useEffect(()=>{ useEffect(() => {
if(data){ if (data) {
let stages = data.stages; let stages = data.stages;
if(stages && stages.length>0){ if (stages && stages.length > 0) {
let pre = stageN ? stages.filter(item=>item.number===stageN)[0] : stages[0]; let pre = stageN
? stages.filter((item) => item.number === stageN)[0]
: stages[0];
setStage(pre); setStage(pre);
let p = pre && pre.steps; let p = pre && pre.steps;
let sub = stepN ? p && p.length > 0 && p.filter(item=>item.id===stepN)[0] : p[0]; let sub = stepN
? p && p.length > 0 && p.filter((item) => item.id === stepN)[0]
: p[0];
setStep(sub); setStep(sub);
if(sub){ if (sub) {
getStep(pre.number,sub.number); getStep(pre.number, sub.number);
} }
}else{ } else {
setSpining(false); setSpining(false);
} }
} }
},[data,stageN,stepN]) }, [data, stageN, stepN]);
function getStep(stageN,stepN){ function getStep(stageN, stepN) {
if(stageN && stepN){ if (stageN && stepN) {
const url = `/${owner}/${projectId}/builds/${opsId}/logs/${stageN}/${stepN}.json`; const url = `/${owner}/${projectId}/builds/${opsId}/logs/${stageN}/${stepN}.json`;
axios.get(url).then(result=>{ axios
if(result){ .get(url)
setCoders(result.data); .then((result) => {
setSpining(false); if (result) {
}else{ setCoders(result.data);
setEmpty(true); setSpining(false);
} } else {
}).catch(error=>{ setEmpty(true);
console.log(error); }
}) })
.catch((error) => {
console.log(error);
});
} }
} }
return ( return (
<Spin spinning={spining}> <Spin spinning={spining}>
<div className="rightMainContent"> <div className="rightMainContent">
{ {data && data.status !== "error" ? (
data && data.status !== "error" ?
<div> <div>
<FlexAJ className="items"> <FlexAJ className="items">
<span>{step && step.name}</span> <span>{step && step.name}</span>
<AlignCenter> <AlignCenter>
{ step && step.duration_time} {step && step.duration_time}
<i className="iconfont icon-sanjiaoxing-down"></i> <i className="iconfont icon-sanjiaoxing-down"></i>
</AlignCenter> </AlignCenter>
</FlexAJ> </FlexAJ>
<div> <div>
{ {coders && coders.length > 0 ? (
coders && coders.length>0 ? coders.map((item,key)=>{ coders.map((item, key) => {
return( return (
<div className="opsDetailOut"> <div className="opsDetailOut">
<span>{key+1}</span> <span>{key + 1}</span>
<p>{item.out}</p> <p>{item.out}</p>
</div> </div>
) );
}): })
empty ? ) : empty ? (
<div className="opsDetailOut"> <div className="opsDetailOut">
<span>1</span> <span>1</span>
<p>{stage && stage.name} {step && step.name}: Skipped</p> <p>
{stage && stage.name} {step && step.name}: Skipped
</p>
</div> </div>
:"" ) : (
} ""
)}
</div> </div>
</div> </div>
: ) : (
<div style={{color:"red"}}>error:{ data && data.error }</div> <div style={{ color: "red" }}>error:{data && data.error}</div>
} )}
</div> </div>
</Spin> </Spin>
); );
}); };

View File

@ -51,9 +51,7 @@ class Index extends Component {
<div className="grid-item"> <div className="grid-item">
<div className="setInputAddon"> <div className="setInputAddon">
<Input <Input
addonBefore={`/${ addonBefore={`/${ projectDetail && projectDetail.identifier }${urlroot}/`}
projectDetail && projectDetail.identifier
}${urlroot}/`}
value={filename} value={filename}
onChange={this.changeFileName} onChange={this.changeFileName}
placeholder="命名文件..." placeholder="命名文件..."