From a17c46ea6bd68a80a550073d758229aeaaf42209 Mon Sep 17 00:00:00 2001 From: vapao Date: Sat, 4 Jul 2020 01:49:22 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=9C=A8=E8=BE=93=E5=87=BA=E5=A4=A7=E9=87=8F?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=97=B6=E7=9A=84=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/deploy/views.py | 4 +-- spug_web/src/pages/deploy/do/Ext1Index.js | 17 ++++--------- spug_web/src/pages/deploy/do/Ext2Index.js | 17 ++++--------- spug_web/src/pages/deploy/do/OutView.js | 30 +++++++++++++++++++++++ 4 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 spug_web/src/pages/deploy/do/OutView.js diff --git a/spug_api/apps/deploy/views.py b/spug_api/apps/deploy/views.py index 3941942..61f2490 100644 --- a/spug_api/apps/deploy/views.py +++ b/spug_api/apps/deploy/views.py @@ -179,8 +179,8 @@ class RequestDetailView(View): return json_response(error='该申请单当前状态还不能执行发布') hosts = Host.objects.filter(id__in=json.loads(req.host_ids)) token = uuid.uuid4().hex - outputs = {str(x.id): {'data': ''} for x in hosts} - outputs.update(local={'data': f'{human_time()} 建立接连... '}) + outputs = {str(x.id): {'data': []} for x in hosts} + outputs.update(local={'data': [f'{human_time()} 建立接连... ']}) req.status = '2' if not req.version: req.version = f'{req.deploy_id}_{req.id}_{datetime.now().strftime("%Y%m%d%H%M%S")}' diff --git a/spug_web/src/pages/deploy/do/Ext1Index.js b/spug_web/src/pages/deploy/do/Ext1Index.js index 11bd303..11bf7a1 100644 --- a/spug_web/src/pages/deploy/do/Ext1Index.js +++ b/spug_web/src/pages/deploy/do/Ext1Index.js @@ -8,6 +8,7 @@ import { observer } from 'mobx-react'; import { Steps, Collapse, PageHeader, Spin, Tag, Button, Icon } from 'antd'; import http from 'libs/http'; import { AuthDiv } from 'components'; +import OutView from './OutView'; import history from 'libs/history'; import styles from './index.module.css'; import store from './store'; @@ -19,11 +20,9 @@ class Ext1Index extends React.Component { super(props); this.id = props.match.params.id; this.log = props.match.params.log; - this.elements = {}; this.state = { fetching: true, loading: false, - request: {}, } } @@ -46,7 +45,7 @@ class Ext1Index extends React.Component { while (res.outputs.length) { const msg = JSON.parse(res.outputs.pop()); if (!outputs.hasOwnProperty(msg.key)) { - const data = msg.key === 'local' ? '读取数据... ' : ''; + const data = msg.key === 'local' ? ['读取数据... '] : []; outputs[msg.key] = {data} } this._parse_message(msg, outputs) @@ -60,9 +59,7 @@ class Ext1Index extends React.Component { outputs = outputs || store.outputs; const {key, data, step, status} = message; if (data !== undefined) { - outputs[key]['data'] += data; - const el = this.elements[key]; - if (el) el.scrollTop = el.scrollHeight + outputs[key]['data'].push(data); } if (step !== undefined) outputs[key]['step'] = step; if (status !== undefined) outputs[key]['status'] = status; @@ -146,9 +143,7 @@ class Ext1Index extends React.Component { }> -
 this.elements['local'] = el} className={styles.ext1Console}>
-                {lds.get(store.outputs, 'local.data')}
-              
+ @@ -167,9 +162,7 @@ class Ext1Index extends React.Component { }> -
 this.elements[item.id] = el} className={styles.ext1Console}>
-                  {lds.get(store.outputs, `${item.id}.data`)}
-                
+ ))} diff --git a/spug_web/src/pages/deploy/do/Ext2Index.js b/spug_web/src/pages/deploy/do/Ext2Index.js index 9b4b278..e034c0a 100644 --- a/spug_web/src/pages/deploy/do/Ext2Index.js +++ b/spug_web/src/pages/deploy/do/Ext2Index.js @@ -8,6 +8,7 @@ import { observer } from 'mobx-react'; import { Steps, Collapse, PageHeader, Spin, Tag, Button, Icon } from 'antd'; import http from 'libs/http'; import { AuthDiv } from 'components'; +import OutView from './OutView'; import history from 'libs/history'; import styles from './index.module.css'; import store from './store'; @@ -19,11 +20,9 @@ class Ext1Index extends React.Component { super(props); this.id = props.match.params.id; this.log = props.match.params.log; - this.elements = {}; this.state = { fetching: true, loading: false, - request: {}, } } @@ -47,7 +46,7 @@ class Ext1Index extends React.Component { while (res.outputs.length) { const msg = JSON.parse(res.outputs.pop()); if (!outputs.hasOwnProperty(msg.key)) { - const data = msg.key === 'local' ? '读取数据... ' : ''; + const data = msg.key === 'local' ? ['读取数据... '] : []; outputs[msg.key] = {data} } this._parse_message(msg, outputs) @@ -61,9 +60,7 @@ class Ext1Index extends React.Component { outputs = outputs || store.outputs; const {key, data, step, status} = message; if (data !== undefined) { - outputs[key]['data'] += data; - const el = this.elements[key]; - if (el) el.scrollTop = el.scrollHeight + outputs[key]['data'].push(data); } if (step !== undefined) outputs[key]['step'] = step; if (status !== undefined) outputs[key]['status'] = status; @@ -147,9 +144,7 @@ class Ext1Index extends React.Component { ))} }> -
 this.elements['local'] = el} className={styles.ext1Console}>
-                {lds.get(store.outputs, 'local.data')}
-              
+ @@ -169,9 +164,7 @@ class Ext1Index extends React.Component { ))} }> -
 this.elements[item.id] = el} className={styles.ext1Console}>
-                    {lds.get(store.outputs, `${item.id}.data`)}
-                  
+ ))} diff --git a/spug_web/src/pages/deploy/do/OutView.js b/spug_web/src/pages/deploy/do/OutView.js new file mode 100644 index 0000000..ab2f0e5 --- /dev/null +++ b/spug_web/src/pages/deploy/do/OutView.js @@ -0,0 +1,30 @@ +/** + * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug + * Copyright (c) + * Released under the AGPL-3.0 License. + */ +import React from 'react'; +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() { + return ( +
 this.el = el} className={styles.ext1Console}>
+        {this.props.outputs}
+      
+ ) + } +} + +export default OutView \ No newline at end of file