diff --git a/pkg/api/routes.go b/pkg/api/routes.go index 76a72e4..a4c5121 100644 --- a/pkg/api/routes.go +++ b/pkg/api/routes.go @@ -104,8 +104,8 @@ func SetupRoutes() *echo.Echo { { sessions.POST("", SessionCreateEndpoint) sessions.GET("/paging", SessionPagingEndpoint) - sessions.POST("/:id/content", SessionContentEndpoint) - sessions.POST("/:id/discontent", Admin(SessionDiscontentEndpoint)) + sessions.POST("/:id/connect", SessionConnectEndpoint) + sessions.POST("/:id/disconnect", Admin(SessionDisconnectEndpoint)) sessions.POST("/:id/resize", SessionResizeEndpoint) sessions.POST("/:id/upload", SessionUploadEndpoint) sessions.GET("/:id/download", SessionDownloadEndpoint) diff --git a/pkg/api/session.go b/pkg/api/session.go index 20e2dbc..f5d9311 100644 --- a/pkg/api/session.go +++ b/pkg/api/session.go @@ -75,7 +75,7 @@ func SessionDeleteEndpoint(c echo.Context) error { return Success(c, nil) } -func SessionContentEndpoint(c echo.Context) error { +func SessionConnectEndpoint(c echo.Context) error { sessionId := c.Param("id") session := model.Session{} @@ -89,7 +89,7 @@ func SessionContentEndpoint(c echo.Context) error { return Success(c, nil) } -func SessionDiscontentEndpoint(c echo.Context) error { +func SessionDisconnectEndpoint(c echo.Context) error { sessionIds := c.Param("id") split := strings.Split(sessionIds, ",") diff --git a/web/src/components/access/Access.js b/web/src/components/access/Access.js index b6e682c..7412c49 100644 --- a/web/src/components/access/Access.js +++ b/web/src/components/access/Access.js @@ -167,7 +167,7 @@ class Access extends Component { }; updateSessionStatus = async (sessionId) => { - let result = await request.post(`/sessions/${sessionId}/content`); + let result = await request.post(`/sessions/${sessionId}/connect`); if (result.code !== 1) { message.error(result.message); } diff --git a/web/src/components/access/Console.js b/web/src/components/access/Console.js index be69114..984e963 100644 --- a/web/src/components/access/Console.js +++ b/web/src/components/access/Console.js @@ -101,7 +101,10 @@ class Console extends Component { if (command !== '') { let webSocket = this.state.webSocket; if (webSocket !== undefined && webSocket.readyState === WebSocket.OPEN) { - webSocket.send(JSON.stringify({type: 'data', content: command + String.fromCharCode(13)})); + webSocket.send(JSON.stringify({ + type: 'data', + content: command + String.fromCharCode(13) + })); } } executedCommand = true; @@ -142,7 +145,7 @@ class Console extends Component { } term.focus(); - if(webSocket.readyState === WebSocket.OPEN){ + if (webSocket.readyState === WebSocket.OPEN) { webSocket.send(JSON.stringify({type: 'resize', content: JSON.stringify({height, width})})); } } diff --git a/web/src/components/command/BatchCommand.js b/web/src/components/command/BatchCommand.js index 0c3e61a..57f8a25 100644 --- a/web/src/components/command/BatchCommand.js +++ b/web/src/components/command/BatchCommand.js @@ -1,9 +1,11 @@ import React, {Component} from 'react'; -import {Card, Input, List, PageHeader} from "antd"; +import {Card, Input, List, PageHeader, Spin} from "antd"; import Console from "../access/Console"; import {itemRender} from "../../utils/utils"; import Logout from "../user/Logout"; import './Command.css' +import request from "../../common/request"; +import {message} from "antd/es"; const {Search} = Input; const routes = [ @@ -29,13 +31,31 @@ class BatchCommand extends Component { webSockets: [], assets: [], active: undefined, + loading: true } componentDidMount() { let params = new URLSearchParams(this.props.location.search); - let command = params.get('command'); 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 }) @@ -66,50 +86,53 @@ class BatchCommand extends Component { > -
- { - 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) - })); + +
+ { + 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='执行'/> -
+ this.commandRef.current.setValue(''); + }} enterButton='执行'/> +
+ +
+ ( + + { + if (this.state.active === item['id']) { + this.setState({ + active: undefined + }) + } else { + this.setState({ + active: item['id'] + }) + } + }} + > + + + + )} + /> +
+ -
- ( - - { - if (this.state.active === item['id']) { - this.setState({ - active: undefined - }) - } else { - this.setState({ - active: item['id'] - }) - } - }} - > - - - - )} - /> -
); } diff --git a/web/src/components/command/Command.css b/web/src/components/command/Command.css index cc9ebec..43af6c5 100644 --- a/web/src/components/command/Command.css +++ b/web/src/components/command/Command.css @@ -1,4 +1,4 @@ .command-active { - box-shadow: 0 0 0 2px #1890FF; - outline: 2px solid #1890FF; + box-shadow: 0 0 0 2px red; + outline: 2px solid red; } \ No newline at end of file diff --git a/web/src/components/command/DynamicCommand.js b/web/src/components/command/DynamicCommand.js index b40e095..d3cb9b4 100644 --- a/web/src/components/command/DynamicCommand.js +++ b/web/src/components/command/DynamicCommand.js @@ -73,7 +73,7 @@ class DynamicCommand extends Component { assetsVisible: false, assets: [], checkedAssets: [], - command: '', + commandId: '', model: null, selectedRowKeys: [], delBtnLoading: false, @@ -223,7 +223,7 @@ class DynamicCommand extends Component { } }); - window.location.href = '#/batch-command?command=' + this.state.command + '&assets=' + JSON.stringify(cAssets); + window.location.href = '#/batch-command?commandId=' + this.state.commandId + '&assets=' + JSON.stringify(cAssets); }; handleOk = async (formData) => { @@ -463,7 +463,7 @@ class DynamicCommand extends Component { this.setState({ assetsVisible: true, - command: record.content + commandId: record['id'] }); let result = await request.get('/assets?protocol=ssh'); diff --git a/web/src/components/command/DynamicCommandModal.js b/web/src/components/command/DynamicCommandModal.js index 20aea46..deb776c 100644 --- a/web/src/components/command/DynamicCommandModal.js +++ b/web/src/components/command/DynamicCommandModal.js @@ -48,7 +48,7 @@ const DynamicCommandModal = ({title, visible, handleOk, handleCancel, confirmLoa -