mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 20:06:08 +08:00
parent
ce323d0703
commit
6549eeaf10
|
@ -1,3 +1,4 @@
|
||||||
|
@import '~@/styles/variable.less';
|
||||||
body {
|
body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
|
@ -55,10 +56,13 @@ body {
|
||||||
.ant-pro-grid-content.wide .ant-pro-page-container-children-content {
|
.ant-pro-grid-content.wide .ant-pro-page-container-children-content {
|
||||||
height: calc(100vh - 184px);
|
height: calc(100vh - 184px);
|
||||||
height: calc(100vh - var(--vh-offset, 0px) - 184px);
|
height: calc(100vh - var(--vh-offset, 0px) - 184px);
|
||||||
|
margin-left: 0;
|
||||||
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
.CodeMirror {
|
.CodeMirror {
|
||||||
height: calc(100vh - 216px);
|
height: calc(100vh - 216px);
|
||||||
height: calc(100vh - var(--vh-offset, 0px) - 216px);
|
height: calc(100vh - var(--vh-offset, 0px) - 216px);
|
||||||
|
width: calc(100vw - 32px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.CodeMirror {
|
.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 { useState, useEffect, useCallback, Key } from 'react';
|
||||||
import { Button, message, Modal, TreeSelect } from 'antd';
|
import { TreeSelect, Tree, Input } from 'antd';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import { Controlled as CodeMirror } from 'react-codemirror2';
|
import { Controlled as CodeMirror } from 'react-codemirror2';
|
||||||
import { request } from '@/utils/http';
|
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 Log = () => {
|
||||||
const [width, setWdith] = useState('100%');
|
const [width, setWdith] = useState('100%');
|
||||||
const [marginLeft, setMarginLeft] = useState(0);
|
const [marginLeft, setMarginLeft] = useState(0);
|
||||||
|
@ -11,12 +42,16 @@ const Log = () => {
|
||||||
const [title, setTitle] = useState('请选择日志文件');
|
const [title, setTitle] = useState('请选择日志文件');
|
||||||
const [value, setValue] = useState('请选择日志文件');
|
const [value, setValue] = useState('请选择日志文件');
|
||||||
const [select, setSelect] = 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 [loading, setLoading] = useState(false);
|
||||||
|
const [isPhone, setIsPhone] = useState(false);
|
||||||
|
|
||||||
const getConfig = () => {
|
const getConfig = () => {
|
||||||
request.get(`${config.apiPrefix}logs`).then((data) => {
|
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.title = x.name;
|
||||||
x.value = x.name;
|
x.value = x.name;
|
||||||
x.disabled = x.isDir;
|
x.disabled = x.isDir;
|
||||||
|
x.key = x.name;
|
||||||
x.children = x.files.map((y: string) => ({
|
x.children = x.files.map((y: string) => ({
|
||||||
title: y,
|
title: y,
|
||||||
value: `${x.name}/${y}`,
|
value: `${x.name}/${y}`,
|
||||||
|
key: `${x.name}/${y}`,
|
||||||
parent: x.name,
|
parent: x.name,
|
||||||
|
isLeaf: true,
|
||||||
}));
|
}));
|
||||||
return x;
|
return x;
|
||||||
});
|
});
|
||||||
|
@ -50,15 +88,30 @@ const Log = () => {
|
||||||
getLog(node);
|
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(() => {
|
useEffect(() => {
|
||||||
if (document.body.clientWidth < 768) {
|
if (document.body.clientWidth < 768) {
|
||||||
setWdith('auto');
|
setWdith('auto');
|
||||||
setMarginLeft(0);
|
setMarginLeft(0);
|
||||||
setMarginTop(0);
|
setMarginTop(0);
|
||||||
|
setIsPhone(true);
|
||||||
} else {
|
} else {
|
||||||
setWdith('100%');
|
setWdith('100%');
|
||||||
setMarginLeft(0);
|
setMarginLeft(0);
|
||||||
setMarginTop(-72);
|
setMarginTop(-72);
|
||||||
|
setIsPhone(false);
|
||||||
}
|
}
|
||||||
getConfig();
|
getConfig();
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -67,18 +120,20 @@ const Log = () => {
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper log-wrapper"
|
className="ql-container-wrapper log-wrapper"
|
||||||
title={title}
|
title={title}
|
||||||
extra={[
|
extra={
|
||||||
<TreeSelect
|
isPhone && [
|
||||||
className="log-select"
|
<TreeSelect
|
||||||
value={select}
|
className="log-select"
|
||||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
value={select}
|
||||||
treeData={data}
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||||
placeholder="请选择日志文件"
|
treeData={data}
|
||||||
showSearch
|
placeholder="请选择日志文件"
|
||||||
key="value"
|
showSearch
|
||||||
onSelect={onSelect}
|
key="value"
|
||||||
/>,
|
onSelect={onSelect}
|
||||||
]}
|
/>,
|
||||||
|
]
|
||||||
|
}
|
||||||
header={{
|
header={{
|
||||||
style: {
|
style: {
|
||||||
padding: '4px 16px 4px 15px',
|
padding: '4px 16px 4px 15px',
|
||||||
|
@ -92,21 +147,38 @@ const Log = () => {
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CodeMirror
|
<div className={`${styles['log-container']}`}>
|
||||||
value={value}
|
{!isPhone && (
|
||||||
options={{
|
<div className={styles['left-tree-container']}>
|
||||||
lineNumbers: true,
|
<Input.Search
|
||||||
lineWrapping: true,
|
className={styles['left-tree-search']}
|
||||||
styleActiveLine: true,
|
onChange={onSearch}
|
||||||
matchBrackets: true,
|
></Input.Search>
|
||||||
mode: 'shell',
|
<div className={styles['left-tree-scroller']}>
|
||||||
readOnly: true,
|
<Tree
|
||||||
}}
|
className={styles['left-tree']}
|
||||||
onBeforeChange={(editor, data, value) => {
|
treeData={filterData}
|
||||||
setValue(value);
|
onSelect={onTreeSelect}
|
||||||
}}
|
></Tree>
|
||||||
onChange={(editor, data, value) => {}}
|
</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>
|
</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