diff --git a/ui/src/components/Kubernetes/MainContent/index.vue b/ui/src/components/Kubernetes/MainContent/index.vue index 0c67c23f..5e09d280 100644 --- a/ui/src/components/Kubernetes/MainContent/index.vue +++ b/ui/src/components/Kubernetes/MainContent/index.vue @@ -652,6 +652,8 @@ const handleClose = (name: string) => { panels.value.splice(index, 1); + treeStore.removeK8sIdMap(name); + const panelLength = panels.value.length; if (panelLength >= 1) { diff --git a/ui/src/hooks/useK8s.ts b/ui/src/hooks/useK8s.ts index 1da8ffc3..51681866 100644 --- a/ui/src/hooks/useK8s.ts +++ b/ui/src/hooks/useK8s.ts @@ -7,7 +7,7 @@ import { ref, h } from 'vue'; import { storeToRefs } from 'pinia'; import { useLogger } from './useLogger.ts'; import { useWebSocket } from '@vueuse/core'; -import { createDiscreteApi } from 'naive-ui'; +import { createDiscreteApi, darkTheme } from 'naive-ui'; import { useTreeStore } from '@/store/modules/tree.ts'; import { useParamsStore } from '@/store/modules/params.ts'; import { generateWsURL, onWebsocketOpen, onWebsocketWrong } from './helper'; @@ -17,7 +17,11 @@ import type { Ref } from 'vue'; import { customTreeOption, IContainer, IPods } from '@/hooks/interface'; const { debug } = useLogger('K8s'); -const { message } = createDiscreteApi(['message']); +const { message, notification } = createDiscreteApi(['message', 'notification'], { + configProviderProps: { + theme: darkTheme + } +}); export const useK8s = () => { const treeStore = useTreeStore(); @@ -168,6 +172,14 @@ export const useK8s = () => { * 二次处理节点 */ const filterSyncNodes = (msg: any) => { + if (msg.err) { + treeStore.setTreeNodes({} as customTreeOption); + return notification.error({ + content: msg.err, + duration: 100000 + }); + } + const data = JSON.parse(msg.data as string); if (Object.keys(data).length === 0) { diff --git a/ui/src/hooks/useTerminal.ts b/ui/src/hooks/useTerminal.ts index c96123dd..109aafe9 100644 --- a/ui/src/hooks/useTerminal.ts +++ b/ui/src/hooks/useTerminal.ts @@ -547,7 +547,11 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr const { currentTab } = storeToRefs(useTerminalStore()); - treeStore.setK8sIdMap(currentNode.value.k8s_id!, { terminal, socket, ...currentNode.value }); + treeStore.setK8sIdMap(currentNode.value.k8s_id!, { + terminal, + socket, + ...currentNode.value + }); messageHandlers = { [currentTab.value]: (e: MessageEvent) => { @@ -558,6 +562,7 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr option.transSocket?.addEventListener('message', (e: MessageEvent) => { // @ts-ignore const handler = messageHandlers[currentTab.value as string]; + if (handler) { handler(e); }