|
286 | 286 | <div>实例操作终端</div> |
287 | 287 | <div> |
288 | 288 | <el-tooltip class="item" effect="dark" content="新开全屏" placement="top"> |
289 | | - <span class="terminal-right-botton"> |
| 289 | + <span class="terminal-right-botton" @click="toFullTerminal(2)"> |
290 | 290 | <i class="el-icon-monitor"></i> |
291 | 291 | </span> |
292 | 292 | </el-tooltip> |
293 | 293 | <el-tooltip class="item" effect="dark" content="立刻全屏" placement="top"> |
294 | | - <span class="terminal-right-botton"> |
| 294 | + <span class="terminal-right-botton" @click="toFullTerminal(1)"> |
295 | 295 | <i class="el-icon-full-screen"></i> |
296 | 296 | </span> |
297 | 297 | </el-tooltip> |
|
311 | 311 | > |
312 | 312 | </el-input> |
313 | 313 | </div> |
| 314 | + <div v-show="isFull" id="full-terminal-option">A</div> |
314 | 315 | </div> |
315 | 316 | </template> |
316 | 317 | </Panel> |
@@ -675,9 +676,20 @@ export default { |
675 | 676 | // 初始化 Terminal 窗口 |
676 | 677 | initTerm() { |
677 | 678 | // 创建窗口与输入事件传递 |
678 | | - this.term = initTerminalWindow(document.getElementById("terminal-container")); |
| 679 | + const terminalContainer = document.getElementById("terminal-container"); |
| 680 | + this.onChangeTerminalContainerHeight(); |
| 681 | + this.term = initTerminalWindow(terminalContainer); |
679 | 682 | this.term.onData(this.sendInput); |
680 | 683 | }, |
| 684 | + // 浏览器改变大小或重置高度事件 |
| 685 | + onChangeTerminalContainerHeight() { |
| 686 | + if (this.isFull) { |
| 687 | + const terminalContainer = document.getElementById("terminal-container"); |
| 688 | + const height = document.body.clientHeight - 50; |
| 689 | + terminalContainer.removeAttribute("style"); |
| 690 | + terminalContainer.setAttribute("style", `height: ${height}px; width:100%`); |
| 691 | + } |
| 692 | + }, |
681 | 693 | // 开启实例(Ajax) |
682 | 694 | async openInstance() { |
683 | 695 | // this.busy = true; |
@@ -938,6 +950,22 @@ export default { |
938 | 950 | showTimeStr(time, now) { |
939 | 951 | const date = new Date(now - time); |
940 | 952 | return `${date.getHours()}:${(Array(2).join(0) + date.getMinutes()).slice(-2)}`; |
| 953 | + }, |
| 954 | +
|
| 955 | + toFullTerminal(type = 1) { |
| 956 | + if (type === 1) { |
| 957 | + this.isFull = true; |
| 958 | + this.onChangeTerminalContainerHeight(); |
| 959 | + router.push({ |
| 960 | + path: `/terminal/${this.serviceUuid}/${this.instanceUuid}/`, |
| 961 | + query: { |
| 962 | + full: 1 |
| 963 | + } |
| 964 | + }); |
| 965 | + } |
| 966 | + if (type === 2) { |
| 967 | + window.open(`#/terminal/${this.serviceUuid}/${this.instanceUuid}/?full=1`); |
| 968 | + } |
941 | 969 | } |
942 | 970 | }, |
943 | 971 | // 装载事件 |
@@ -967,9 +995,15 @@ export default { |
967 | 995 | console.error(error); |
968 | 996 | // 忽略 |
969 | 997 | } |
| 998 | +
|
| 999 | + // 监听窗口变化事件 |
| 1000 | + window.addEventListener("resize", this.onChangeTerminalContainerHeight); |
970 | 1001 | }, |
971 | 1002 | // 卸载事件 |
972 | 1003 | beforeUnmount() { |
| 1004 | + // 卸载监听浏览器窗口改变时间 |
| 1005 | + window.removeEventListener("resize", this.onChangeTerminalContainerHeight); |
| 1006 | +
|
973 | 1007 | try { |
974 | 1008 | // 停止定时器 |
975 | 1009 | this.stopInterval(); |
|
0 commit comments