Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: Fixed command duplication issues #1543

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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