fix: 终端SSH视图组件调整参数配置外部地址

This commit is contained in:
TsMask
2024-10-17 15:06:34 +08:00
parent 91af2bed92
commit 3e0529cf87

View File

@@ -13,6 +13,11 @@ const props = defineProps({
type: String, type: String,
required: true, required: true,
}, },
/**ws连接地址必传 如/ws/view */
url: {
type: String,
required: true,
},
/**网元类型,必传 */ /**网元类型,必传 */
neType: { neType: {
type: String, type: String,
@@ -33,6 +38,11 @@ const props = defineProps({
type: Number, type: Number,
default: 40, default: 40,
}, },
/**ws发送requestId前缀 如ssh_id */
prefix: {
type: String,
default: 'ssh',
},
}); });
/**终端输入DOM节点实例对象 */ /**终端输入DOM节点实例对象 */
@@ -148,13 +158,18 @@ function wsMessage(res: Record<string, any>) {
if (parts.length > 0) { if (parts.length > 0) {
let text = parts[parts.length - 1]; let text = parts[parts.length - 1];
// 找到最后输出标记 // 找到最后输出标记
const lestIndex = text.lastIndexOf('\u001b[?2004h\u001b]0;'); let lestIndex = text.lastIndexOf('\u001b[?2004h\u001b]0;');
if (lestIndex !== -1) { if (lestIndex !== -1) {
text = text.substring(0, lestIndex); text = text.substring(0, lestIndex);
} }
if (text === '' || text === '\r\n' || text.startsWith("^C\r\n") ) { if (text === '' || text === '\r\n' || text.startsWith('^C\r\n')) {
return; return;
} }
// 是否还有最后输出标记
lestIndex = text.lastIndexOf('\u001b[?2004h');
if (lestIndex !== -1) {
text = text.substring(0, lestIndex);
}
// console.log({ parts, text }); // console.log({ parts, text });
terminal.value.write(text); terminal.value.write(text);
return; return;
@@ -168,7 +183,7 @@ onMounted(() => {
if (props.neType && props.neId) { if (props.neType && props.neId) {
// 建立链接 // 建立链接
const options: OptionsType = { const options: OptionsType = {
url: '/ws/view', url: props.url,
params: { params: {
neType: props.neType, neType: props.neType,
neId: props.neId, neId: props.neId,
@@ -185,7 +200,7 @@ onMounted(() => {
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
ws.close(); if (ws.state() === WebSocket.OPEN) ws.close();
}); });
// 给组件设置属性 ref="xxxTerminal" // 给组件设置属性 ref="xxxTerminal"
@@ -200,7 +215,7 @@ defineExpose({
/**发送命令 */ /**发送命令 */
send: (type: string, data: Record<string, any>) => { send: (type: string, data: Record<string, any>) => {
ws.send({ ws.send({
requestId: `ssh_${props.id}`, requestId: `${props.prefix}_${props.id}`,
type, type,
data, data,
}); });
@@ -208,7 +223,7 @@ defineExpose({
/**模拟按下 Ctrl+C */ /**模拟按下 Ctrl+C */
ctrlC: () => { ctrlC: () => {
ws.send({ ws.send({
requestId: `ssh_${props.id}`, requestId: `${props.prefix}_${props.id}`,
type: 'ctrl-c', type: 'ctrl-c',
}); });
}, },