mirror of
https://github.com/woodchen-ink/clash-and-dashboard.git
synced 2025-07-18 22:11:56 +08:00
feat(logs): update logs page
This commit is contained in:
parent
cc70575a86
commit
344005aa4e
@ -4,6 +4,8 @@ import { translate } from 'react-i18next'
|
|||||||
import { I18nProps } from '@models'
|
import { I18nProps } from '@models'
|
||||||
import { Card, Header } from '@components'
|
import { Card, Header } from '@components'
|
||||||
import './style.scss'
|
import './style.scss'
|
||||||
|
import { StreamReader } from '@lib/streamer'
|
||||||
|
import { getExternalControllerConfig, getConfig } from '@lib/request'
|
||||||
|
|
||||||
interface Log {
|
interface Log {
|
||||||
type: string
|
type: string
|
||||||
@ -22,13 +24,18 @@ class Logs extends React.Component<LogsProps, LogsState> {
|
|||||||
logs: []
|
logs: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private streamReader = null
|
||||||
private listRef = React.createRef<HTMLUListElement>()
|
private listRef = React.createRef<HTMLUListElement>()
|
||||||
componentDidMount () {
|
async componentDidMount () {
|
||||||
const logs: Log[] = Array.from(
|
const externalController = await getExternalControllerConfig()
|
||||||
{ length: 32 },
|
const { data: config } = await getConfig()
|
||||||
() => ({ type: 'info', payload: 'google.com match DomainSuffix using Proxy', time: new Date() })
|
const logUrl = `http://${externalController.hostname}:${externalController.port}/logs?level=${config['log-level']}`
|
||||||
)
|
this.streamReader = new StreamReader({ url: logUrl })
|
||||||
|
let logs = []
|
||||||
|
this.streamReader.subscribe('data', (data) => {
|
||||||
|
logs = [].concat(this.state.logs, data.map(d => ({ ...d, time: new Date() })))
|
||||||
this.setState({ logs }, () => this.scrollToBottom())
|
this.setState({ logs }, () => this.scrollToBottom())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToBottom = () => {
|
scrollToBottom = () => {
|
||||||
@ -45,9 +52,9 @@ class Logs extends React.Component<LogsProps, LogsState> {
|
|||||||
<ul className="logs-panel" ref={this.listRef}>
|
<ul className="logs-panel" ref={this.listRef}>
|
||||||
{
|
{
|
||||||
this.state.logs.map(
|
this.state.logs.map(
|
||||||
log => (
|
(log, index) => (
|
||||||
<li>
|
<li key={index}>
|
||||||
<span className="logs-panel-time">{ dayjs().format('YYYY-MM-DD HH:mm:ss') }</span>
|
<span className="logs-panel-time">{ dayjs(log.time).format('YYYY-MM-DD HH:mm:ss') }</span>
|
||||||
<span>[{ log.type }] { log.payload }</span>
|
<span>[{ log.type }] { log.payload }</span>
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
|
@ -1,8 +1,20 @@
|
|||||||
@import '~@styles/variables';
|
@import '~@styles/variables';
|
||||||
|
|
||||||
.rules-card {
|
.rules-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
margin-top: 25px;
|
margin-top: 25px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|
||||||
|
.rules {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex-grow: 1;
|
||||||
|
flex-basis: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.rule-item {
|
.rule-item {
|
||||||
|
@ -46,7 +46,6 @@ export class ConfigStore {
|
|||||||
payload: r[1],
|
payload: r[1],
|
||||||
proxy: r[2]
|
proxy: r[2]
|
||||||
}))
|
}))
|
||||||
console.log(rule)
|
|
||||||
this.config = {
|
this.config = {
|
||||||
general: {
|
general: {
|
||||||
port: config.port || 0,
|
port: config.port || 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user