Skip to content

Commit

Permalink
fixed: Fixed command duplication issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoJiSen committed Oct 14, 2024
1 parent 993cd06 commit cc815b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ const handleClose = (name: string) => {
findNodeById(nameRef.value);
terminalStore.setTerminalConfig('currentTab', nameRef.value);
}
if (panelLength === 0) {
mittBus.emit('remove-event');
}
};
/**
Expand Down
14 changes: 11 additions & 3 deletions ui/src/hooks/useTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr
let lastReceiveTime: Ref<Date> = ref(new Date());

let messageHandlers = {};
let handleSocketMessage: any;

const dispatch = (data: string) => {
if (!data) return;
Expand Down Expand Up @@ -560,14 +561,16 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr
}
};

option.transSocket?.addEventListener('message', (e: MessageEvent) => {
handleSocketMessage = (e: MessageEvent) => {
// @ts-ignore
const handler = messageHandlers[currentTab.value as string];
const handler = messageHandlers[currentTab.value];

if (handler) {
handler(e);
}
});
};

option.transSocket?.addEventListener('message', handleSocketMessage);
} else {
initSocketEvent();
}
Expand All @@ -577,6 +580,11 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr
* 初始化事件总线相关事件
*/
const initMittBusEvents = () => {
mittBus.on('remove-event', () => {
// @ts-ignore
option.transSocket.removeEventListener('message', handleSocketMessage);
});

mittBus.on('terminal-search', ({ keyword, type = '' }) => {
searchKeyWord(keyword, type);
});
Expand Down
1 change: 1 addition & 0 deletions ui/src/utils/mittBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { customTreeOption } from '@/hooks/interface';
import { shareUser } from '@/views/interface';

type Event = {
'remove-event': void;
'alt-shift-right': void;
'alt-shift-left': void;
'open-setting': void;
Expand Down

0 comments on commit cc815b9

Please sign in to comment.