diff --git a/spug_web/src/pages/deploy/request/Ext1Form.js b/spug_web/src/pages/deploy/request/Ext1Form.js index ce4071c..8f9c8d6 100644 --- a/spug_web/src/pages/deploy/request/Ext1Form.js +++ b/spug_web/src/pages/deploy/request/Ext1Form.js @@ -105,8 +105,9 @@ export default observer(function () { if (index === -1) { setHostIds([id, ...host_ids]) } else { - host_ids.splice(index, 1); - setHostIds(host_ids) + const tmp = lds.clone(host_ids); + tmp.splice(index, 1); + setHostIds(tmp) } } diff --git a/spug_web/src/pages/deploy/request/Ext2Form.js b/spug_web/src/pages/deploy/request/Ext2Form.js index 28e46f5..4d54304 100644 --- a/spug_web/src/pages/deploy/request/Ext2Form.js +++ b/spug_web/src/pages/deploy/request/Ext2Form.js @@ -3,130 +3,119 @@ * Copyright (c) * Released under the AGPL-3.0 License. */ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { observer } from 'mobx-react'; +import { UploadOutlined } from '@ant-design/icons'; import { Modal, Form, Input, Tag, Upload, message, Button } from 'antd'; import hostStore from 'pages/host/store'; import { http, X_TOKEN } from 'libs'; import store from './store'; import lds from 'lodash'; -@observer -class Ext2Form extends React.Component { - constructor(props) { - super(props); - this.state = { - loading: false, - uploading: false, - fileList: [], - host_ids: store.record['app_host_ids'].concat() - } - } +export default observer(function () { + const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); + const [uploading, setUploading] = useState(false); + const [fileList, setFileList] = useState([]); + const [host_ids, setHostIds] = useState(lds.clone(store.record.app_host_ids)); - componentDidMount() { + useEffect(() => { if (hostStore.records.length === 0) { hostStore.fetchRecords() } const file = lds.get(store, 'record.extra.1'); if (file) { file.uid = '0'; - this.setState({fileList: [file]}) + setFileList([file]) } - } + }, []) - handleSubmit = () => { - if (this.state.host_ids.length === 0) { + function handleSubmit() { + if (host_ids.length === 0) { return message.error('请至少选择一个要发布的目标主机') } - this.setState({loading: true}); - const formData = this.props.form.getFieldsValue(); + setLoading(true); + const formData = form.getFieldsValue(); formData['id'] = store.record.id; formData['deploy_id'] = store.record.deploy_id; formData['extra'] = [formData['extra']]; - if (this.state.fileList.length > 0) { - formData['extra'].push(lds.pick(this.state.fileList[0], ['path', 'name'])) + if (fileList.length > 0) { + formData['extra'].push(lds.pick(fileList[0], ['path', 'name'])) } - formData['host_ids'] = this.state.host_ids; + formData['host_ids'] = host_ids; http.post('/api/deploy/request/', formData) .then(res => { message.success('操作成功'); store.ext2Visible = false; store.fetchRecords() - }, () => this.setState({loading: false})) - }; + }, () => setLoading(false)) + } - handleChange = (id, v) => { - const host_ids = this.state.host_ids; + function handleChange(id, v) { const index = host_ids.indexOf(id); if (index === -1) { - this.setState({host_ids: [id, ...host_ids]}) + setHostIds([id, ...host_ids]) } else { - host_ids.splice(index, 1); - this.setState({host_ids}) + const tmp = lds.clone(host_ids); + tmp.splice(index, 1); + setHostIds(tmp) } - }; + } - handleUploadChange = (v) => { + function handleUploadChange(v) { if (v.fileList.length === 0) { - this.setState({fileList: []}) + setFileList([]) } - }; + } - handleUpload = (file, fileList) => { - this.setState({uploading: true}); + function handleUpload(file, fileList) { + setUploading(true); const formData = new FormData(); formData.append('file', file); formData.append('deploy_id', store.record.deploy_id); http.post('/api/deploy/request/upload/', formData, {timeout: 120000}) .then(res => { file.path = res; - this.setState({fileList: [file]}) + setFileList([file]) }) - .finally(() => this.setState({uploading: false})) + .finally(() => setUploading(false)) return false - }; - - render() { - const info = store.record; - const {host_ids, fileList, uploading} = this.state; - const {getFieldDecorator} = this.props.form; - return ( - store.ext2Visible = false} - confirmLoading={this.state.loading} - onOk={this.handleSubmit}> -
- - {getFieldDecorator('name', {initialValue: info['name']})( - - )} - - - {getFieldDecorator('extra', {initialValue: lds.get(info, 'extra.0')})( - - )} - - - - {fileList.length === 0 ? : null} - - - - {info['app_host_ids'].map(id => ( - this.handleChange(id, v)}> - {lds.get(hostStore.idMap, `${id}.name`)}({lds.get(hostStore.idMap, `${id}.hostname`)}:{lds.get(hostStore.idMap, `${id}.port`)}) - - ))} - -
-
- ) } -} -export default Form.create()(Ext2Form) + return ( + store.ext2Visible = false} + confirmLoading={loading} + onOk={handleSubmit}> +
+ + + + + + + + + {fileList.length === 0 ? : null} + + + + {store.record['app_host_ids'].map(id => ( + handleChange(id, v)}> + {lds.get(hostStore.idMap, `${id}.name`)}({lds.get(hostStore.idMap, `${id}.hostname`)}:{lds.get(hostStore.idMap, `${id}.port`)}) + + ))} + +
+
+ ) +}) \ No newline at end of file diff --git a/spug_web/src/pages/deploy/request/Table.js b/spug_web/src/pages/deploy/request/Table.js index 1556b15..efa684e 100644 --- a/spug_web/src/pages/deploy/request/Table.js +++ b/spug_web/src/pages/deploy/request/Table.js @@ -69,11 +69,11 @@ class ComTable extends React.Component { render: info => { if (info.status === '-1' && info.reason) { return - {info['status_alias']} + {info['status_alias']} } else if (info.status === '1' && info.reason) { return - {info['status_alias']} + {info['status_alias']} } else if (info.status === '2') { return {info['status_alias']}