mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
parent
ce323d0703
commit
6549eeaf10
|
@ -1,3 +1,4 @@
|
|||
@import '~@/styles/variable.less';
|
||||
body {
|
||||
height: 100%;
|
||||
overflow-y: hidden;
|
||||
|
@ -55,10 +56,13 @@ body {
|
|||
.ant-pro-grid-content.wide .ant-pro-page-container-children-content {
|
||||
height: calc(100vh - 184px);
|
||||
height: calc(100vh - var(--vh-offset, 0px) - 184px);
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
.CodeMirror {
|
||||
height: calc(100vh - 216px);
|
||||
height: calc(100vh - var(--vh-offset, 0px) - 216px);
|
||||
width: calc(100vw - 32px);
|
||||
}
|
||||
}
|
||||
.CodeMirror {
|
||||
|
|
38
src/pages/log/index.module.less
Normal file
38
src/pages/log/index.module.less
Normal file
|
@ -0,0 +1,38 @@
|
|||
@import '~@/styles/variable.less';
|
||||
|
||||
.left-tree {
|
||||
&-container {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
background-color: #fff;
|
||||
height: calc(100vh - 128px);
|
||||
height: calc(100vh - var(--vh-offset, 0px) - 128px);
|
||||
width: @tree-width;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
&-scroller {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
}
|
||||
&-search {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.log-container {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
:global {
|
||||
.log-wrapper {
|
||||
.ant-pro-grid-content.wide .ant-pro-page-container-children-content {
|
||||
padding: 0;
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.CodeMirror {
|
||||
width: calc(100% - 32px - @tree-width);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,40 @@
|
|||
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
|
||||
import { Button, message, Modal, TreeSelect } from 'antd';
|
||||
import { useState, useEffect, useCallback, Key } from 'react';
|
||||
import { TreeSelect, Tree, Input } from 'antd';
|
||||
import config from '@/utils/config';
|
||||
import { PageContainer } from '@ant-design/pro-layout';
|
||||
import { Controlled as CodeMirror } from 'react-codemirror2';
|
||||
import { request } from '@/utils/http';
|
||||
import styles from './index.module.less';
|
||||
|
||||
function getFilterData(keyword: string, data: any) {
|
||||
const expandedKeys: string[] = [];
|
||||
if (keyword) {
|
||||
const tree: any = [];
|
||||
data.forEach((item: any) => {
|
||||
if (item.title.includes(keyword)) {
|
||||
tree.push(item);
|
||||
expandedKeys.push(...item.children.map((x: any) => x.key));
|
||||
} else {
|
||||
const children: any[] = [];
|
||||
(item.children || []).forEach((subItem: any) => {
|
||||
if (subItem.title.includes(keyword)) {
|
||||
children.push(subItem);
|
||||
}
|
||||
});
|
||||
if (children.length > 0) {
|
||||
tree.push({
|
||||
...item,
|
||||
children,
|
||||
});
|
||||
expandedKeys.push(...children.map((x) => x.key));
|
||||
}
|
||||
}
|
||||
});
|
||||
return { tree, expandedKeys };
|
||||
}
|
||||
return { tree: data, expandedKeys };
|
||||
}
|
||||
|
||||
const Log = () => {
|
||||
const [width, setWdith] = useState('100%');
|
||||
const [marginLeft, setMarginLeft] = useState(0);
|
||||
|
@ -11,12 +42,16 @@ const Log = () => {
|
|||
const [title, setTitle] = useState('请选择日志文件');
|
||||
const [value, setValue] = useState('请选择日志文件');
|
||||
const [select, setSelect] = useState();
|
||||
const [data, setData] = useState();
|
||||
const [data, setData] = useState<any[]>([]);
|
||||
const [filterData, setFilterData] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isPhone, setIsPhone] = useState(false);
|
||||
|
||||
const getConfig = () => {
|
||||
request.get(`${config.apiPrefix}logs`).then((data) => {
|
||||
setData(formatData(data.dirs) as any);
|
||||
const result = formatData(data.dirs) as any;
|
||||
setData(result);
|
||||
setFilterData(result);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -25,10 +60,13 @@ const Log = () => {
|
|||
x.title = x.name;
|
||||
x.value = x.name;
|
||||
x.disabled = x.isDir;
|
||||
x.key = x.name;
|
||||
x.children = x.files.map((y: string) => ({
|
||||
title: y,
|
||||
value: `${x.name}/${y}`,
|
||||
key: `${x.name}/${y}`,
|
||||
parent: x.name,
|
||||
isLeaf: true,
|
||||
}));
|
||||
return x;
|
||||
});
|
||||
|
@ -50,15 +88,30 @@ const Log = () => {
|
|||
getLog(node);
|
||||
};
|
||||
|
||||
const onTreeSelect = useCallback((keys: Key[], e: any) => {
|
||||
onSelect(keys[0], e.node);
|
||||
}, []);
|
||||
|
||||
const onSearch = useCallback(
|
||||
(e) => {
|
||||
const keyword = e.target.value;
|
||||
const { tree } = getFilterData(keyword, data);
|
||||
setFilterData(tree);
|
||||
},
|
||||
[data, setFilterData],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (document.body.clientWidth < 768) {
|
||||
setWdith('auto');
|
||||
setMarginLeft(0);
|
||||
setMarginTop(0);
|
||||
setIsPhone(true);
|
||||
} else {
|
||||
setWdith('100%');
|
||||
setMarginLeft(0);
|
||||
setMarginTop(-72);
|
||||
setIsPhone(false);
|
||||
}
|
||||
getConfig();
|
||||
}, []);
|
||||
|
@ -67,18 +120,20 @@ const Log = () => {
|
|||
<PageContainer
|
||||
className="ql-container-wrapper log-wrapper"
|
||||
title={title}
|
||||
extra={[
|
||||
<TreeSelect
|
||||
className="log-select"
|
||||
value={select}
|
||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||
treeData={data}
|
||||
placeholder="请选择日志文件"
|
||||
showSearch
|
||||
key="value"
|
||||
onSelect={onSelect}
|
||||
/>,
|
||||
]}
|
||||
extra={
|
||||
isPhone && [
|
||||
<TreeSelect
|
||||
className="log-select"
|
||||
value={select}
|
||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||
treeData={data}
|
||||
placeholder="请选择日志文件"
|
||||
showSearch
|
||||
key="value"
|
||||
onSelect={onSelect}
|
||||
/>,
|
||||
]
|
||||
}
|
||||
header={{
|
||||
style: {
|
||||
padding: '4px 16px 4px 15px',
|
||||
|
@ -92,21 +147,38 @@ const Log = () => {
|
|||
},
|
||||
}}
|
||||
>
|
||||
<CodeMirror
|
||||
value={value}
|
||||
options={{
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
styleActiveLine: true,
|
||||
matchBrackets: true,
|
||||
mode: 'shell',
|
||||
readOnly: true,
|
||||
}}
|
||||
onBeforeChange={(editor, data, value) => {
|
||||
setValue(value);
|
||||
}}
|
||||
onChange={(editor, data, value) => {}}
|
||||
/>
|
||||
<div className={`${styles['log-container']}`}>
|
||||
{!isPhone && (
|
||||
<div className={styles['left-tree-container']}>
|
||||
<Input.Search
|
||||
className={styles['left-tree-search']}
|
||||
onChange={onSearch}
|
||||
></Input.Search>
|
||||
<div className={styles['left-tree-scroller']}>
|
||||
<Tree
|
||||
className={styles['left-tree']}
|
||||
treeData={filterData}
|
||||
onSelect={onTreeSelect}
|
||||
></Tree>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<CodeMirror
|
||||
value={value}
|
||||
options={{
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
styleActiveLine: true,
|
||||
matchBrackets: true,
|
||||
mode: 'shell',
|
||||
readOnly: true,
|
||||
}}
|
||||
onBeforeChange={(editor, data, value) => {
|
||||
setValue(value);
|
||||
}}
|
||||
onChange={(editor, data, value) => {}}
|
||||
/>
|
||||
</div>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
|
1
src/styles/variable.less
Normal file
1
src/styles/variable.less
Normal file
|
@ -0,0 +1 @@
|
|||
@tree-width: 300px;
|
Loading…
Reference in New Issue
Block a user