diff --git a/spug_web/src/pages/deploy/do/index.js b/spug_web/src/pages/deploy/do/index.js index e3b679a..129a5b0 100644 --- a/spug_web/src/pages/deploy/do/index.js +++ b/spug_web/src/pages/deploy/do/index.js @@ -1,15 +1,19 @@ import React from 'react'; +import { observer } from 'mobx-react'; import { Steps, Collapse, Icon } from 'antd'; import http from 'libs/http'; import styles from './index.module.css'; import store from './store'; +import lds from 'lodash'; - +@observer class Index extends React.Component { componentDidMount() { const {id} = this.props.match.params; http.post(`/api/deploy/request/${id}/`) - .then(token => { + .then(({token, outputs, targets}) => { + store.outputs = outputs; + store.targets = targets; this.socket = new WebSocket(`ws://localhost:8000/ws/exec/${token}/`); this.socket.onopen = () => { this.socket.send('ok'); @@ -18,17 +22,13 @@ class Index extends React.Component { if (e.data === 'pong') { this.socket.send('ping') } else { - console.log(JSON.parse(e.data)); - // const {key, data, type, status} = JSON.parse(e.data); - // 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'}) - // } - // } + const {key, data, step, status} = JSON.parse(e.data); + if (data !== undefined) store.outputs[key]['data'] += data; + if (step !== undefined) store.outputs[key]['step'] = step; + if (status !== undefined) store.outputs[key]['status'] = status; + // if (this.elements[key]) { + // this.elements[key].scrollIntoView({behavior: 'smooth'}) + // } } } }) @@ -38,32 +38,54 @@ class Index extends React.Component { if (this.socket) this.socket.close() } + getStatus = (key, n) => { + const step = lds.get(store.outputs, `${key}.step`, 0); + const isError = lds.get(store.outputs, `${key}.status`) === 'error'; + const icon = ; + if (n > step) { + return {key: n, status: 'wait'} + } else if (n === step) { + return isError ? {key: n, status: 'error'} : {key: n, status: 'process', icon} + } else { + return {key: n, status: 'finish'} + } + }; + render() { return (
服务端执行 :
- + - - - }/> - - }>web -01 + + + + + + + }> +
{lds.get(store.outputs, 'local.data')}
+
目标主机执行 :
- - -
web-01
- - - - }/> - -
- }>web -01 - web -02 + }> + {store.targets.map((item, index) => ( + + {item.title} + + + + + + + }> +
{lds.get(store.outputs, `${item.id}.data`)}
+
+ ))}
) diff --git a/spug_web/src/pages/deploy/do/index.module.css b/spug_web/src/pages/deploy/do/index.module.css index 87a3abd..8863064 100644 --- a/spug_web/src/pages/deploy/do/index.module.css +++ b/spug_web/src/pages/deploy/do/index.module.css @@ -1,3 +1,17 @@ .header { display: flex; +} + +.collapse :global(.ant-collapse-content-box) { + padding: 0; +} + +.console { + min-height: 40px; + max-height: 300px; + padding: 10px 15px; +} + +pre { + margin: 0; } \ No newline at end of file diff --git a/spug_web/src/pages/deploy/do/store.js b/spug_web/src/pages/deploy/do/store.js index a2df1e8..0edb6a0 100644 --- a/spug_web/src/pages/deploy/do/store.js +++ b/spug_web/src/pages/deploy/do/store.js @@ -1,7 +1,8 @@ import { observable } from "mobx"; class Store { - @observable outputs = []; + @observable outputs = {}; + @observable targets = []; } export default new Store() \ No newline at end of file