From 6aaa67f2402e5c39c1e908c63e14d46b1b0e265f Mon Sep 17 00:00:00 2001 From: caishi <1149225589@qq.com> Date: Fri, 1 Sep 2023 15:01:19 +0800 Subject: [PATCH] =?UTF-8?q?merge=20=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/forge/Main/tree/Index.jsx | 312 +++++++++++++++++++++++++++++++-- src/forge/Main/tree/Index.scss | 104 ++++++++++- 2 files changed, 401 insertions(+), 15 deletions(-) diff --git a/src/forge/Main/tree/Index.jsx b/src/forge/Main/tree/Index.jsx index 2455a929f..b9897d4a4 100644 --- a/src/forge/Main/tree/Index.jsx +++ b/src/forge/Main/tree/Index.jsx @@ -3,23 +3,60 @@ import CopyTool from '../../Component/CopyTool'; import { truncateCommitId } from '../../common/util'; import { Link } from 'react-router-dom'; import { getImageUrl , turnbar } from 'educoder'; -import { Dropdown , Menu , Spin } from 'antd'; -import Nodata from '../../Nodata'; +import { Button, Dropdown , Input, Menu , message, Modal, Select, Spin, Table, Tooltip } from 'antd'; +import Modals from '../../Component/PublicModal/Index'; import './Index.scss'; import Tree from '../img/tree.png'; import Axios from 'axios'; function Index(props) { + const [ reload, setReload] = useState(undefined); const [ list , setList ] = useState([]); const [ isSpin , setIsSpin ] = useState(true); + // 删除分支 + const [visible, setVisible] = useState(false); + // 新建分支 + const [addBranch, setAddBranch] = useState(false); + const [newBranchName, setNewBranchName] = useState(undefined); + const [newFormBranchName, setNewFormBranchName] = useState(undefined); + const [newBranchError, setNewBranchError] = useState(undefined); + const [branchList, setBranchList] = useState([]);//所有分支 + // 通过分支名搜索分支 + const [name, setName] = useState(undefined); + // 分页 + const [current, setCurrent] = useState(1); + const [total, setTotal] = useState(0); + const [pageSize, setPageSize] = useState(10); const { projectsId , owner } = props.match.params; - const { isManager , isDeveloper , projectDetail , defaultBranch } = props; - + const { isManager , isDeveloper , projectDetail , defaultBranch, getDetail } = props; useEffect(()=>{ - getList(); - },[]) + // getList(); + const url = `/v1/${owner}/${projectsId}/branches.json`; + Axios.get(url,{ + params:{ + keyword: name, + page: current, + limit: pageSize + } + }).then(result=>{ + if(result){ + const {branches, total_count} = result.data; + setTotal(total_count) + setList(branches); + setNewFormBranchName(branches[0].name); + } + setIsSpin(false); + }).catch(error=>{setIsSpin(false);}) + },[name, reload, pageSize, current]) + + useEffect(()=>{ + if(projectDetail && document.title.indexOf('所有分支-') === -1){ + const { author, name} = projectDetail; + document.title = `所有分支-${author.name}/${name}`; + } + }, [projectDetail]) const menu =(zip_url,tar_url)=> ( @@ -29,6 +66,105 @@ function Index(props) { ) + const columns = [ + { + title: "分支名称", + dataIndex: "name", + key: 1, + ellipsis: true, + className: "branchNameColumn", + render: (txt, item) => { + return ( + {window.scrollTo(0,0)}} className="task-hide">{txt} + ) + } + }, + { + title: "更新信息", + dataIndex: "commit", + key: 3, + ellipsis: true, + width: "240px", + render: (txt, item) => { + return ( +
+ { + txt && txt.committer && txt.committer.id? + + + {txt && txt.committer && txt.committer.name} + + : + + + {txt && txt.committer && txt.committer.name} + + } + 更新于{txt && txt.time_ago} +
+ ) + } + }, + { + title: "commit信息", + dataIndex: "commit_id", + key: 4, + ellipsis: true, + width: "250px", + render: (txt, item) => { + return
+
+ + sha + {truncateCommitId(txt)} + + + +
+
+ } + }, + { + title: "分支类型", + dataIndex: "default_branch", + key: 5, + width: "150px", + render: (txt, item) => { + return isManager ? txt === item.name ? 默认分支 : : txt === item.name ? '默认分支' : '普通分支' + } + }, + { + title: "操作", + dataIndex: "name", + key: 6, + align: "center", + width: "320px", + className: "branchActionColumn", + render: (txt, item) => { + return ( +
+ { + (isManager || isDeveloper) && (projectDetail && projectDetail.type!==2) && + + 合并请求 + } + + 下载 + + {isManager && (txt === item.default_branch ? : )} +
+ ) + } + } + ]; + function getList() { const url = `/${owner}/${projectsId}/branches_slice.json`; Axios.get(url).then(result=>{ @@ -39,10 +175,121 @@ function Index(props) { }).catch(error=>{setIsSpin(false);}) } + // 删除分支确认函数 + function deleteLabel(){ + Axios.delete(`/v1/${owner}/${projectsId}/branches/${visible.name}.json`).then(res=>{ + if(res && res.data){ + if(current>1 && (list && list.length===1)){ + setCurrent(current-1); + }else{ + setReload(Math.random()); + } + setVisible(false); + !res.data.status && message.success('删除成功'); + } + }) + } + + // 新建分支确认函数 + function createBranch(){ + setNewBranchError(undefined); + if(!newBranchName){ + setNewBranchError("请输入新建分支名称"); + }else{ + Axios.post(`/v1/${owner}/${projectsId}/branches.json`, { + new_branch_name: newBranchName, + old_branch_name: newFormBranchName + }).then(res=>{ + if(res && res.data){ + // 重新请求仓库详情接口,更新分支总数信息 + getDetail(); + setReload(Math.random()); + setAddBranch(false); + message.success('新建分支成功'); + } + }) + } + } + + // 新建分支名检查格式 + function checkNewBranchName(e) { + setNewBranchError(undefined); + const value = e.target.value; + if (value) { + const str = '^*'; + let reg = /\\/g; + if(reg.test(value)){ + setNewBranchError('分支名不能包含下列任何字符:^ * \\ '); + }else{ + for(var i=0;i -1){ + setNewBranchError('分支名不能包含下列任何字符:^ * \\ '); + return; + }else{ + setNewBranchName(e.target.value); + } + } + } + } + } + + // 更新默认仓库分支 + function updateDefaultBranch(value, info){ + Axios.patch(`/v1/${owner}/${projectsId}/branches/update_default_branch.json`,{ + name: info.name + }).then(res=>{ + if(res && res.data){ + getDetail(); + setReload(Math.random()); + !res.data.status && message.success('操作成功'); + } + }) + } + + // 改变pagesize + function onShowSizeChange(current, pageSize){ + window.scrollTo(0, 0); + setCurrent(1); + setPageSize(pageSize); + } + + // 切换页数 + function changePage(page, pageSize){ + window.scrollTo(0, 0); + setCurrent(page); + } + + // 新建分支按钮点击函数 + function addBranchBtn(){ + setAddBranch(true); + const url = `/v1/${owner}/${projectsId}/branches/all.json`; + Axios.get(url).then(result=>{ + if(result){ + setBranchList(result.data); + } + }).catch(error=>{console.log('error', error);}) + } + return(
- { +
+ {setCurrent(1);setName(value)}} allowClear/> +
+ {isManager && 分支设置} + {(isManager || isDeveloper) && (projectDetail && projectDetail.type!==2) && } +
+
+ +
+ {/* { list && list.length>0 && list.map((item,key)=>{ return( @@ -86,7 +333,12 @@ function Index(props) {
{ (isManager || isDeveloper) && (projectDetail && projectDetail.type!==2) && - + 合并请求 + + 合并请求 } 下载 @@ -101,11 +353,47 @@ function Index(props) { ) }) - } - { - list && list.length === 0 && - } + } */}
+ {setVisible(false)}} + visible={Boolean(visible)} + width="456px" + btn={ +
+ + +
+ } + > +
+ +

确定删除{visible.name}分支?

+
+
+ {setAddBranch(false)}} + visible={addBranch} + width="388px" + footer={ + + } + className="createNewBranchModal" + > +
+
分支名称
+ +
{newBranchError}
+
分支起点
+ +
+
) } diff --git a/src/forge/Main/tree/Index.scss b/src/forge/Main/tree/Index.scss index f65a1c68f..1c31ea8f1 100644 --- a/src/forge/Main/tree/Index.scss +++ b/src/forge/Main/tree/Index.scss @@ -1,3 +1,98 @@ +.treeinfo{ + .branchLastUpdateUserImage{ + height: 20px; + width: 20px; + margin-right: 5px; + } +} +.f6_bor_but, .f6_bor_but:focus{ + color:#f60011; + background-color:rgba(196, 0, 14, 0.09); + border:1px solid #f60011; + border-radius:5px; + &:hover{ + color:#f60011; + background-color:rgba(196, 0, 14, 0.18); + border-color:#ff727c; + } + &:active{ + color:#f60011; + background-color:rgba(196, 0, 14, 0.22); + border-color:#f60011; + } +} +.branchListTable{ + .ant-table-thead > tr > th{ + border-top: 1px solid rgba(42, 97, 255, 0.23); + border-bottom: 1px solid rgba(42, 97, 255, 0.23) !important; + background-color:#fafcff; + } + .ant-table-column-title{ + color:#40424a; + } + .ant-table-thead > tr:first-child > th:last-child{ + border-right: 1px solid rgba(42, 97, 255, 0.23); + } + .ant-table-thead > tr:first-child > th:first-child{ + border-left: 1px solid rgba(42, 97, 255, 0.23); + } + .ant-table-tbody > tr > td{ + border-color: #eeeeee; + padding: 18.5px 16px; + } + .branchNameColumn{ + border-left: 1px solid #d0d0d0; + } + .branchActionColumn{ + border-right: 1px solid #d0d0d0; + } + .task-hide{ + color: $primary-color; + } + .ant-table-empty .ant-table-placeholder{ + border-left: 1px solid #d0d0d0; + border-right: 1px solid #d0d0d0; + } +} +.branchListActionBox{ + display: flex; + justify-content: space-between; + align-items: center; + margin: 20px 0 30px; +} +.createNewBranchModal{ + .ant-modal-title{ + text-align: left; + color:#333333; + font-size:17px; + font-weight: normal !important; + } + .ant-modal-header{ + border-bottom: none; + background-color:rgba(70, 106, 255, 0.05); + } + .ant-modal-close{right: 5px;} + .ant-modal-close-x{font-size: 26px;} + .ant-modal-footer{ + border-top: none; + text-align: center; + padding-bottom: 53px; + } + .ant-modal-content{ + background-image:linear-gradient(359.37deg,#ebf3ff 0%,#f8fbff 55.01%,#f1f5ff 100%); + } + .createBranchLabel{ + color:#27282d; + margin-bottom: 12px; + } + .createBranchInput, .createBranchInput .ant-select-selection{ + border-color:#9eaacb; + background-color: transparent !important; + } + .newBranchError{ + color:#df0002; + } +} .branchSort{ font-weight: 500; color: #333333; @@ -49,14 +144,16 @@ } .treecopy{ flex:1; - display: flex; - justify-content: center; + display: flex; + // justify-content: center; + &>div:not(.treeCopyBox){ + position: relative; + } &>div{ height: 32px; background: #FAFBFC; border-radius: 4px; border: 1px solid #D0D0D0; - position: relative; z-index: 1; display: flex; align-items: center; @@ -64,6 +161,7 @@ padding:0px 15px; border-right: 1px solid rgba(153, 153, 153, 0.4); height: 100%; + width: 140px; img{ margin-right: 4px; }