diff --git a/src/forge/Server/data.jsx b/src/forge/Server/data.jsx index 0974ddf6..5be21ece 100644 --- a/src/forge/Server/data.jsx +++ b/src/forge/Server/data.jsx @@ -2,22 +2,30 @@ import React, { useEffect, useState } from 'react'; import DataEmpty from './dataEmpty'; import AgreementModal from './agreementModal'; import DetectionModal from './detectionModal'; -import { Table } from 'antd'; +import { Table , Spin, message } from 'antd'; import axios from 'axios'; -const source=[ - {name:"maste2988989898984qwerrfccdr",status:"failure",time:"2022-05-11 17:21"}, - {name:"maste2988989898984qwerrfccdr",status:"success",time:"2022-05-11 17:21"}, - {name:"maste2988989898984qwerrfccdr",status:"50",time:"2022-05-11 17:21"}, - {name:"maste2988989898984qwerrfccdr",status:"80",time:"2022-05-11 17:21"} -] + function Data(props){ const [ visible , setVisible ] = useState(false); const [ detectionVisible , setDetectionVisible ] = useState(false); - const [ dataSource , setDataSource ] = useState(source); + const [ dataSource , setDataSource ] = useState(undefined); const [ page , setPage ] = useState(1); - const limit = 15; + const [ spining , setSpining ] = useState(true); + const [ has_trace_user , setHas_trace_user ] = useState(false); + const [ relayCount , setRelayCount ] = useState(5); + const [ repeatId , setRepeatId ] = useState(undefined); + const [ repeatBranch , setRepeatBranch ] = useState(undefined); + const { owner , projectsId } = props.match.params; + const { current_user } = props; + const limit = 15; + + useEffect(()=>{ + if(current_user){ + setHas_trace_user(has_trace_user); + } + },[current_user]) function onOk(){ setVisible(false); @@ -25,10 +33,13 @@ function Data(props){ } function onDetectionOk(){ + props.showNotification("扫描成功!"); setDetectionVisible(false); + setSpining(true); + Init(); } - useEffect(()=>{ + function Init(){ const url = `/traces/${owner}/${projectsId}/task_results.json`; axios.get(url,{ params:{ @@ -36,9 +47,17 @@ function Data(props){ } }).then(result=>{ if(result){ - + setDataSource(result.data.data); + let count = result.data.data && result.data.data.length; + setRelayCount(relayCount-count); + setSpining(false); } }).catch(error=>{}) + } + + useEffect(()=>{ + setSpining(true); + Init(); },[]) const columns=[ @@ -52,32 +71,35 @@ function Data(props){ }, { title:"分支名称", - dataIndex:"name", - key:"name", + dataIndex:"branch_tag", + key:"branch_tag", width:"30%", align:"left", ellipsis:true }, { title:"检测状态", - dataIndex:"status", - key:"status", + dataIndex:"detect_status", + key:"detect_status", align:"left", render: (k,e,e1) => { return ( - k === "failure" ? + k === "fail" ? 失败 - : k==="success" ? - 成功 + : k==="detecting" ? +
+ + {e.detect_process}% +
: -
{k}%
+ 成功 ) } }, { title:"检测时间", - dataIndex:"time", - key:"time", + dataIndex:"detect_startdate", + key:"detect_startdate", align:"left", }, { @@ -89,15 +111,60 @@ function Data(props){ render: (k,e,e1) => { return(
- 重新扫描 - 查看 - 下载报告 + repeatCheck(e.project_id,e.branch_tag)}>重新扫描 + { + (e.detect_status ==="fail" || e.detect_status ==="detecting") ? + 查看 + : + 查看 + } + { + (e.detect_status ==="fail" || e.detect_status ==="detecting") ? + 下载报告 + : + downloadFunc(e.task_id)}>下载报告 + }
) } } ] + // 下载报告 + function downloadFunc(task_id){ + setSpining(true); + const url = `/traces/${owner}/${projectsId}/task_pdf.json?task_id=${task_id}`; + axios.get(url).then(result=>{ + setSpining(false); + }).catch(error=>{}) + } + + // 重新扫描 + function repeatCheck(project_id,branch){ + if(relayCount <= 0){ + message.error("无可用检测次数"); + return; + } + setRepeatId(project_id); + setRepeatBranch(branch); + setDetectionVisible(true); + } + + // 新建分析:判断是否签订过协议,签订过就弹出检测弹框 + function createCheck(){ + if(relayCount <= 0){ + message.error("无可用检测次数"); + return; + } + setRepeatBranch(undefined); + setRepeatId(undefined); + if(has_trace_user){ + setVisible(true); + }else{ + setDetectionVisible(true); + } + } + return(
setVisible(false)} onOk={onOk}/> @@ -107,15 +174,28 @@ function Data(props){ onOk={onDetectionOk} owner={owner} projectsId={projectsId} + relayCount={relayCount} + repeatId={repeatId} + repeatBranch={repeatBranch} />
重晴鸟代码溯源系统 - setVisible(true)}>新建分析 + 新建分析
-
- - - + +
+ { + dataSource && dataSource.length >0 && +
+
+ + } + { + dataSource === null || (dataSource && dataSource.length === 0) && + + } + + ) } diff --git a/src/forge/Server/detectionModal.jsx b/src/forge/Server/detectionModal.jsx index 1935c26b..34440088 100644 --- a/src/forge/Server/detectionModal.jsx +++ b/src/forge/Server/detectionModal.jsx @@ -2,13 +2,12 @@ import React, { useState , forwardRef, useEffect } from 'react'; import { Modal , Form , Select } from 'antd'; import axios from 'axios'; -function DetectionModal({form , visible , onCancel , onOk , projectsId,owner }){ +function DetectionModal({form , visible , onCancel , onOk , projectsId, owner , relayCount , repeatId , repeatBranch }){ const { getFieldDecorator, validateFields , setFieldsValue } = form; const [ check , setCheck ] = useState(false); const [ branch , setBranch ] = useState(""); const [ branchList , setBranchList ] = useState([]); - const layout = { labelCol: { span: 5 }, wrapperCol: { span: 18 }, @@ -40,7 +39,32 @@ function DetectionModal({form , visible , onCancel , onOk , projectsId,owner }){ if(!error){ setCheck(true); setBranch(values.branch); - // onOk(); + if(repeatId){ + // 重新扫描 + const url = `/traces/${owner}/${projectsId}/reload_task.json`; + axios.get(url,{ + params:{ + project_id:repeatId, + branch_name:repeatBranch + } + }).then(result=>{ + if(result){ + onOk(); + } + setCheck(false); + }).catch(error=>{}) + }else{ + // 新建分析 + const url = `/traces/${owner}/${projectsId}/tasks.json`; + axios.post(url,{ + branch_name:values.branch + }).then(result=>{ + if(result){ + onOk(); + } + setCheck(false); + }).catch(error=>{}) + } } }) } @@ -54,7 +78,7 @@ function DetectionModal({form , visible , onCancel , onOk , projectsId,owner }){ footer={
取消 - { !check && 开始检测 } + { !check && relayCount !== 0 && 开始检测 }
} > @@ -73,18 +97,18 @@ function DetectionModal({form , visible , onCancel , onOk , projectsId,owner }){ check ?

正在开启检测,请等待...

: -

剩余扫描次数5

+

剩余扫描次数{relayCount}

}
{ - !check && + !check && !repeatBranch && {getFieldDecorator("branch",{ rules:[{required:true,message:"请选择要检测的分支"}] })( - { branchList && branchList.length >0 ? branchList.map((i,k)=>{ @@ -101,10 +125,10 @@ function DetectionModal({form , visible , onCancel , onOk , projectsId,owner }){ }
{ - check && branch && + (check && branch) || repeatBranch &&
检测分支 -

{branch}

+

{branch || repeatBranch}

}
diff --git a/src/forge/Server/index.scss b/src/forge/Server/index.scss index 08feef7b..b19ec7b0 100644 --- a/src/forge/Server/index.scss +++ b/src/forge/Server/index.scss @@ -229,7 +229,7 @@ height: 22px; background-color: rgba(75, 75, 75, 0.1); border-radius:26px; - span{ + span.percentline{ position: absolute; left: 0px; top:0px; @@ -241,32 +241,41 @@ color: rgba(51, 51, 51, 1); } } + .percentNum{ + position: absolute; + height: 24px; + line-height: 24px; + } .operationBtns{ display: flex; align-items: center; justify-content: center; - a{ + a,span{ margin:0px 14px; position: relative; color: rgba(70, 106, 255, 1); display: flex; align-items: center; height: 26px; - i{ - width: 13px; - } - &::before{ - position: absolute; - content: ""; - width: 1px; - height: 12px; - top:7px; - background-color: rgba(213, 213, 213, 1); - left: -14px; - } - &:first-child::before{ - display: none; - } + } + span{ + color: rgba(197, 204, 225, 1)!important; + cursor: default; + } + a > i,span>i{ + width: 13px; + } + a::before,span::before{ + position: absolute; + content: ""; + width: 1px; + height: 12px; + top:7px; + background-color: rgba(213, 213, 213, 1); + left: -14px; + } + a:first-child::before,span:first-child::before{ + display: none; } } }