From fb24a699e69ee2a8c788946dd90fdaf450308e71 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 16 Oct 2025 14:29:40 +0800 Subject: [PATCH] fix: Fix the issue of abnormal refresh after container creation/editing (#10657) --- agent/app/dto/container.go | 1 - agent/app/service/container.go | 9 +--- frontend/src/api/interface/container.ts | 1 - .../src/layout/components/Sidebar/index.vue | 1 - .../src/views/container/container/index.vue | 6 +-- .../container/container/operate/index.vue | 54 ++++++++++--------- .../host/file-management/terminal/index.vue | 2 +- .../website/runtime/php/create/index.vue | 1 - 8 files changed, 34 insertions(+), 41 deletions(-) diff --git a/agent/app/dto/container.go b/agent/app/dto/container.go index d6e00a2a2..dfa950080 100644 --- a/agent/app/dto/container.go +++ b/agent/app/dto/container.go @@ -71,7 +71,6 @@ type ResourceLimit struct { type ContainerOperate struct { TaskID string `json:"taskID"` - ContainerID string `json:"containerID"` ForcePull bool `json:"forcePull"` Name string `json:"name" validate:"required"` Image string `json:"image" validate:"required"` diff --git a/agent/app/service/container.go b/agent/app/service/container.go index ff46f8846..3c8f33f33 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -640,7 +640,6 @@ func (u *ContainerService) ContainerInfo(req dto.OperationWithName) (*dto.Contai } var data dto.ContainerOperate - data.ContainerID = oldContainer.ID data.Name = strings.ReplaceAll(oldContainer.Name, "/", "") data.Image = oldContainer.Config.Image if oldContainer.NetworkSettings != nil { @@ -702,11 +701,7 @@ func (u *ContainerService) ContainerUpdate(req dto.ContainerOperate) error { } defer client.Close() ctx := context.Background() - newContainer, _ := client.ContainerInspect(ctx, req.Name) - if newContainer.ContainerJSONBase != nil && newContainer.ID != req.ContainerID { - return buserr.New("ErrContainerName") - } - oldContainer, err := client.ContainerInspect(ctx, req.ContainerID) + oldContainer, err := client.ContainerInspect(ctx, req.Name) if err != nil { return err } @@ -730,7 +725,7 @@ func (u *ContainerService) ContainerUpdate(req dto.ContainerOperate) error { }, nil) taskItem.AddSubTask(i18n.GetWithName("ContainerCreate", req.Name), func(t *task.Task) error { - err := client.ContainerRemove(ctx, req.ContainerID, container.RemoveOptions{Force: true}) + err := client.ContainerRemove(ctx, req.Name, container.RemoveOptions{Force: true}) taskItem.LogWithStatus(i18n.GetWithName("ContainerRemoveOld", req.Name), err) if err != nil { return err diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index ee84e69fb..76c05989b 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -55,7 +55,6 @@ export namespace Container { } export interface ContainerHelper { taskID: string; - containerID: string; name: string; image: string; imageInput: boolean; diff --git a/frontend/src/layout/components/Sidebar/index.vue b/frontend/src/layout/components/Sidebar/index.vue index 8594e4b59..b62560a97 100644 --- a/frontend/src/layout/components/Sidebar/index.vue +++ b/frontend/src/layout/components/Sidebar/index.vue @@ -54,7 +54,6 @@ const isCollapse = computed((): boolean => menuStore.isCollapse); let routerMenus = computed((): RouteRecordRaw[] => { const aa = menuStore.menuList.filter((route) => route.meta && !route.meta.hideInSidebar) as RouteRecordRaw[]; - console.log(aa); return aa; }); diff --git a/frontend/src/views/container/container/index.vue b/frontend/src/views/container/container/index.vue index 9a4ba233a..0adbd24c4 100644 --- a/frontend/src/views/container/container/index.vue +++ b/frontend/src/views/container/container/index.vue @@ -594,8 +594,8 @@ function loadMemValue(t: number) { return Number((t / Math.pow(num, 3)).toFixed(2)); } -const onContainerOperate = async (containerID: string) => { - routerToNameWithQuery('ContainerCreate', { containerID: containerID }); +const onContainerOperate = async (container: string) => { + routerToNameWithQuery('ContainerCreate', { name: container }); }; const dialogMonitorRef = ref(); @@ -701,7 +701,7 @@ const buttons = [ { label: i18n.global.t('commons.button.edit'), click: (row: Container.ContainerInfo) => { - onContainerOperate(row.containerID); + onContainerOperate(row.name); }, }, { diff --git a/frontend/src/views/container/container/operate/index.vue b/frontend/src/views/container/container/operate/index.vue index 587db17f1..c852e75cf 100644 --- a/frontend/src/views/container/container/operate/index.vue +++ b/frontend/src/views/container/container/operate/index.vue @@ -28,7 +28,7 @@ ({ taskID: '', - containerID: '', name: '', image: '', imageInput: false, @@ -431,7 +430,7 @@ const form = reactive({ const search = async () => { if (!isCreate.value) { loading.value = true; - await loadContainerInfo(form.containerID) + await loadContainerInfo(form.name) .then((res) => { loading.value = false; form.name = res.data.name; @@ -520,6 +519,7 @@ const goBack = () => { }; const closeTask = () => { taskLogRef.value.handleClose(); + checkExist(); }; const dialogTerminalRef = ref(); const toTerminal = () => { @@ -621,7 +621,6 @@ const submit = async () => { openTaskLog(form.taskID); }) .catch(() => { - updateContainerID(); loading.value = false; }); } @@ -631,24 +630,6 @@ const openTaskLog = (taskID: string) => { taskLogRef.value.openWithTaskID(taskID); }; -const updateContainerID = async () => { - let params = { - page: 1, - pageSize: 1, - state: 'all', - name: form.name, - filters: '', - orderBy: 'createdAt', - order: 'null', - }; - await searchContainer(params).then((res) => { - if (res.data.items?.length === 1) { - form.containerID = res.data.items[0].containerID; - return; - } - }); -}; - const checkPortValid = () => { if (form.exposedPorts.length === 0) { return true; @@ -727,10 +708,31 @@ const splitStringIgnoringQuotes = (input) => { return result; }; +const checkExist = async () => { + let params = { + page: 1, + pageSize: 1, + state: 'all', + name: form.name, + filters: '', + orderBy: 'createdAt', + order: 'null', + }; + await searchContainer(params).then((res) => { + if (res.data.items?.length === 1) { + isCreate.value = false; + routerToNameWithQuery('ContainerCreate', { name: form.name, t: Date.now() }); + return; + } else { + isCreate.value = true; + } + }); +}; + onMounted(() => { - if (router.currentRoute.value.query.containerID) { + if (router.currentRoute.value.query.name) { isCreate.value = false; - form.containerID = String(router.currentRoute.value.query.containerID); + form.name = String(router.currentRoute.value.query.name); } else { isCreate.value = true; } diff --git a/frontend/src/views/host/file-management/terminal/index.vue b/frontend/src/views/host/file-management/terminal/index.vue index ed75a880c..0bcc11c21 100644 --- a/frontend/src/views/host/file-management/terminal/index.vue +++ b/frontend/src/views/host/file-management/terminal/index.vue @@ -9,7 +9,7 @@ >