From 5a0c50b9a2f4c004ea6a35f2bddb633b4d9f08b2 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 2 Sep 2025 17:48:10 +0800 Subject: [PATCH] style: Optimize volume list display (#10231) Refs #6601 --- agent/app/dto/container.go | 16 +++-- agent/app/service/container_volume.go | 48 ++++++++++----- frontend/src/views/container/volume/index.vue | 59 ++++++++++++++++--- 3 files changed, 93 insertions(+), 30 deletions(-) diff --git a/agent/app/dto/container.go b/agent/app/dto/container.go index 69dbc9de9..b69295ca6 100644 --- a/agent/app/dto/container.go +++ b/agent/app/dto/container.go @@ -209,11 +209,12 @@ type NetworkCreate struct { } type Volume struct { - Name string `json:"name"` - Labels []string `json:"labels"` - Driver string `json:"driver"` - Mountpoint string `json:"mountpoint"` - CreatedAt time.Time `json:"createdAt"` + Name string `json:"name"` + Labels []VolumeOption `json:"labels"` + Driver string `json:"driver"` + Mountpoint string `json:"mountpoint"` + CreatedAt time.Time `json:"createdAt"` + Options []VolumeOption `json:"options"` } type VolumeCreate struct { Name string `json:"name" validate:"required"` @@ -221,7 +222,10 @@ type VolumeCreate struct { Options []string `json:"options"` Labels []string `json:"labels"` } - +type VolumeOption struct { + Key string `json:"key"` + Value string `json:"value"` +} type BatchDelete struct { TaskID string `json:"taskID"` Force bool `json:"force"` diff --git a/agent/app/service/container_volume.go b/agent/app/service/container_volume.go index e9fcf389c..0443361dc 100644 --- a/agent/app/service/container_volume.go +++ b/agent/app/service/container_volume.go @@ -5,6 +5,7 @@ import ( "sort" "strings" "time" + "unicode" "github.com/1Panel-dev/1Panel/agent/app/dto" "github.com/1Panel-dev/1Panel/agent/buserr" @@ -53,25 +54,27 @@ func (u *ContainerService) PageVolume(req dto.SearchWithPage) (int64, interface{ nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd()) for _, item := range records { - tag := make([]string, 0) - for _, val := range item.Labels { - tag = append(tag, val) + var volume dto.Volume + volume.Driver = item.Driver + volume.Mountpoint = item.Mountpoint + volume.Name = simplifyVolumeName(item.Name) + for key, val := range item.Labels { + volume.Labels = append(volume.Labels, dto.VolumeOption{Key: key, Value: val}) } - var createTime time.Time - if strings.Contains(item.CreatedAt, "Z") { - createTime, _ = time.ParseInLocation("2006-01-02T15:04:05Z", item.CreatedAt, nyc) - } else if strings.Contains(item.CreatedAt, "+") { - createTime, _ = time.ParseInLocation("2006-01-02T15:04:05+08:00", item.CreatedAt, nyc) - } else { - createTime, _ = time.ParseInLocation("2006-01-02T15:04:05", item.CreatedAt, nyc) + for key, val := range item.Options { + volume.Options = append(volume.Options, dto.VolumeOption{Key: key, Value: val}) } - data = append(data, dto.Volume{ - CreatedAt: createTime, - Name: item.Name, - Driver: item.Driver, - Mountpoint: item.Mountpoint, - Labels: tag, + sort.Slice(volume.Options, func(i, j int) bool { + return volume.Options[i].Key < volume.Options[j].Key }) + if strings.Contains(item.CreatedAt, "Z") { + volume.CreatedAt, _ = time.ParseInLocation("2006-01-02T15:04:05Z", item.CreatedAt, nyc) + } else if strings.Contains(item.CreatedAt, "+") { + volume.CreatedAt, _ = time.ParseInLocation("2006-01-02T15:04:05+08:00", item.CreatedAt, nyc) + } else { + volume.CreatedAt, _ = time.ParseInLocation("2006-01-02T15:04:05", item.CreatedAt, nyc) + } + data = append(data, volume) } return int64(total), data, nil @@ -140,3 +143,16 @@ func (u *ContainerService) CreateVolume(req dto.VolumeCreate) error { } return nil } + +func simplifyVolumeName(name string) string { + if len(name) != 64 { + return name + } + + for _, char := range name { + if !unicode.Is(unicode.ASCII_Hex_Digit, char) { + return name + } + } + return name[:12] +} diff --git a/frontend/src/views/container/volume/index.vue b/frontend/src/views/container/volume/index.vue index ed982a488..0b99175f5 100644 --- a/frontend/src/views/container/volume/index.vue +++ b/frontend/src/views/container/volume/index.vue @@ -47,15 +47,35 @@ - + + > + + { taskLogRef.value.openWithTaskID(taskID); }; +const jumpTo = async (path: any) => { + await checkFile(path, false).then((res) => { + if (res.data) { + routerToFileWithPath(path); + } else { + MsgError(i18n.global.t('file.noSuchFile')); + } + }); +}; + const batchDelete = async (row: Container.VolumeInfo | null) => { let names = []; if (row) {