Skip to content

Commit

Permalink
Merge pull request #1443 from jumpserver/pr@dev@fix_connect
Browse files Browse the repository at this point in the history
fixed:Fixed the issue that the Terminal cannot be typed after connecting
  • Loading branch information
feng626 authored Aug 29, 2024
2 parents 07990f5 + eee5a6d commit bc87f46
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 121 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM jumpserver/koko-base:20240828_091135 AS stage-build
FROM jumpserver/koko-base:20240829_082809 AS stage-build
WORKDIR /opt/koko
ARG TARGETARCH
COPY . .
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"devDependencies": {
"@types/node": "^20.14.11",
"@vicons/carbon": "^0.12.0",
"@vicons/fluent": "^0.12.0",
"@vicons/ionicons5": "^0.12.0",
"@vitejs/plugin-vue": "^5.0.5",
Expand Down
29 changes: 26 additions & 3 deletions ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<!-- <TabSuffix />-->
</template>
</n-tabs>
<Tip v-if="panels.length === 0" />
<!-- <Tip v-if="panels.length === 0" />-->
</n-layout>
<Settings :settings="settings" />
</template>
Expand All @@ -56,7 +56,7 @@ import {
import xtermTheme from 'xterm-theme';
import mittBus from '@/utils/mittBus.ts';
import Tip from './components/Tip/index.vue';
// import Tip from './components/Tip/index.vue';
import Share from '@/components/Share/index.vue';
import Settings from '@/components/Settings/index.vue';
import ThemeConfig from '@/components/ThemeConfig/index.vue';
Expand All @@ -76,6 +76,7 @@ import { useLogger } from '@/hooks/useLogger.ts';
import { useTreeStore } from '@/store/modules/tree.ts';
import { useParamsStore } from '@/store/modules/params.ts';
import { useTerminalStore } from '@/store/modules/terminal.ts';
import { customTreeOption } from '@/hooks/interface';
const message = useMessage();
const { debug } = useLogger('K8s-CustomTerminal');
Expand All @@ -94,7 +95,7 @@ const paramsStore = useParamsStore();
const terminalStore = useTerminalStore();
const { setting } = storeToRefs(paramsStore);
const { connectInfo } = storeToRefs(treeStore);
const { connectInfo, treeNodes } = storeToRefs(treeStore);
const nameRef = ref('');
const sessionId = ref('');
Expand Down Expand Up @@ -288,9 +289,29 @@ const handleClose = (name: string) => {
panels.value.splice(index, 1);
};
const findNodeById = (id: string): void => {
const searchNode = (nodes: customTreeOption[]) => {
for (const node of nodes) {
if (node.id === id) {
treeStore.setCurrentNode(node);
return true;
}
if (node.children && node.children.length > 0) {
const found = searchNode(node.children);
if (found) return true;
}
}
return false;
};
searchNode(treeNodes.value);
};
const handleChangeTab = (value: string) => {
nameRef.value = value;
findNodeById(value);
terminalStore.setTerminalConfig('currentTab', nameRef.value);
};
Expand All @@ -311,6 +332,8 @@ onMounted(() => {
tab: currentNode.label
});
treeStore.setCurrentNode(currentNode);
const sendTerminalData = () => {
if (terminalRef.value) {
setTimeout(() => {
Expand Down
18 changes: 11 additions & 7 deletions ui/src/components/Kubernetes/Tree/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,23 @@ const handleFilter = (option: TreeOption) => {
};
const handleOnLoad = (node: TreeOption) => {
let expendKey: string;
treeStore.setCurrentNode(node);
emits('sync-load-node', node);
if (!expandedKeysRef.value.includes(node.key as string)) {
setTimeout(() => {
expandedKeysRef.value.push(node.key as string);
}, 300);
if (typeof node.key === 'string') {
expendKey = node.key;
if (!expandedKeysRef.value.includes(expendKey)) {
setTimeout(() => {
expandedKeysRef.value.push(expendKey);
}, 300);
}
}
return new Promise<boolean>(resolve => {
resolve(false);
});
return false;
};
const handleSelect = (key: string, _option: DropdownOption) => {
Expand Down
7 changes: 0 additions & 7 deletions ui/src/components/Share/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ watch(
}
);
watch(
() => shareId.value,
value => {
console.log(value);
}
);
const copyShareURL = () => {
if (!shareId.value) return;
if (!props.enableShare) return;
Expand Down
61 changes: 32 additions & 29 deletions ui/src/hooks/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,52 +171,55 @@ export const handleTerminalOnData = (
socket: WebSocket
) => {
const terminalStore = useTerminalStore();

const { enableZmodem, zmodemStatus } = storeToRefs(terminalStore);

// 如果未开启 Zmodem 且当前在 Zmodem 状态,不允许输入
if (!enableZmodem.value && zmodemStatus.value) {
return message.warning('未开启 Zmodem 且当前在 Zmodem 状态,不允许输入');
}

data = preprocessInput(data, config);

const eventType = type === 'k8s' ? 'TERMINAL_K8S_DATA' : 'TERMINAL_DATA';

// 如果类型是 k8s,处理 k8s 的逻辑
if (type === 'k8s') {
const treeStore = useTreeStore();
const { currentNode } = storeToRefs(treeStore);
const node = currentNode.value;

// 获取默认的消息体
const messageData = {
data: data,
id: terminalId,
type: eventType,
pod: '',
k8s_id: node.k8s_id,
namespace: '',
container: ''
};

if (currentNode.value.children) {
const currentItem = currentNode.value.children[0];

return socket.send(
JSON.stringify({
data: data,
id: terminalId,
type: eventType,
pod: currentItem.pod,
k8s_id: currentItem.k8s_id,
namespace: currentItem.namespace,
container: currentItem.container
})
);
} else {
return socket.send(
JSON.stringify({
data: data,
id: terminalId,
type: eventType,
pod: '',
k8s_id: currentNode.value.k8s_id,
namespace: '',
container: ''
})
);
// 如果有子节点并且是父节点的处理
if (node.children && node.isParent) {
return socket.send(JSON.stringify(messageData));
}

// 如果有子节点但不是父节点,取第一个子节点的信息
if (node.children && node.children.length > 0) {
const currentItem = node.children[0];
Object.assign(messageData, {
pod: currentItem.pod,
k8s_id: currentItem.k8s_id,
namespace: currentItem.namespace,
container: currentItem.container
});
}

// 发送消息
return socket.send(JSON.stringify(messageData));
}

// 处理非 k8s 的情况
sendEventToLuna('KEYBOARDEVENT', '');

socket.send(formatMessage(terminalId, eventType, data));
};

Expand Down
Loading

0 comments on commit bc87f46

Please sign in to comment.