This commit is contained in:
linlu 2022-07-14 11:13:09 +08:00
parent 940a1b33e6
commit 554ff5b175
2 changed files with 42 additions and 27 deletions

View File

@ -1,5 +1,5 @@
import React, { Component } from "react";
import {UnControlled as CodeMirror} from 'react-codemirror2';
import { UnControlled as CodeMirror } from 'react-codemirror2';
import 'codemirror/addon/selection/active-line.js';
import 'codemirror/mode/javascript/javascript.js';
import 'codemirror/mode/clike/clike';
@ -13,28 +13,32 @@ import "./editor.css";
class m_editor extends Component {
constructor(props) {
super(props);
this.editorDidMount = this.editorDidMount.bind(this)
this.state = {
editorValue: this.props.content,
changeValue:this.props.content,
prevHeight:0
changeValue: this.props.content,
prevHeight: 0
};
}
componentDidUpdate=(prevProps)=>{
if(prevProps && this.props && this.props.content !== prevProps.content){
componentDidUpdate = (prevProps) => {
if (prevProps && this.props && this.props.content !== prevProps.content) {
this.setState({
editorValue:this.props.content
editorValue: this.props.content
})
}
}
changeEditor = (editorValue,data) => {
changeEditor = (editorValue, data) => {
this.setState({
changeValue:editorValue.getValue(),
changeValue: editorValue.getValue(),
});
};
editorDidMount = (cm, data) => {
if (this.props.goLine)
cm.scrollIntoView({ line: this.props.goLine, char: 1 }, 200)
};
render() {
const { editorValue , changeValue } = this.state;
const { readOnly, editorType, currentBranch , descName , checkName } = this.props;
const { editorValue, changeValue } = this.state;
const { readOnly, editorType, currentBranch, descName, checkName } = this.props;
const editor_options = {
lineNumbers: "on",
lineWrapping: true, //强制换行
@ -42,7 +46,7 @@ class m_editor extends Component {
lineHeight: 24,
renderLineHighlight: "line",
revealHorizontalRightPadding: 5,
placeholder:"请输入内容",
placeholder: "请输入内容",
readOnly: readOnly,
cursorStyle: readOnly ? "underline-thin" : "line",
folding: true,
@ -50,7 +54,7 @@ class m_editor extends Component {
automaticLayout: true, // 自适应布局
overviewRulerBorder: false, // 不要滚动条的边框
scrollBeyondLastLine: false, // 取消代码后面一大段空白
styleActiveLine:true,//光标代码高亮
styleActiveLine: true,//光标代码高亮
minimap: {
// 不要小地图
enabled: false,
@ -64,10 +68,11 @@ class m_editor extends Component {
value={editorValue}
options={editor_options}
onChange={this.changeEditor}
onUpdate={this.editorDidMount}
/>
</div>
{!readOnly && (
<div className="editorBorderSubmitBox" style={{padding:"20px"}}>
<div className="editorBorderSubmitBox" style={{ padding: "20px" }}>
<UserSubmitComponent
{...this.props}
{...this.state}
@ -78,7 +83,7 @@ class m_editor extends Component {
descName={descName}
checkName={checkName}
></UserSubmitComponent>
</div>
</div>
)}
</React.Fragment>
);

View File

@ -17,7 +17,7 @@ function Quality(props){
const [statuts,setStatus] = useState(-1)
const [questionList,setQuestionList] = useState([]) //对应问题列表
const [isDetail,setDetail] = useState(false) //对应问题列表
const [codeDetailValue,setCodeDetailValue] = useState("") //对应问题列表
const [codeDetailValue,setCodeDetailValue] = useState({}) //对应问题列表
const [indexValue,setIndexValue] = useState(null)
const severityList = {
'BLOCKER': "致命缺陷",
@ -32,8 +32,12 @@ function Quality(props){
useEffect(()=>{
if(indexValue){
const domBox = document.getElementsByClassName('CodeMirror-code')[0].childNodes[indexValue]
domBox.style.cssText='border:1px solid red; padding: 5px;border-radius: 10px;color: black;background: lemonchiffon;'
// document.getElementById('htmlDOM').innerHTML
const domBox = document.getElementsByClassName('CodeMirror-code')[0].childNodes[indexValue.line - 1]
const divs = document.createElement("div");
divs.innerHTML = questionList[indexValue.index].message;
domBox.appendChild(divs)
divs.style.cssText='border:1px solid red; padding: 5px;border-radius: 10px;color: black;background: lemonchiffon;'
}
},[indexValue])
const getTask = () => {
@ -67,6 +71,7 @@ function Quality(props){
const getTaskDetail = (task_id) => {
axios.get(`/${owner}/${projectsId}/sonar_tasks/type_detail.json?task_id=${task_id}&type=ALL`)
.then(({data:{data,message,status}})=>{
document.body.scrollIntoView()
setStatus(0)
setQuestionList(data);
}).catch(function (error) {
@ -78,20 +83,24 @@ function Quality(props){
setStatus(2)
getTaskData()
}
const getCodeDetailData = (item) => {
const getCodeDetailData = (item,index) => {
axios.get(`/${owner}/${projectsId}/sonar_tasks/code_source.json?component=${item.component}&task_id=${sonarList.task_id}`)
.then(({data:{data,message,status}})=>{
data.splice(item.line,0,{code:document.getElementById('htmlDOM').innerHTML,line:item.line})
document.body.scrollIntoView()
// data.splice(item.line,0,{code:document.getElementById('htmlDOM').innerHTML,line:item.line})
const text = data.map(item => item.code).join("\n")
const dom = document.createElement("div");
dom.innerHTML = text;
setDetail(true)
setCodeDetailValue(dom.innerText)
setIndexValue(item.line?item.line:'')
setCodeDetailValue({content:dom.innerText,line:item.line + 5})
setIndexValue({
line:item.line,
index
})
})
}
const handleCodeDetail = (item) => {
getCodeDetailData(item)
const handleCodeDetail = (item,index) => {
getCodeDetailData(item,index)
}
const handleBack = () => {
setDetail(false)
@ -117,7 +126,7 @@ function Quality(props){
</div>
<div>
{questionList.map((item,index)=>{
return <div key={index} className='message-item' onClick={()=>handleCodeDetail(item)}>
return <div key={index} className='message-item' onClick={()=>handleCodeDetail(item,index)}>
{item.component}
<div className="message-item-content mb30 mt10" >
<img alt="" src={bugRed}/><span id="htmlDOM">{item.message}&nbsp;&nbsp;&nbsp;</span>
@ -129,10 +138,11 @@ function Quality(props){
</div>
</div>:
<div className="wrap-code">
<Button type="primary" onClick={handleBack} >返回</Button>
<Button type="primary" style={{marginBottom:20}} onClick={handleBack} >返回</Button>
<Meditor
content={codeDetailValue || "" }
content={codeDetailValue.content || "" }
readOnly={true}
goLine={codeDetailValue.line || ""}
editorType="update"
/>
</div>