# 批量执行窗口增加直接打开web终端功能

pull/410/head
vapao 2021-10-28 10:16:09 +08:00
parent a7b17f09f3
commit 9c7e77f506
3 changed files with 34 additions and 35 deletions

View File

@ -6,7 +6,7 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { observer, useLocalStore } from 'mobx-react'; import { observer, useLocalStore } from 'mobx-react';
import { Card, Progress, Modal, Collapse, Steps, Skeleton } from 'antd'; import { Card, Progress, Modal, Collapse, Steps, Skeleton } from 'antd';
import { ShrinkOutlined, CaretRightOutlined, LoadingOutlined, CloseOutlined, CodeOutlined } from '@ant-design/icons'; import { ShrinkOutlined, LoadingOutlined, CloseOutlined, CodeOutlined } from '@ant-design/icons';
import OutView from './OutView'; import OutView from './OutView';
import { http, X_TOKEN } from 'libs'; import { http, X_TOKEN } from 'libs';
import styles from './index.module.less'; import styles from './index.module.less';
@ -161,10 +161,7 @@ function Ext1Console(props) {
</Collapse> </Collapse>
)} )}
<Collapse <Collapse defaultActiveKey="0" className={styles.collapse}>
defaultActiveKey="0"
className={styles.collapse}
expandIcon={({isActive}) => <CaretRightOutlined style={{fontSize: 16}} rotate={isActive ? 90 : 0}/>}>
{Object.entries(hosts).map(([key, item], index) => ( {Object.entries(hosts).map(([key, item], index) => (
<Collapse.Panel <Collapse.Panel
key={index} key={index}

View File

@ -6,7 +6,7 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { observer, useLocalStore } from 'mobx-react'; import { observer, useLocalStore } from 'mobx-react';
import { Card, Progress, Modal, Collapse, Steps, Skeleton } from 'antd'; import { Card, Progress, Modal, Collapse, Steps, Skeleton } from 'antd';
import { ShrinkOutlined, CaretRightOutlined, LoadingOutlined, CloseOutlined, CodeOutlined } from '@ant-design/icons'; import { ShrinkOutlined, LoadingOutlined, CloseOutlined, CodeOutlined } from '@ant-design/icons';
import OutView from './OutView'; import OutView from './OutView';
import { http, X_TOKEN } from 'libs'; import { http, X_TOKEN } from 'libs';
import styles from './index.module.less'; import styles from './index.module.less';
@ -171,8 +171,7 @@ function Ext2Console(props) {
accordion accordion
defaultActiveKey="0" defaultActiveKey="0"
className={styles.collapse} className={styles.collapse}
style={{marginTop: sActions.length > 0 ? 24 : 0}} style={{marginTop: sActions.length > 0 ? 24 : 0}}>
expandIcon={({isActive}) => <CaretRightOutlined style={{fontSize: 16}} rotate={isActive ? 90 : 0}/>}>
{hostOutputs.map((item, index) => ( {hostOutputs.map((item, index) => (
<Collapse.Panel <Collapse.Panel
key={index} key={index}

View File

@ -6,12 +6,12 @@
import React from 'react'; import React from 'react';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { import {
CaretRightOutlined,
CheckCircleTwoTone, CheckCircleTwoTone,
LoadingOutlined, LoadingOutlined,
WarningTwoTone, WarningTwoTone,
FullscreenOutlined, FullscreenOutlined,
FullscreenExitOutlined FullscreenExitOutlined,
CodeOutlined
} from '@ant-design/icons'; } from '@ant-design/icons';
import { Modal, Collapse, Tooltip } from 'antd'; import { Modal, Collapse, Tooltip } from 'antd';
import OutView from './OutView'; import OutView from './OutView';
@ -82,27 +82,26 @@ class ExecConsole extends React.Component {
} }
} }
genExtra = (status, key) => { StatusExtra = (props) => (
if (status === -2) {
return <LoadingOutlined style={{fontSize: 20, color: '#108ee9'}}/>;
} else if (status === 0) {
return (
<div style={{display: 'flex', alignItems: 'center'}}> <div style={{display: 'flex', alignItems: 'center'}}>
<pre className={styles.header2}>{this.lastOutputs[key]}</pre> {props.status === -2 ? (
<CheckCircleTwoTone style={{fontSize: 20}} twoToneColor="#52c41a"/> <LoadingOutlined style={{fontSize: 22, color: '#108ee9'}}/>
</div> ) : (
) <>
} else { <pre className={styles.header2}>{this.lastOutputs[props.id]}</pre>
return ( {props.status === 0 ? (
<div style={{display: 'flex', alignItems: 'center'}}> <CheckCircleTwoTone style={{fontSize: 22}} twoToneColor="#52c41a"/>
<pre className={styles.header2}>{this.lastOutputs[key]}</pre> ) : (
<Tooltip title={`退出状态码:${status}`}> <Tooltip title={`退出状态码:${props.status}`}>
<WarningTwoTone style={{fontSize: 20}} twoToneColor="red"/> <WarningTwoTone style={{fontSize: 22}} twoToneColor="red"/>
</Tooltip> </Tooltip>
)}
</>
)}
<CodeOutlined style={{fontSize: 22, color: '#1890ff', marginLeft: 16}}
onClick={e => this.openTerminal(e, props.id)}/>
</div> </div>
) )
}
};
handleUpdate = (data) => { handleUpdate = (data) => {
this.setState(data, () => { this.setState(data, () => {
@ -111,6 +110,11 @@ class ExecConsole extends React.Component {
}) })
} }
openTerminal = (e, key) => {
e.stopPropagation()
window.open(`/ssh?id=${key}`)
}
render() { render() {
const {isFullscreen, activeKey} = this.state; const {isFullscreen, activeKey} = this.state;
return ( return (
@ -131,13 +135,12 @@ class ExecConsole extends React.Component {
accordion accordion
className={styles.collapse} className={styles.collapse}
activeKey={activeKey} activeKey={activeKey}
onChange={key => this.handleUpdate({activeKey: key})} onChange={key => this.handleUpdate({activeKey: key})}>
expandIcon={({isActive}) => <CaretRightOutlined style={{fontSize: 16}} rotate={isActive ? 90 : 0}/>}>
{Object.entries(store.outputs).map(([key, item], index) => ( {Object.entries(store.outputs).map(([key, item], index) => (
<Collapse.Panel <Collapse.Panel
key={key} key={key}
header={<div className={styles.header1}>{item['title']}</div>} header={<div className={styles.header1}>{item.title}</div>}
extra={this.genExtra(item.status, key)}> extra={<this.StatusExtra status={item.status} id={key}/>}>
<OutView <OutView
isFullscreen={isFullscreen} isFullscreen={isFullscreen}
getOutput={() => this.outputs[key]} getOutput={() => this.outputs[key]}