import React, {Component} from 'react'; import {Card, Input, List, PageHeader, Spin} from "antd"; import Console from "../access/Console"; import {itemRender} from "../../utils/utils"; import './Command.css' import request from "../../common/request"; import {message} from "antd/es"; const {Search} = Input; const routes = [ { path: '', breadcrumbName: '首页', }, { path: '/dynamic-command', breadcrumbName: '动态指令', }, { path: '/batch-command', breadcrumbName: '批量执行命令', } ]; class BatchCommand extends Component { commandRef = React.createRef(); state = { webSockets: [], assets: [], active: undefined, loading: true } componentDidMount() { let params = new URLSearchParams(this.props.location.search); let assets = JSON.parse(params.get('assets')); let commandId = params.get('commandId'); this.init(commandId, assets) } init = async (commandId, assets) => { let result = await request.get(`/commands/${commandId}`); if (result['code'] !== 1) { message.error(result['message'], 10); this.setState({ loading: false }) return; } let command = result['data']['content']; this.setState({ loading: false, command: command, assets: assets }) } onPaneChange = activeKey => { this.setState({activeKey}); }; appendWebsocket = (webSocket) => { this.state.webSockets.push(webSocket); } render() { return ( <>
{ for (let i = 0; i < this.state.webSockets.length; i++) { let ws = this.state.webSockets[i]['ws']; if (ws.readyState === WebSocket.OPEN) { ws.send(JSON.stringify({ type: 'data', content: value + String.fromCharCode(13) })); } } this.commandRef.current.setValue(''); }} enterButton='执行'/>
( { if (this.state.active === item['id']) { this.setState({ active: undefined }) } else { this.setState({ active: item['id'] }) } }} > )} />
); } } export default BatchCommand;