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 an issue where users would be displayed even when disconnected #1490

Merged
merged 1 commit into from
Sep 13, 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
35 changes: 21 additions & 14 deletions ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,7 @@ import Settings from '@/components/Settings/index.vue';
import ThemeConfig from '@/components/ThemeConfig/index.vue';
import CustomTerminal from '@/components/CustomTerminal/index.vue';

import {
DropdownOption,
NIcon,
NMessageProvider,
TabPaneProps,
useDialog,
useMessage,
useNotification
} from 'naive-ui';
import { DropdownOption, NIcon, NMessageProvider, TabPaneProps, useDialog, useMessage } from 'naive-ui';
import type { ISettingProp, shareUser } from '@/views/interface';
import type { customTreeOption } from '@/hooks/interface';

Expand All @@ -126,7 +118,6 @@ const props = defineProps<{

const { t } = useI18n();
const dialog = useDialog();
const notification = useNotification();

const treeStore = useTreeStore();
const paramsStore = useParamsStore();
Expand All @@ -139,6 +130,7 @@ const el = ref();

const dropdownY = ref(0);
const dropdownX = ref(0);
const deleteUserCounter = ref(0);
const nameRef = ref('');
const sessionId = ref('');
const waterMarkContent = ref('');
Expand Down Expand Up @@ -547,11 +539,25 @@ const onSocketData = (msgType: string, msg: any, terminal: Terminal) => {
}
case 'CLOSE': {
enableShare.value = false;
break;
}
case 'K8S_CLOSE': {
enableShare.value = false;

deleteUserCounter.value--;

// 用于删除根用户
if (deleteUserCounter.value === 0) {
for (const key in onlineUsersMap) {
delete onlineUsersMap[key];
}
}

// 用于删除分享的用户
if (onlineUsersMap.hasOwnProperty(msg.id)) {
delete onlineUsersMap[msg.id];
}

notification.error({
content: t('WebSocketClosed'),
duration: 50000
});
break;
}
default:
Expand Down Expand Up @@ -746,6 +752,7 @@ onMounted(() => {

nameRef.value = key;
terminalStore.setTerminalConfig('currentTab', key);
deleteUserCounter.value++;
});
});

Expand Down
26 changes: 19 additions & 7 deletions ui/src/views/Connection/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { useLogger } from '@/hooks/useLogger.ts';
import { useDialog, useMessage, useNotification } from 'naive-ui';
import { useDialog, useMessage } from 'naive-ui';
import { useParamsStore } from '@/store/modules/params.ts';
import { useTerminalStore } from '@/store/modules/terminal.ts';

Expand Down Expand Up @@ -51,11 +51,10 @@ const { setting } = storeToRefs(paramsStore);

const dialog = useDialog();
const message = useMessage();
const notification = useNotification();

const terminalType = ref<string>('common');
const sessionId = ref<string>('');
const themeName = ref<string>('Default');
const terminalType = ref<string>('common');
const enableShare = ref<boolean>(false);
const userOptions = ref<shareUser[]>([]);

Expand Down Expand Up @@ -148,11 +147,22 @@ const settings = computed((): ISettingProp[] => {
];
});

/**
* 重置分享连接表单
*/
const resetShareDialog = () => {
paramsStore.setShareId('');
paramsStore.setShareCode('');
dialog.destroyAll();
};

/**
* 抛出到外层的 Socket message 事件处理
*
* @param msgType
* @param msg
* @param terminal
*/
const onSocketData = (msgType: string, msg: any, terminal: Terminal) => {
switch (msgType) {
case 'TERMINAL_SESSION': {
Expand Down Expand Up @@ -245,10 +255,11 @@ const onSocketData = (msgType: string, msg: any, terminal: Terminal) => {
case 'CLOSE': {
enableShare.value = false;

notification.error({
content: t('WebSocketClosed'),
duration: 50000
});
// 用于删除分享的用户
if (onlineUsersMap.hasOwnProperty(msg.id)) {
delete onlineUsersMap[msg.id];
}

break;
}
default:
Expand All @@ -257,6 +268,7 @@ const onSocketData = (msgType: string, msg: any, terminal: Terminal) => {

debug('On WebSocket Data:', msg);
};

const onEvent = (event: string, data: any) => {
switch (event) {
case 'reconnect':
Expand Down
Loading