U 优化查看发布申请的刷新机制

pull/220/head
vapao 2020-09-28 18:03:19 +08:00
parent 87576ebe4e
commit 15cb876d8a
3 changed files with 29 additions and 26 deletions

View File

@ -21,14 +21,21 @@ class Action extends React.Component {
return <Button type="link" {...props} style={{padding: 0}}/> return <Button type="link" {...props} style={{padding: 0}}/>
} }
_handle = (data, el) => {
const length = data.length;
if (canVisible(el.props.auth)) {
if (length !== 0) data.push(<Divider key={length} type="vertical"/>)
data.push(el)
}
}
render() { render() {
const children = []; const children = [];
this.props.children.forEach((el, index) => { if (Array.isArray(this.props.children)) {
if (canVisible(el.props.auth)) { this.props.children.forEach(el => this._handle(children, el))
if (children.length !== 0) children.push(<Divider key={index} type="vertical"/>); } else {
children.push(el) this._handle(children, this.props.children)
} }
})
return <span> return <span>
{children} {children}

View File

@ -18,10 +18,11 @@ import lds from 'lodash';
class Ext1Index extends React.Component { class Ext1Index extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.timer = null;
this.id = props.match.params.id; this.id = props.match.params.id;
this.log = props.match.params.log; this.log = props.match.params.log;
this.state = { this.state = {
fetching: false, fetching: true,
loading: false, loading: false,
} }
} }
@ -32,14 +33,13 @@ class Ext1Index extends React.Component {
componentWillUnmount() { componentWillUnmount() {
if (this.socket) this.socket.close(); if (this.socket) this.socket.close();
if (this.interval) clearInterval(this.interval); if (this.timer) clearTimeout(this.timer);
store.request = {targets: [], host_actions: [], server_actions: []}; store.request = {targets: [], host_actions: [], server_actions: []};
store.outputs = {}; store.outputs = {};
} }
fetch = () => { fetch = () => {
if (this.state.fetching) return ; if (!this.timer) this.setState({fetching: true});
this.setState({fetching: true});
http.get(`/api/deploy/request/${this.id}/`, {params: {log: this.log}}) http.get(`/api/deploy/request/${this.id}/`, {params: {log: this.log}})
.then(res => { .then(res => {
store.request = res; store.request = res;
@ -53,12 +53,10 @@ class Ext1Index extends React.Component {
this._parse_message(msg, outputs) this._parse_message(msg, outputs)
} }
store.outputs = outputs; store.outputs = outputs;
if (this.interval) { if (store.request.status === '2') {
if (['3', '-3'].includes(store.request.status)) { this.timer = setTimeout(this.fetch, 2000)
clearInterval(this.interval) } else {
} this.timer = null
} else if (store.request.status === '2') {
this.interval = setInterval(this.fetch, 2000)
} }
}) })
.finally(() => this.setState({fetching: false})) .finally(() => this.setState({fetching: false}))

View File

@ -18,10 +18,11 @@ import lds from 'lodash';
class Ext1Index extends React.Component { class Ext1Index extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.timer = null;
this.id = props.match.params.id; this.id = props.match.params.id;
this.log = props.match.params.log; this.log = props.match.params.log;
this.state = { this.state = {
fetching: false, fetching: true,
loading: false, loading: false,
} }
} }
@ -32,15 +33,14 @@ class Ext1Index extends React.Component {
componentWillUnmount() { componentWillUnmount() {
if (this.socket) this.socket.close(); if (this.socket) this.socket.close();
if (this.interval) clearInterval(this.interval); if (this.timer) clearTimeout(this.timer);
store.request = {targets: [], server_actions: [], host_actions: []}; store.request = {targets: [], server_actions: [], host_actions: []};
store.outputs = {}; store.outputs = {};
} }
fetch = () => { fetch = () => {
if (this.state.fetching) return; if (!this.timer) this.setState({fetching: true});
this.setState({fetching: true});
http.get(`/api/deploy/request/${this.id}/`, {params: {log: this.log}}) http.get(`/api/deploy/request/${this.id}/`, {params: {log: this.log}})
.then(res => { .then(res => {
store.request = res; store.request = res;
@ -54,12 +54,10 @@ class Ext1Index extends React.Component {
this._parse_message(msg, outputs) this._parse_message(msg, outputs)
} }
store.outputs = outputs; store.outputs = outputs;
if (this.interval) { if (store.request.status === '2') {
if (['3', '-3'].includes(store.request.status)) { this.timer = setTimeout(this.fetch, 2000)
clearInterval(this.interval) } else {
} this.timer = null
} else if (store.request.status === '2') {
this.interval = setInterval(this.fetch, 2000)
} }
}) })
.finally(() => this.setState({fetching: false})) .finally(() => this.setState({fetching: false}))