From d5b609cd12e9a61f7730bd3e8d71499b305207a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E4=BA=8C=E7=8C=9B?= Date: Wed, 18 Dec 2019 09:21:43 +0800 Subject: [PATCH] A web update --- spug_web/src/pages/deploy/request/Ext1Form.js | 51 +++++++++++------- .../src/pages/deploy/request/SelectApp.js | 6 +-- spug_web/src/pages/deploy/request/Table.js | 53 +++++++++++++------ spug_web/src/pages/deploy/request/index.js | 10 ++-- spug_web/src/pages/deploy/request/store.js | 13 ++++- 5 files changed, 82 insertions(+), 51 deletions(-) diff --git a/spug_web/src/pages/deploy/request/Ext1Form.js b/spug_web/src/pages/deploy/request/Ext1Form.js index cc75eb1..145c600 100644 --- a/spug_web/src/pages/deploy/request/Ext1Form.js +++ b/spug_web/src/pages/deploy/request/Ext1Form.js @@ -10,24 +10,28 @@ import lds from 'lodash'; class Ext1Form extends React.Component { constructor(props) { super(props); + this.isReady = false; this.state = { loading: false, fetching: true, - git_type: 'branch', - extra1: undefined, - extra2: undefined, + git_type: lds.get(store.record, 'extra.0', 'branch'), + extra1: lds.get(store.record, 'extra.1'), + extra2: lds.get(store.record, 'extra.2'), versions: {}, host_ids: store.record['host_ids'].concat() } } componentDidMount() { - this.fetchVersions() + this.fetchVersions(); + if (hostStore.records.length === 0) { + hostStore.fetchRecords() + } } fetchVersions = () => { this.setState({fetching: true}); - http.get(`/api/app/${store.record.id}/versions/`) + http.get(`/api/app/${store.record.app_id}/versions/`) .then(res => { this.setState({versions: res}, this._initExtra1); }) @@ -35,19 +39,23 @@ class Ext1Form extends React.Component { }; _initExtra1 = () => { - const {git_type, versions: {branches, tags}} = this.state; - let [extra1, extra2] = [undefined, undefined]; - if (git_type === 'branch') { - if (branches) { - extra1 = lds.get(Object.keys(branches), 0); - extra2 = lds.get(branches[extra1], '0.id') + if (this.isReady === true || this.state.extra1 === undefined) { + const {git_type, versions: {branches, tags}} = this.state; + let [extra1, extra2] = [undefined, undefined]; + if (git_type === 'branch') { + if (branches) { + extra1 = lds.get(Object.keys(branches), 0); + extra2 = lds.get(branches[extra1], '0.id') + } + } else { + if (tags) { + extra1 = lds.get(Object.keys(tags), 0) + } } + this.setState({extra1, extra2}) } else { - if (tags) { - extra1 = lds.get(Object.keys(tags), 0) - } + this.isReady = true } - this.setState({extra1, extra2}) }; switchType = (v) => { @@ -67,13 +75,16 @@ class Ext1Form extends React.Component { return message.error('请至少选择一个要发布的目标主机') } this.setState({loading: true}); + const {git_type, extra1, extra2} = this.state; const formData = this.props.form.getFieldsValue(); formData['id'] = store.record.id; - formData['body'] = this.state.body; - http.post('/api/exec/template/', formData) + formData['app_id'] = store.record.app_id; + formData['host_ids'] = this.state.host_ids; + formData['extra'] = [git_type, extra1, extra2]; + http.post('/api/deploy/request/', formData) .then(res => { message.success('操作成功'); - store.formVisible = false; + store.ext1Visible = false; store.fetchRecords() }, () => this.setState({loading: false})) }; @@ -135,7 +146,7 @@ class Ext1Form extends React.Component { {git_type === 'branch' && ( store.f_type = v} placeholder="请选择"> - {store.types.map(item => ( - {item} - ))} - + store.f_app_name = e.target.value} placeholder="请输入"/> - + store.f_name = e.target.value} placeholder="请输入"/> diff --git a/spug_web/src/pages/deploy/request/store.js b/spug_web/src/pages/deploy/request/store.js index 9a49258..1fb9172 100644 --- a/spug_web/src/pages/deploy/request/store.js +++ b/spug_web/src/pages/deploy/request/store.js @@ -11,14 +11,23 @@ class Store { @observable ext2Visible = false; @observable f_name; - @observable f_type; + @observable f_app_name; fetchRecords = () => { this.isFetching = true; - http.get('/api/app/') + http.get('/api/deploy/request/') .then(res => this.records = res) .finally(() => this.isFetching = false) }; + + showForm = (info) => { + this.record = info; + if (info['app_extend'] === '1') { + this.ext1Visible = true + } else { + this.ext2Visible = true + } + } } export default new Store() \ No newline at end of file