Skip to content

Commit

Permalink
U 优化任务批量执行页面性能
Browse files Browse the repository at this point in the history
  • Loading branch information
vapao committed Jul 5, 2020
1 parent 00797fa commit 6f2c22a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
37 changes: 18 additions & 19 deletions spug_web/src/pages/exec/task/ExecConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React from 'react';
import { observer } from 'mobx-react';
import { Modal, Collapse, Icon } from 'antd';
import OutView from './OutView';
import styles from './index.module.css';
import store from './store';

Expand All @@ -27,7 +28,7 @@ class ExecConsole extends React.Component {
this.socket.onopen = () => {
this.socket.send('ok');
for (let item of Object.values(store.outputs)) {
item['system'] += '### Waiting for schedule\n'
item['system'].push('### Waiting for schedule\n')
}
};
this.socket.onmessage = e => {
Expand All @@ -38,11 +39,7 @@ class ExecConsole extends React.Component {
if (status !== undefined) {
store.outputs[key]['status'] = status
} else if (data) {
store.outputs[key][type] += data;
store.outputs[key]['latest'] = data;
if (this.elements[key]) {
this.elements[key].scrollIntoView({behavior: 'smooth'})
}
store.outputs[key][type].push(data);
}
}
}
Expand All @@ -52,15 +49,21 @@ class ExecConsole extends React.Component {
this.socket.close()
}

genExtra = (key) => {
const item = store.outputs[key];
genExtra = (outputs) => {
let latest, icon;
if (outputs['status'] === -2) {
return <Icon type="loading" style={{fontSize: 20, color: '#108ee9'}}/>
} else if (outputs['status'] === 0) {
latest = outputs['info'][outputs['info'].length - 1];
icon = <Icon type="check-circle" style={{fontSize: 20}} theme="twoTone" twoToneColor="#52c41a"/>
} else {
latest = outputs['error'][outputs['error'].length - 1]
icon = <Icon type="warning" style={{fontSize: 20}} theme="twoTone" twoToneColor="red"/>
}
return (
<div style={{display: 'flex', alignItems: 'center'}}>
<pre className={styles.header}>{item['latest']}</pre>
{item['status'] === -2 ? <Icon type="loading" style={{fontSize: 20, color: '#108ee9'}}/> :
item['status'] === 0 ?
<Icon type="check-circle" style={{fontSize: 20}} theme="twoTone" twoToneColor="#52c41a"/> :
<Icon type="warning" style={{fontSize: 20}} theme="twoTone" twoToneColor="red"/>}
<pre className={styles.header}>{latest}</pre>
{icon}
</div>
)
};
Expand All @@ -84,12 +87,8 @@ class ExecConsole extends React.Component {
<Collapse.Panel
key={index}
header={<b>{item['title']}</b>}
extra={this.genExtra(key)}>
<pre className={styles.console}>
<pre style={{color: '#91d5ff'}}>{item['system']}</pre>
{item['info']}
<pre ref={ref => this.elements[key] = ref} style={{color: '#ffa39e'}}>{item['error']}</pre>
</pre>
extra={this.genExtra(item)}>
<OutView outputs={item}/>
</Collapse.Panel>
))}
</Collapse>
Expand Down
34 changes: 34 additions & 0 deletions spug_web/src/pages/exec/task/OutView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) OpenSpug Organization. https://github.com/openspug/spug
* Copyright (c) <[email protected]>
* Released under the AGPL-3.0 License.
*/
import React from 'react';
import { toJS } from 'mobx';
import { observer } from 'mobx-react';
import styles from './index.module.css';

@observer
class OutView extends React.Component {
constructor(props) {
super(props);
this.el = null;
}

componentDidUpdate(prevProps, prevState, snapshot) {
setTimeout(() => this.el.scrollTop = this.el.scrollHeight, 100)
}

render() {
const outputs = toJS(this.props.outputs);
return (
<div ref={ref => this.el = ref} className={styles.console}>
<pre style={{color: '#91d5ff'}}>{outputs['system']}</pre>
<pre>{outputs['info']}</pre>
<pre style={{color: '#ffa39e'}}>{outputs['error']}</pre>
</div>
)
}
}

export default OutView
1 change: 1 addition & 0 deletions spug_web/src/pages/exec/task/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.console {
max-height: 300px;
padding: 10px 15px;
overflow: scroll;
}

.header {
Expand Down
7 changes: 3 additions & 4 deletions spug_web/src/pages/exec/task/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ class Store {
const key = `${item.hostname}:${item.port}`;
this.outputs[key] = {
title: `${item.name}(${key})`,
system: '### Establishing communication\n',
info: '',
error: '',
latest: '',
system: ['### Establishing communication\n'],
info: [],
error: [],
status: -2
}
}
Expand Down

0 comments on commit 6f2c22a

Please sign in to comment.