Skip to content

Commit

Permalink
Merge pull request #1419 from jumpserver/pr@dev@fix_message_repeat
Browse files Browse the repository at this point in the history
fixed: fixed issue where multiple tabs would cause message to be written to another
  • Loading branch information
feng626 authored Aug 21, 2024
2 parents 7afb146 + 43f7592 commit 65e82ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
9 changes: 0 additions & 9 deletions ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,6 @@ onMounted(() => {
sendTerminalData();
// watch(
// () => terminalRef.value,
// newValue => {
// if (newValue) {
// sendTerminalData();
// }
// }
// );
const key: string = currentNode.key as string;
nameRef.value = key;
Expand Down
2 changes: 0 additions & 2 deletions ui/src/directive/sidebarDraggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export const draggable = {
startX = event.clientX;
startWidth = el.offsetWidth;

console.log(startX, startWidth);

document.addEventListener('mousemove', mouseMoveHandler);
document.addEventListener('mouseup', mouseUpHandler);
}
Expand Down
23 changes: 11 additions & 12 deletions ui/src/hooks/useTerminal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 导入外部库
import { ref, watch } from 'vue';
import { ref } from 'vue';
import { nextTick, Ref } from 'vue';
import { storeToRefs } from 'pinia';
import { Terminal } from '@xterm/xterm';
Expand Down Expand Up @@ -92,22 +92,21 @@ export const useTerminal = (callbackOptions: ICallbackOptions): ITerminalReturn

const { currentTab } = storeToRefs(useTerminalStore());

nextTick(() => {
watch(
() => k8s_id.value,
newId => {
console.log(newId);
}
);
const messageHandlers = {
[currentTab.value]: (e: MessageEvent) => {
handleK8sMessage(JSON.parse(e.data));
}
};

nextTick(() => {
sentry = createSentry(callbackOptions.transSocket!, terminalRef.value!);

console.log(currentTab.value);

if (callbackOptions.transSocket) {
// 现在相当于给所有的 socket 加上了 message
callbackOptions.transSocket.addEventListener('message', (e: MessageEvent) => {
return handleK8sMessage(JSON.parse(e.data));
const handler = messageHandlers[currentTab.value];
if (handler) {
handler(e);
}
});
}
}).then();
Expand Down

0 comments on commit 65e82ee

Please sign in to comment.