Skip to content

Commit

Permalink
fixed:Fixed connection timeout shareable issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoJiSen committed Aug 28, 2024
1 parent 7bdd243 commit b4cd25d
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions ui/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ declare module 'vue' {
NList: typeof import('naive-ui')['NList']
NListItem: typeof import('naive-ui')['NListItem']
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NNotificationProvider: typeof import('naive-ui')['NNotificationProvider']
NPopover: typeof import('naive-ui')['NPopover']
NResult: typeof import('naive-ui')['NResult']
NScrollbar: typeof import('naive-ui')['NScrollbar']
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"serve": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview",
Expand Down
8 changes: 5 additions & 3 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<template>
<n-config-provider :theme="darkTheme" :locale="zhCN" :date-locale="dateZhCN">
<n-dialog-provider>
<n-message-provider>
<router-view v-if="i18nLoaded" />
</n-message-provider>
<n-notification-provider>
<n-message-provider>
<router-view v-if="i18nLoaded" />
</n-message-provider>
</n-notification-provider>
</n-dialog-provider>
</n-config-provider>
<n-float-button :right="20" :bottom="20" shape="circle">
Expand Down
11 changes: 8 additions & 3 deletions ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import CustomTerminal from '@/components/CustomTerminal/index.vue';
// import TabSuffix from '@/components/Kubernetes/MainContent/components/TabSuffix/index.vue';
// 引入 type
import { NMessageProvider, TabPaneProps, useDialog } from 'naive-ui';
import { NMessageProvider, TabPaneProps, useDialog, useNotification } from 'naive-ui';
import type { Ref } from 'vue';
import type { ISettingProp, shareUser } from '@/views/interface';
Expand All @@ -90,6 +90,8 @@ const treeStore = useTreeStore();
const { t } = useI18n();
const dialog = useDialog();
const notification = useNotification();
const paramsStore = useParamsStore();
const terminalStore = useTerminalStore();
Expand Down Expand Up @@ -268,8 +270,11 @@ const onSocketData = (msgType: string, msg: any, terminal: Terminal) => {
break;
}
case 'CLOSE': {
sessionId.value = '';
message.error(t('TerminalClosed'));
enableShare.value = false;
notification.error({
content: t('TerminalClosed'),
duration: 50000
});
break;
}
default:
Expand Down
4 changes: 2 additions & 2 deletions ui/src/hooks/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ export const generateWsURL = () => {
export const onWebsocketWrong = (event: Event, type: string, terminal?: Terminal) => {
switch (type) {
case 'error': {
terminal ? terminal.write('Connection Websocket Error') : message.error('Error');
terminal ? terminal.write('Connection Websocket Error') : '';
break;
}
case 'disconnected': {
terminal ? terminal.write('Connection Websocket Closed') : message.error('Disconnected');
terminal ? terminal.write('Connection Websocket Closed') : '';
break;
}
}
Expand Down
2 changes: 0 additions & 2 deletions ui/src/hooks/useK8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ export const useK8s = () => {
}
case 'CLOSE':
case 'ERROR': {
message.error('Receive Connection Closed');

socket.close();
break;
}
Expand Down
2 changes: 0 additions & 2 deletions ui/src/hooks/useTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr
break;
}
case 'CLOSE': {
terminal?.writeln('Receive Connection closed');
socket.close();
sendEventToLuna('CLOSE', '');
break;
Expand Down Expand Up @@ -273,7 +272,6 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr
break;
}
case 'TERMINAL_ERROR': {
message.error(`Socket Error ${socketData.err}`);
terminal?.write(socketData.err);
break;
}
Expand Down
11 changes: 8 additions & 3 deletions ui/src/views/Connection/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useTerminalStore } from '@/store/modules/terminal.ts';
import { Terminal } from '@xterm/xterm';
import { storeToRefs } from 'pinia';
import { useNotification } from 'naive-ui';
import { NMessageProvider } from 'naive-ui';
import { computed, h, markRaw, nextTick, reactive, ref } from 'vue';
Expand Down Expand Up @@ -50,6 +51,7 @@ const { setting } = storeToRefs(paramsStore);
const dialog = useDialog();
const message = useMessage();
const notification = useNotification();
const terminalType = ref<string>('common');
const sessionId = ref<string>('');
Expand Down Expand Up @@ -237,9 +239,12 @@ const onSocketData = (msgType: string, msg: any, terminal: Terminal) => {
message.info(`${data.user} ${t('ResumeSession')}`);
break;
}
case 'ClOSE': {
sessionId.value = '';
message.error(t('TerminalClosed'));
case 'CLOSE': {
enableShare.value = false;
notification.error({
content: t('TerminalClosed'),
duration: 50000
});
break;
}
default:
Expand Down

0 comments on commit b4cd25d

Please sign in to comment.