fix issue

pull/330/head
vapao 2021-03-31 17:31:10 +08:00
parent fe86ac7e1b
commit 95a76f133a
2 changed files with 22 additions and 18 deletions

View File

@ -6,9 +6,9 @@
import React from 'react'; import React from 'react';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { PlusOutlined, ThunderboltOutlined } from '@ant-design/icons'; import { PlusOutlined, ThunderboltOutlined } from '@ant-design/icons';
import { Form, Button, Card, Tag } from 'antd'; import { Form, Button, Card, Alert } from 'antd';
import { ACEditor, AuthDiv, Breadcrumb } from 'components'; import { ACEditor, AuthDiv, Breadcrumb } from 'components';
import HostSelector from './HostSelector'; import Selector from 'pages/host/Selector';
import TemplateSelector from './TemplateSelector'; import TemplateSelector from './TemplateSelector';
import ExecConsole from './ExecConsole'; import ExecConsole from './ExecConsole';
import { http, cleanCommand } from 'libs'; import { http, cleanCommand } from 'libs';
@ -26,7 +26,7 @@ class TaskIndex extends React.Component {
handleSubmit = () => { handleSubmit = () => {
this.setState({loading: true}); this.setState({loading: true});
const host_ids = store.hosts.map(item => item.id); const host_ids = store.host_ids;
http.post('/api/exec/do/', {host_ids, command: cleanCommand(this.state.body)}) http.post('/api/exec/do/', {host_ids, command: cleanCommand(this.state.body)})
.then(store.switchConsole) .then(store.switchConsole)
.finally(() => this.setState({loading: false})) .finally(() => this.setState({loading: false}))
@ -43,17 +43,15 @@ class TaskIndex extends React.Component {
</Breadcrumb> </Breadcrumb>
<Card> <Card>
<Form layout="vertical"> <Form layout="vertical">
<Form.Item label="执行主机" style={{marginBottom: 12}}> <Form.Item required label="目标主机">
{store.hosts.map(item => ( {store.host_ids.length > 0 && (
<Tag <Alert style={{width: 200}} type="info" message={`已选择 ${store.host_ids.length}`}/>
closable )}
color="#108ee9"
key={item.id}
onClose={() => store.hosts = store.hosts.filter(x => x.id !== item.id)}>
{item.name}({item.hostname}:{item.port})</Tag>
))}
</Form.Item> </Form.Item>
<Button style={{marginBottom: 24}} icon={<PlusOutlined/>} onClick={store.switchHost}>从主机列表中选择</Button> <Button
style={{marginBottom: 24}}
icon={<PlusOutlined/>}
onClick={() => store.showHost = true}>从主机列表中选择</Button>
<Form.Item label="执行命令"> <Form.Item label="执行命令">
<ACEditor mode="sh" value={body} height="300px" onChange={body => this.setState({body})}/> <ACEditor mode="sh" value={body} height="300px" onChange={body => this.setState({body})}/>
</Form.Item> </Form.Item>
@ -63,10 +61,14 @@ class TaskIndex extends React.Component {
<Button icon={<ThunderboltOutlined/>} type="primary" onClick={this.handleSubmit}>开始执行</Button> <Button icon={<ThunderboltOutlined/>} type="primary" onClick={this.handleSubmit}>开始执行</Button>
</Form> </Form>
</Card> </Card>
{store.showHost && <HostSelector onCancel={store.switchHost} onOk={hosts => store.hosts = hosts}/>}
{store.showTemplate && {store.showTemplate &&
<TemplateSelector onCancel={store.switchTemplate} onOk={v => this.setState({body: body + v})}/>} <TemplateSelector onCancel={store.switchTemplate} onOk={v => this.setState({body: body + v})}/>}
{store.showConsole && <ExecConsole token={token} onCancel={store.switchConsole}/>} {store.showConsole && <ExecConsole token={token} onCancel={store.switchConsole}/>}
<Selector
visible={store.showHost}
selectedRowKeys={[...store.host_ids]}
onCancel={() => store.showHost = false}
onOk={(_, ids) => store.host_ids = ids}/>
</AuthDiv> </AuthDiv>
); );
} }

View File

@ -4,10 +4,11 @@
* Released under the AGPL-3.0 License. * Released under the AGPL-3.0 License.
*/ */
import { observable } from "mobx"; import { observable } from "mobx";
import hostStore from 'pages/host/store';
class Store { class Store {
@observable outputs = {}; @observable outputs = {};
@observable hosts = []; @observable host_ids = [];
@observable token = null; @observable token = null;
@observable isFullscreen = false; @observable isFullscreen = false;
@observable showHost = false; @observable showHost = false;
@ -27,10 +28,11 @@ class Store {
this.showConsole = false; this.showConsole = false;
this.outputs = {} this.outputs = {}
} else { } else {
for (let item of this.hosts) { for (let id of this.host_ids) {
const key = `${item.hostname}:${item.port}`; const host = hostStore.idMap[id];
const key = `${host.hostname}:${host.port}`;
this.outputs[key] = { this.outputs[key] = {
title: `${item.name}(${key})`, title: `${host.name}(${key})`,
system: ['### Establishing communication\n'], system: ['### Establishing communication\n'],
info: [], info: [],
error: [], error: [],