From b1c2c4be839eb4bc1eff0856af717ddd9ee24abd Mon Sep 17 00:00:00 2001 From: ssongliu Date: Tue, 6 Dec 2022 18:24:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/container.go | 4 ++++ backend/app/service/container_compose.go | 4 ++++ backend/app/service/container_network.go | 4 ++++ backend/app/service/container_volume.go | 4 ++++ .../src/views/container/compose/detail/index.vue | 4 ++-- frontend/src/views/container/compose/index.vue | 4 ++-- frontend/src/views/container/container/index.vue | 4 ++-- frontend/src/views/container/image/index.vue | 8 +++----- frontend/src/views/container/network/index.vue | 12 +++++------- frontend/src/views/container/repo/index.vue | 4 ++-- frontend/src/views/container/template/index.vue | 9 ++++----- frontend/src/views/container/volume/index.vue | 8 +++----- frontend/src/views/host/terminal/command/index.vue | 6 +++--- 13 files changed, 42 insertions(+), 33 deletions(-) diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 0c311566b..9bdfd9b2b 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "io/ioutil" + "sort" "strconv" "strings" "time" @@ -67,6 +68,9 @@ func (u *ContainerService) Page(req dto.PageContainer) (int64, interface{}, erro if err != nil { return 0, nil, err } + sort.Slice(list, func(i, j int) bool { + return list[i].Created > list[j].Created + }) total, start, end := len(list), (req.Page-1)*req.PageSize, req.Page*req.PageSize if start > total { records = make([]types.Container, 0) diff --git a/backend/app/service/container_compose.go b/backend/app/service/container_compose.go index 6d904c37a..49aa6d92a 100644 --- a/backend/app/service/container_compose.go +++ b/backend/app/service/container_compose.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "sort" "strings" "time" @@ -96,6 +97,9 @@ func (u *ContainerService) PageCompose(req dto.PageInfo) (int64, interface{}, er value.Name = key records = append(records, value) } + sort.Slice(records, func(i, j int) bool { + return records[i].CreatedAt > records[j].CreatedAt + }) total, start, end := len(records), (req.Page-1)*req.PageSize, req.Page*req.PageSize if start > total { BackDatas = make([]dto.ComposeInfo, 0) diff --git a/backend/app/service/container_network.go b/backend/app/service/container_network.go index 67396813e..b008c65c2 100644 --- a/backend/app/service/container_network.go +++ b/backend/app/service/container_network.go @@ -3,6 +3,7 @@ package service import ( "context" "fmt" + "sort" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/utils/docker" @@ -23,6 +24,9 @@ func (u *ContainerService) PageNetwork(req dto.PageInfo) (int64, interface{}, er data []dto.Network records []types.NetworkResource ) + sort.Slice(list, func(i, j int) bool { + return list[i].Created.Before(list[j].Created) + }) total, start, end := len(list), (req.Page-1)*req.PageSize, req.Page*req.PageSize if start > total { records = make([]types.NetworkResource, 0) diff --git a/backend/app/service/container_volume.go b/backend/app/service/container_volume.go index e1a569dbf..8bdca1431 100644 --- a/backend/app/service/container_volume.go +++ b/backend/app/service/container_volume.go @@ -2,6 +2,7 @@ package service import ( "context" + "sort" "time" "github.com/1Panel-dev/1Panel/backend/app/dto" @@ -24,6 +25,9 @@ func (u *ContainerService) PageVolume(req dto.PageInfo) (int64, interface{}, err data []dto.Volume records []*types.Volume ) + sort.Slice(list.Volumes, func(i, j int) bool { + return list.Volumes[i].CreatedAt > list.Volumes[j].CreatedAt + }) total, start, end := len(list.Volumes), (req.Page-1)*req.PageSize, req.Page*req.PageSize if start > total { records = make([]*types.Volume, 0) diff --git a/frontend/src/views/container/compose/detail/index.vue b/frontend/src/views/container/compose/detail/index.vue index cb0aecc6e..d850e8b38 100644 --- a/frontend/src/views/container/compose/detail/index.vue +++ b/frontend/src/views/container/compose/detail/index.vue @@ -134,7 +134,7 @@ const acceptParams = (props: DialogProps): void => { const data = ref(); const selects = ref([]); const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); @@ -144,7 +144,7 @@ const loading = ref(false); const search = async () => { let filterItem = filters.value; let params = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, filters: filterItem, }; diff --git a/frontend/src/views/container/compose/index.vue b/frontend/src/views/container/compose/index.vue index f2ef0028e..2e975e718 100644 --- a/frontend/src/views/container/compose/index.vue +++ b/frontend/src/views/container/compose/index.vue @@ -73,14 +73,14 @@ const loading = ref(false); const isOnDetail = ref(false); const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); const search = async () => { let params = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, }; loading.value = true; diff --git a/frontend/src/views/container/container/index.vue b/frontend/src/views/container/container/index.vue index bb6114030..a3a11d35c 100644 --- a/frontend/src/views/container/container/index.vue +++ b/frontend/src/views/container/container/index.vue @@ -96,7 +96,7 @@ import i18n from '@/lang'; const data = ref(); const selects = ref([]); const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); @@ -117,7 +117,7 @@ const dialogReNameRef = ref(); const search = async () => { let filterItem = props.filters ? props.filters : ''; let params = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, filters: filterItem, }; diff --git a/frontend/src/views/container/image/index.vue b/frontend/src/views/container/image/index.vue index e2e8bd6c4..26a2306c2 100644 --- a/frontend/src/views/container/image/index.vue +++ b/frontend/src/views/container/image/index.vue @@ -100,7 +100,7 @@ const data = ref(); const repos = ref(); const selects = ref([]); const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); @@ -120,13 +120,11 @@ const deleteForm = reactive({ const search = async () => { const repoSearch = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, }; await searchImage(repoSearch).then((res) => { - if (res.data) { - data.value = res.data.items; - } + data.value = res.data.items || []; paginationConfig.total = res.data.total; }); }; diff --git a/frontend/src/views/container/network/index.vue b/frontend/src/views/container/network/index.vue index d0de6d571..6e9305650 100644 --- a/frontend/src/views/container/network/index.vue +++ b/frontend/src/views/container/network/index.vue @@ -68,7 +68,7 @@ const codemirror = ref(); const data = ref(); const selects = ref([]); const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); @@ -88,15 +88,13 @@ function selectable(row) { const search = async () => { const params = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, }; await searchNetwork(params).then((res) => { - if (res.data) { - data.value = res.data.items; - for (const item of data.value) { - item.isSystem = isSystem(item.name); - } + data.value = res.data.items || []; + for (const item of data.value) { + item.isSystem = isSystem(item.name); } paginationConfig.total = res.data.total; }); diff --git a/frontend/src/views/container/repo/index.vue b/frontend/src/views/container/repo/index.vue index 6fb327688..d94974dea 100644 --- a/frontend/src/views/container/repo/index.vue +++ b/frontend/src/views/container/repo/index.vue @@ -47,14 +47,14 @@ import i18n from '@/lang'; const data = ref(); const selects = ref([]); const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); const search = async () => { let params = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, }; await searchImageRepo(params).then((res) => { diff --git a/frontend/src/views/container/template/index.vue b/frontend/src/views/container/template/index.vue index b19c2a5f2..c51e07959 100644 --- a/frontend/src/views/container/template/index.vue +++ b/frontend/src/views/container/template/index.vue @@ -85,20 +85,19 @@ const detailInfo = ref(); const extensions = [javascript(), oneDark]; const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); const search = async () => { let params = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, }; await searchComposeTemplate(params).then((res) => { - if (res.data) { - data.value = res.data.items; - } + data.value = res.data.items || []; + paginationConfig.total = res.data.total; }); }; diff --git a/frontend/src/views/container/volume/index.vue b/frontend/src/views/container/volume/index.vue index 3bdd9d5e8..d7e9dd57d 100644 --- a/frontend/src/views/container/volume/index.vue +++ b/frontend/src/views/container/volume/index.vue @@ -57,7 +57,7 @@ const codemirror = ref(); const data = ref(); const selects = ref([]); const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); @@ -73,13 +73,11 @@ const onCreate = async () => { const search = async () => { const params = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, }; await searchVolume(params).then((res) => { - if (res.data) { - data.value = res.data.items; - } + data.value = res.data.items || []; paginationConfig.total = res.data.total; }); }; diff --git a/frontend/src/views/host/terminal/command/index.vue b/frontend/src/views/host/terminal/command/index.vue index f8cdb0e15..75b49bec2 100644 --- a/frontend/src/views/host/terminal/command/index.vue +++ b/frontend/src/views/host/terminal/command/index.vue @@ -53,7 +53,7 @@ import { ElMessage } from 'element-plus'; const data = ref(); const selects = ref([]); const paginationConfig = reactive({ - page: 1, + currentPage: 1, pageSize: 10, total: 0, }); @@ -139,12 +139,12 @@ const buttons = [ const search = async () => { let params = { - page: paginationConfig.page, + page: paginationConfig.currentPage, pageSize: paginationConfig.pageSize, info: info.value, }; const res = await getCommandPage(params); - data.value = res.data.items; + data.value = res.data.items || []; paginationConfig.total = res.data.total; };