|
|
@@ -1,8 +1,8 @@
|
|
|
import React, { PureComponent } from 'react';
|
|
|
import { Terminal as XTerm } from 'xterm';
|
|
|
-import {message} from 'antd'
|
|
|
-import styles from './terminal.less'
|
|
|
-import 'xterm/css/xterm.css'
|
|
|
+import { message } from 'antd';
|
|
|
+import styles from './terminal.less';
|
|
|
+import 'xterm/css/xterm.css';
|
|
|
import { FitAddon } from 'xterm-addon-fit';
|
|
|
|
|
|
export default class Terminal extends PureComponent {
|
|
|
@@ -10,24 +10,25 @@ export default class Terminal extends PureComponent {
|
|
|
this.term = new XTerm();
|
|
|
const fitAddon = new FitAddon();
|
|
|
this.term.loadAddon(fitAddon);
|
|
|
- this.term.open(document.getElementById('terminal'), true)
|
|
|
+ this.term.open(document.getElementById('terminal'), true);
|
|
|
fitAddon.fit();
|
|
|
const isDev = process.env.NODE_ENV === 'development';
|
|
|
- this.socket = new WebSocket(`ws://${isDev ? '172.19.240.15:8080' : window.location.host}/ws/terminal${this.props.location?.search}`);
|
|
|
- this.socket.onerror = (error) => {
|
|
|
+ this.socket = new WebSocket(
|
|
|
+ `wss://${
|
|
|
+ isDev ? '172.19.240.15:8080' : window.location.host
|
|
|
+ }/ws/terminal${this.props.location?.search}`,
|
|
|
+ );
|
|
|
+ this.socket.onerror = error => {
|
|
|
message.error('连接错误!请尝试重新登陆或重新打开终端!');
|
|
|
- }
|
|
|
- this.socket.onmessage = (event) => {
|
|
|
+ };
|
|
|
+ this.socket.onmessage = event => {
|
|
|
this.term.write(event.data);
|
|
|
- }
|
|
|
- this.term.onData((data) => {
|
|
|
+ };
|
|
|
+ this.term.onData(data => {
|
|
|
this.socket.send(data);
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
render() {
|
|
|
- return (
|
|
|
- <div id="terminal" style={{height: '100%', width: '100%'}}>
|
|
|
- </div>
|
|
|
- );
|
|
|
+ return <div id="terminal" style={{ height: '100%', width: '100%' }}></div>;
|
|
|
}
|
|
|
}
|