fix: Fix the problem of abnormal terminal connection (#8493)

This commit is contained in:
ssongliu 2025-04-27 23:21:45 +08:00 committed by GitHub
parent d025fc6abd
commit e75449f19d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 18 additions and 21 deletions

View file

@ -166,8 +166,7 @@ var InitSetting = &gormigrate.Migration{
var InitHost = &gormigrate.Migration{
ID: "20240816-init-host",
Migrate: func(tx *gorm.DB) error {
hostGroup := &model.Group{Name: "Default", Type: "host", IsDefault: true}
if err := global.DB.Create(hostGroup).Error; err != nil {
if err := tx.Create(&model.Group{Name: "Default", Type: "host", IsDefault: true}).Error; err != nil {
return err
}
if err := tx.Create(&model.Group{Name: "Default", Type: "node", IsDefault: true}).Error; err != nil {
@ -182,12 +181,6 @@ var InitHost = &gormigrate.Migration{
if err := tx.Create(&model.Group{Name: "Default", Type: "redis", IsDefault: true}).Error; err != nil {
return err
}
host := model.Host{
Name: "local", Addr: "127.0.0.1", User: "root", Port: 22, AuthMode: "password", GroupID: hostGroup.ID,
}
if err := tx.Create(&host).Error; err != nil {
return err
}
return nil
},
}

View file

@ -32,14 +32,14 @@ func NewCommand(script string) (*LocalCommand, error) {
} else {
cmd.Env = append(os.Environ(), "TERM=xterm")
}
cmd.Env = append(cmd.Env, "INIT_SCRIPT="+script)
cmd.Env = append(cmd.Env, "1PANEL_INIT_SCRIPT="+script)
pty, err := pty.Start(cmd)
if err != nil {
return nil, errors.Wrapf(err, "failed to start command")
}
if len(script) != 0 {
time.Sleep(100 * time.Millisecond)
_, _ = pty.Write([]byte("bash -c \"$INIT_SCRIPT\"\n"))
_, _ = pty.Write([]byte("bash -c \"$1PANEL_INIT_SCRIPT\"\n"))
}
lcmd := &LocalCommand{

View file

@ -8,7 +8,8 @@ import { Terminal } from '@xterm/xterm';
import '@xterm/xterm/css/xterm.css';
import { FitAddon } from '@xterm/addon-fit';
import { Base64 } from 'js-base64';
import { TerminalStore } from '@/store';
import { GlobalStore, TerminalStore } from '@/store';
const globalStore = GlobalStore();
const terminalElement = ref<HTMLDivElement | null>(null);
const fitAddon = new FitAddon();
@ -166,7 +167,7 @@ const initWebSocket = (endpoint_: string, args: string = '') => {
const host = href.split('//')[1].split('/')[0];
const endpoint = endpoint_.replace(/^\/+/, '');
terminalSocket.value = new WebSocket(
`${protocol}://${host}/${endpoint}?cols=${term.value.cols}&rows=${term.value.rows}&${args}`,
`${protocol}://${host}/${endpoint}?cols=${term.value.cols}&rows=${term.value.rows}&${args}&operateNode=${globalStore.currentNode}`,
);
terminalSocket.value.onopen = runRealTerminal;
terminalSocket.value.onmessage = onWSReceive;

View file

@ -277,8 +277,8 @@
</el-table-column>
<el-table-column
:label="$t('container.ip')"
:width="mobile ? 80 : 'auto'"
min-width="100"
:width="mobile ? 120 : 'auto'"
min-width="120"
prop="network"
>
<template #default="{ row }">

View file

@ -3,7 +3,7 @@
<LayoutContent v-loading="loading" :title="$t('logs.login')">
<template #leftToolBar>
<el-button type="primary" @click="onOpenDialog('create')">
{{ $t('commons.button.add') }}
{{ $t('commons.button.create') }}
</el-button>
<el-button type="primary" plain @click="onSync()">
{{ $t('commons.button.sync') }}
@ -244,7 +244,9 @@ const buttons = [
let item = deepCopy(row) as Cronjob.ScriptInfo;
item.id = 0;
item.name += '-' + getCurrentDateFormatted();
onOpenDialog('create', item);
item.groupList = row.groupList || [];
item.groupBelong = row.groupBelong || [];
onOpenDialog('clone', item);
},
},
{

View file

@ -3,7 +3,7 @@
v-model="drawerVisible"
:header="title"
@close="handleClose"
:resource="dialogData.title === 'create' ? '' : dialogData.rowData?.name"
:resource="dialogData.title !== 'edit' ? '' : dialogData.rowData?.name"
size="large"
>
<el-form ref="formRef" v-loading="loading" label-position="top" :model="dialogData.rowData" :rules="rules">
@ -64,7 +64,7 @@ const groupOptions = ref();
const acceptParams = (params: DialogProps): void => {
dialogData.value = params;
title.value = i18n.global.t('cronjob.library.' + dialogData.value.title);
title.value = i18n.global.t('commons.button.' + dialogData.value.title);
loadGroupOptions();
drawerVisible.value = true;
};
@ -87,9 +87,10 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
formEl.validate(async (valid) => {
if (!valid) return;
loading.value = true;
dialogData.value.rowData.groupList = dialogData.value.rowData.groupList || [];
dialogData.value.rowData.groups = dialogData.value.rowData.groupList.join(',');
if (dialogData.value.title === 'create') {
if (dialogData.value.rowData.groupList.length !== 0) {
dialogData.value.rowData.groups = dialogData.value.rowData.groupList?.join(',');
}
if (dialogData.value.title === 'create' || dialogData.value.title === 'clone') {
await addScript(dialogData.value.rowData)
.then(() => {
loading.value = false;