diff --git a/spug_api/apps/host/views.py b/spug_api/apps/host/views.py index 329a740..ef8e270 100644 --- a/spug_api/apps/host/views.py +++ b/spug_api/apps/host/views.py @@ -46,6 +46,19 @@ class HostView(View): Host.objects.create(created_by=request.user, **form) return json_response(error=error) + def patch(self, request): + form, error = JsonParser( + Argument('id', type=int, required=False), + Argument('zone', help='请输入主机类别') + ).parse(request.body) + if error is None: + host = Host.objects.filter(pk=form.id).first() + if not host: + return json_response(error='未找到指定主机') + count = Host.objects.filter(zone=host.zone, deleted_by_id__isnull=True).update(zone=form.zone) + return json_response(count) + return json_response(error=error) + def delete(self, request): form, error = JsonParser( Argument('id', type=int, help='请指定操作对象') diff --git a/spug_web/src/pages/host/Form.js b/spug_web/src/pages/host/Form.js index b25cdb4..c610d10 100644 --- a/spug_web/src/pages/host/Form.js +++ b/spug_web/src/pages/host/Form.js @@ -16,7 +16,8 @@ class ComForm extends React.Component { this.state = { loading: false, password: null, - zone: null, + addZone: null, + editZone: store.record.zone, } } @@ -65,26 +66,48 @@ class ComForm extends React.Component { }; handleAddZone = () => { - Modal.confirm({ - icon: 'exclamation-circle', - title: '添加主机类别', - content: this.addZoneForm, - onOk: () => { - if (this.state.zone) { - store.zones.push(this.state.zone); - this.props.form.setFieldsValue({'zone': this.state.zone}) - } - }, - }) + this.setState({zone: ''}, () => { + Modal.confirm({ + icon: 'exclamation-circle', + title: '添加主机类别', + content: ( +