|
@@ -1,9 +1,11 @@
|
|
|
-import { Button, Card, Checkbox, message, Space, Table } from 'antd'
|
|
|
+import { Button, Card, Checkbox, Input, message, Space, Table } from 'antd'
|
|
|
import React, { useEffect, useState } from 'react'
|
|
|
import { useLocation, useNavigate } from 'react-router-dom'
|
|
|
import styled from 'styled-components'
|
|
|
import { getAllTask, getTaskLog } from '../services/index'
|
|
|
import moment from 'moment'
|
|
|
+import { UpOutlined, DownOutlined } from '@ant-design/icons'
|
|
|
+import Mark from 'mark.js'
|
|
|
|
|
|
const LogWrapper = styled.div`
|
|
|
padding: 20px;
|
|
@@ -19,7 +21,7 @@ const LogWrapper = styled.div`
|
|
|
.refresh {
|
|
|
height: 50px;
|
|
|
display: flex;
|
|
|
- justify-content: flex-end;
|
|
|
+ justify-content: space-between;
|
|
|
}
|
|
|
.log {
|
|
|
background-color: #012b36;
|
|
@@ -64,6 +66,12 @@ const TaskLogWatcher = () => {
|
|
|
|
|
|
const [autoRefresh, setAutoRefresh] = useState(false)
|
|
|
|
|
|
+ const [keyWord, setKeyWord] = useState(null)
|
|
|
+
|
|
|
+ const [keyWordList, setKeyWordList] = useState([])
|
|
|
+
|
|
|
+ const [keyWordIndex, setKeyWordIndex] = useState(0)
|
|
|
+
|
|
|
const columns = [
|
|
|
{
|
|
|
title: '序号',
|
|
@@ -215,6 +223,81 @@ const TaskLogWatcher = () => {
|
|
|
}}
|
|
|
/>
|
|
|
)
|
|
|
+ const findLast = () => {
|
|
|
+ if (keyWordList.length) {
|
|
|
+ const logWindow = document.getElementById('log')
|
|
|
+ keyWordList[keyWordIndex - 1].style.backgroundColor = '#fffd38'
|
|
|
+ if (keyWordIndex - 1 > 0) {
|
|
|
+ setKeyWordIndex(keyWordIndex - 1)
|
|
|
+ keyWordList[keyWordIndex - 2].style.backgroundColor = '#fd9640'
|
|
|
+ const targetbox =
|
|
|
+ document.getElementsByClassName('keyword_mark')[keyWordIndex - 2]
|
|
|
+ logWindow.scrollTop = targetbox.offsetTop - 150
|
|
|
+ logWindow.scrollLeft = targetbox.offsetLeft - logWindow.clientWidth
|
|
|
+ } else {
|
|
|
+ setKeyWordIndex(keyWordList.length)
|
|
|
+ keyWordList[keyWordList.length - 1].style.backgroundColor = '#fd9640'
|
|
|
+ const targetbox =
|
|
|
+ document.getElementsByClassName('keyword_mark')[
|
|
|
+ keyWordList.length - 1
|
|
|
+ ]
|
|
|
+ logWindow.scrollTop = targetbox.offsetTop - 150
|
|
|
+ logWindow.scrollLeft = targetbox.offsetLeft - logWindow.clientWidth
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const findNext = () => {
|
|
|
+ if (keyWordList.length) {
|
|
|
+ const logWindow = document.getElementById('log')
|
|
|
+ keyWordList[keyWordIndex - 1].style.backgroundColor = '#fffd38'
|
|
|
+ if (keyWordIndex + 1 <= keyWordList.length) {
|
|
|
+ setKeyWordIndex(keyWordIndex + 1)
|
|
|
+ keyWordList[keyWordIndex].style.backgroundColor = '#fd9640'
|
|
|
+ const targetbox =
|
|
|
+ document.getElementsByClassName('keyword_mark')[keyWordIndex]
|
|
|
+ logWindow.scrollTop = targetbox.offsetTop - 150
|
|
|
+ logWindow.scrollLeft = targetbox.offsetLeft - logWindow.clientWidth
|
|
|
+ } else {
|
|
|
+ setKeyWordIndex(1)
|
|
|
+ keyWordList[0].style.backgroundColor = '#fd9640'
|
|
|
+ const targetbox = document.getElementsByClassName('keyword_mark')[0]
|
|
|
+ logWindow.scrollTop = targetbox.offsetTop - 150
|
|
|
+ logWindow.scrollLeft = targetbox.offsetLeft - logWindow.clientWidth
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const changeKeyWord = e => {
|
|
|
+ setKeyWord(e.target.value)
|
|
|
+ setKeyWordIndex(0)
|
|
|
+ const markInstance = new Mark(document.querySelector('#log'))
|
|
|
+ markInstance.unmark({
|
|
|
+ done: () => {
|
|
|
+ const list = []
|
|
|
+ markInstance.mark(e.target.value, {
|
|
|
+ each: val => {
|
|
|
+ val.style.backgroundColor = '#fffd38'
|
|
|
+ val.style.padding = 0
|
|
|
+ val.className = 'keyword_mark'
|
|
|
+ list.push(val)
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if (list.length > 0) {
|
|
|
+ setKeyWordIndex(1)
|
|
|
+ list[0].style.backgroundColor = '#fd9640'
|
|
|
+ }
|
|
|
+ setKeyWordList(list)
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const searchTools = (
|
|
|
+ <Space>
|
|
|
+ <span>
|
|
|
+ {keyWordIndex}/{keyWordList.length}
|
|
|
+ </span>
|
|
|
+ <UpOutlined onClick={findLast} />
|
|
|
+ <DownOutlined onClick={findNext} />
|
|
|
+ </Space>
|
|
|
+ )
|
|
|
return (
|
|
|
<LogWrapper>
|
|
|
<div className="job-list">
|
|
@@ -237,6 +320,14 @@ const TaskLogWatcher = () => {
|
|
|
style={{ height: '100%', width: '100%' }}
|
|
|
bodyStyle={{ height: '100%', width: '100%' }}>
|
|
|
<div className="refresh">
|
|
|
+ <Space>
|
|
|
+ <Input
|
|
|
+ value={keyWord}
|
|
|
+ onChange={changeKeyWord}
|
|
|
+ addonAfter={searchTools}
|
|
|
+ placeholder="输入关键词"
|
|
|
+ />
|
|
|
+ </Space>
|
|
|
<Space>
|
|
|
<Checkbox onChange={changeRefresh} checked={autoRefresh}>
|
|
|
自动刷新
|
|
@@ -251,7 +342,9 @@ const TaskLogWatcher = () => {
|
|
|
</Button>
|
|
|
</Space>
|
|
|
</div>
|
|
|
- <pre className="log">{logData}</pre>
|
|
|
+ <pre className="log" id="log">
|
|
|
+ {logData}
|
|
|
+ </pre>
|
|
|
</Card>
|
|
|
</div>
|
|
|
</LogWrapper>
|