71 lines
2.3 KiB
JavaScript
71 lines
2.3 KiB
JavaScript
import React, { useEffect, useState } from "react";
|
|
import { Button, Select, message, Card } from "antd";
|
|
import axios from "axios";
|
|
function sitelist(props) {
|
|
const [page, setPage] = useState(undefined);
|
|
const [branch, setBranch] = useState("");
|
|
const [branchlist, setBranchlist] = useState(undefined);
|
|
const Url = window.location.href;
|
|
const params = Url.split('/');
|
|
const owner = params[3];
|
|
const repo = params[4];
|
|
const { current_user, resetUserInfo, projectDetail, showNotification } = props;
|
|
const { Option } = Select;
|
|
useEffect(() => {
|
|
axios.get(`/site_pages/x.json?owner=${owner}&repo=${repo}`).then((res) => {
|
|
if (res) {
|
|
setPage(res.data.data)
|
|
}
|
|
})
|
|
}, [])
|
|
useEffect(() => {
|
|
axios.get(`/v1/${owner}/${repo}/branches/all.json`).then((res) => {
|
|
if (res) {
|
|
setBranchlist(res.data);
|
|
}
|
|
})
|
|
}, [])
|
|
function handleClick() {
|
|
const params = { branch, owner, repo }
|
|
if (page) {
|
|
axios.post(`/site_pages/${page.id}/build.json`, params).then((res) => {
|
|
if (res && res.status === 200) {
|
|
message.success("部署成功");
|
|
} else {
|
|
message.error("部署失败");
|
|
}
|
|
})
|
|
}
|
|
}
|
|
function handlechange(value) {
|
|
let u = value;
|
|
setBranch(u);
|
|
}
|
|
return (
|
|
<div style={{width:"50%"}}>
|
|
<Card title={page ? page.site_name : ""}>
|
|
<p>建站工具 {page ? page.language_frame : ""}</p>
|
|
<p>绑定仓库 {page ? page.owner + "/" + page.repo : ""}</p>
|
|
<p style={{ display: "flex" }}>上次部署时间 {page ? page.last_build_at : ""}<p className="ml30">创建时间 {page ? page.created_at : ""}</p></p>
|
|
<div style={{display:"flex"}}>
|
|
<Select onChange={handlechange} style={{ width: "100px"}} >
|
|
{
|
|
branchlist && branchlist.length > 0 &&
|
|
branchlist.map((i, k) => {
|
|
return (
|
|
<Option value={i.name} className="task-hide" >{i.name}</Option>
|
|
)
|
|
})
|
|
}
|
|
</Select>
|
|
<p className="mt5 ml20">分支数:{projectDetail ? projectDetail.branches_count : ""}</p>
|
|
<Button onClick={handleClick} style={{right:"-320px"}} >部署</Button>
|
|
</div>
|
|
</Card>
|
|
</div>
|
|
)
|
|
}
|
|
export default sitelist
|
|
|
|
|