From 1bb7b99db23354f34f3092f2d61dfd252c2cd5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Sat, 21 Dec 2019 12:37:49 +0800 Subject: [PATCH] A web update --- spug_web/src/pages/deploy/do/index.js | 74 +++++++++++++++---- spug_web/src/pages/deploy/do/index.module.css | 4 + spug_web/src/pages/deploy/do/store.js | 1 + 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/spug_web/src/pages/deploy/do/index.js b/spug_web/src/pages/deploy/do/index.js index 129a5b0..49cc89b 100644 --- a/spug_web/src/pages/deploy/do/index.js +++ b/spug_web/src/pages/deploy/do/index.js @@ -1,17 +1,42 @@ import React from 'react'; import { observer } from 'mobx-react'; -import { Steps, Collapse, Icon } from 'antd'; +import { Steps, Collapse, PageHeader, Spin, Tag, Button, Icon } from 'antd'; import http from 'libs/http'; +import history from 'libs/history'; import styles from './index.module.css'; import store from './store'; import lds from 'lodash'; @observer class Index extends React.Component { + constructor(props) { + super(props); + this.state = { + fetching: true, + loading: false, + request: {}, + } + } + componentDidMount() { - const {id} = this.props.match.params; - http.post(`/api/deploy/request/${id}/`) + this.id = this.props.match.params.id; + http.get(`/api/deploy/request/${this.id}/`) + .then(res => store.request = res) + .finally(() => this.setState({fetching: false})) + } + + componentWillUnmount() { + if (this.socket) this.socket.close(); + store.request = {}; + store.outputs = {}; + store.targets = [] + } + + handleDeploy = () => { + this.setState({loading: true}); + http.post(`/api/deploy/request/${this.id}/`) .then(({token, outputs, targets}) => { + store.request.status = '3'; store.outputs = outputs; store.targets = targets; this.socket = new WebSocket(`ws://localhost:8000/ws/exec/${token}/`); @@ -26,20 +51,14 @@ class Index extends React.Component { 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'}) - // } } } }) - } - - componentWillUnmount() { - if (this.socket) this.socket.close() - } + .finally(() => this.setState({loading: false})) + }; getStatus = (key, n) => { - const step = lds.get(store.outputs, `${key}.step`, 0); + const step = lds.get(store.outputs, `${key}.step`, -1); const isError = lds.get(store.outputs, `${key}.status`) === 'error'; const icon = ; if (n > step) { @@ -51,10 +70,33 @@ class Index extends React.Component { } }; + getStatusAlias = () => { + if (store.targets.length !== 0) { + for (let item of store.targets) { + if (lds.get(store.outputs, `${item.id}.status`) === 'error') { + return 发布异常 + } else if (lds.get(store.outputs, `${item.id}.step`, -1) < 5) { + return 发布中 + } + } + return 发布成功 + } else { + return {store.request['status_alias'] || '...'} + } + }; + render() { + const {app_name, env_name, status} = store.request; return ( -
-
服务端执行 :
+ + 发布} + onBack={() => history.goBack()}/> @@ -67,7 +109,7 @@ class Index extends React.Component {
{lds.get(store.outputs, 'local.data')}
-
目标主机执行 :
+ ))} -
+ ) } } diff --git a/spug_web/src/pages/deploy/do/index.module.css b/spug_web/src/pages/deploy/do/index.module.css index 8863064..9173a06 100644 --- a/spug_web/src/pages/deploy/do/index.module.css +++ b/spug_web/src/pages/deploy/do/index.module.css @@ -2,6 +2,10 @@ display: flex; } +.collapse { + margin-top: 16px; +} + .collapse :global(.ant-collapse-content-box) { padding: 0; } diff --git a/spug_web/src/pages/deploy/do/store.js b/spug_web/src/pages/deploy/do/store.js index 0edb6a0..8eec50d 100644 --- a/spug_web/src/pages/deploy/do/store.js +++ b/spug_web/src/pages/deploy/do/store.js @@ -3,6 +3,7 @@ import { observable } from "mobx"; class Store { @observable outputs = {}; @observable targets = []; + @observable request = {}; } export default new Store() \ No newline at end of file