1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

fix: 解决系统分页错误问题

This commit is contained in:
ssongliu 2022-12-06 18:24:26 +08:00 committed by ssongliu
parent 41be181c7d
commit b1c2c4be83
13 changed files with 42 additions and 33 deletions

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -67,6 +68,9 @@ func (u *ContainerService) Page(req dto.PageContainer) (int64, interface{}, erro
if err != nil { if err != nil {
return 0, nil, err 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 total, start, end := len(list), (req.Page-1)*req.PageSize, req.Page*req.PageSize
if start > total { if start > total {
records = make([]types.Container, 0) records = make([]types.Container, 0)

View File

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"sort"
"strings" "strings"
"time" "time"
@ -96,6 +97,9 @@ func (u *ContainerService) PageCompose(req dto.PageInfo) (int64, interface{}, er
value.Name = key value.Name = key
records = append(records, value) 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 total, start, end := len(records), (req.Page-1)*req.PageSize, req.Page*req.PageSize
if start > total { if start > total {
BackDatas = make([]dto.ComposeInfo, 0) BackDatas = make([]dto.ComposeInfo, 0)

View File

@ -3,6 +3,7 @@ package service
import ( import (
"context" "context"
"fmt" "fmt"
"sort"
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/utils/docker" "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 data []dto.Network
records []types.NetworkResource 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 total, start, end := len(list), (req.Page-1)*req.PageSize, req.Page*req.PageSize
if start > total { if start > total {
records = make([]types.NetworkResource, 0) records = make([]types.NetworkResource, 0)

View File

@ -2,6 +2,7 @@ package service
import ( import (
"context" "context"
"sort"
"time" "time"
"github.com/1Panel-dev/1Panel/backend/app/dto" "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 data []dto.Volume
records []*types.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 total, start, end := len(list.Volumes), (req.Page-1)*req.PageSize, req.Page*req.PageSize
if start > total { if start > total {
records = make([]*types.Volume, 0) records = make([]*types.Volume, 0)

View File

@ -134,7 +134,7 @@ const acceptParams = (props: DialogProps): void => {
const data = ref(); const data = ref();
const selects = ref<any>([]); const selects = ref<any>([]);
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
@ -144,7 +144,7 @@ const loading = ref(false);
const search = async () => { const search = async () => {
let filterItem = filters.value; let filterItem = filters.value;
let params = { let params = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
filters: filterItem, filters: filterItem,
}; };

View File

@ -73,14 +73,14 @@ const loading = ref(false);
const isOnDetail = ref(false); const isOnDetail = ref(false);
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
const search = async () => { const search = async () => {
let params = { let params = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
}; };
loading.value = true; loading.value = true;

View File

@ -96,7 +96,7 @@ import i18n from '@/lang';
const data = ref(); const data = ref();
const selects = ref<any>([]); const selects = ref<any>([]);
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
@ -117,7 +117,7 @@ const dialogReNameRef = ref();
const search = async () => { const search = async () => {
let filterItem = props.filters ? props.filters : ''; let filterItem = props.filters ? props.filters : '';
let params = { let params = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
filters: filterItem, filters: filterItem,
}; };

View File

@ -100,7 +100,7 @@ const data = ref();
const repos = ref(); const repos = ref();
const selects = ref<any>([]); const selects = ref<any>([]);
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
@ -120,13 +120,11 @@ const deleteForm = reactive({
const search = async () => { const search = async () => {
const repoSearch = { const repoSearch = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
}; };
await searchImage(repoSearch).then((res) => { await searchImage(repoSearch).then((res) => {
if (res.data) { data.value = res.data.items || [];
data.value = res.data.items;
}
paginationConfig.total = res.data.total; paginationConfig.total = res.data.total;
}); });
}; };

View File

@ -68,7 +68,7 @@ const codemirror = ref();
const data = ref(); const data = ref();
const selects = ref<any>([]); const selects = ref<any>([]);
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
@ -88,16 +88,14 @@ function selectable(row) {
const search = async () => { const search = async () => {
const params = { const params = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
}; };
await searchNetwork(params).then((res) => { await searchNetwork(params).then((res) => {
if (res.data) { data.value = res.data.items || [];
data.value = res.data.items;
for (const item of data.value) { for (const item of data.value) {
item.isSystem = isSystem(item.name); item.isSystem = isSystem(item.name);
} }
}
paginationConfig.total = res.data.total; paginationConfig.total = res.data.total;
}); });
}; };

View File

@ -47,14 +47,14 @@ import i18n from '@/lang';
const data = ref(); const data = ref();
const selects = ref<any>([]); const selects = ref<any>([]);
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
const search = async () => { const search = async () => {
let params = { let params = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
}; };
await searchImageRepo(params).then((res) => { await searchImageRepo(params).then((res) => {

View File

@ -85,20 +85,19 @@ const detailInfo = ref();
const extensions = [javascript(), oneDark]; const extensions = [javascript(), oneDark];
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
const search = async () => { const search = async () => {
let params = { let params = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
}; };
await searchComposeTemplate(params).then((res) => { await searchComposeTemplate(params).then((res) => {
if (res.data) { data.value = res.data.items || [];
data.value = res.data.items; paginationConfig.total = res.data.total;
}
}); });
}; };

View File

@ -57,7 +57,7 @@ const codemirror = ref();
const data = ref(); const data = ref();
const selects = ref<any>([]); const selects = ref<any>([]);
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
@ -73,13 +73,11 @@ const onCreate = async () => {
const search = async () => { const search = async () => {
const params = { const params = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
}; };
await searchVolume(params).then((res) => { await searchVolume(params).then((res) => {
if (res.data) { data.value = res.data.items || [];
data.value = res.data.items;
}
paginationConfig.total = res.data.total; paginationConfig.total = res.data.total;
}); });
}; };

View File

@ -53,7 +53,7 @@ import { ElMessage } from 'element-plus';
const data = ref(); const data = ref();
const selects = ref<any>([]); const selects = ref<any>([]);
const paginationConfig = reactive({ const paginationConfig = reactive({
page: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
}); });
@ -139,12 +139,12 @@ const buttons = [
const search = async () => { const search = async () => {
let params = { let params = {
page: paginationConfig.page, page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize, pageSize: paginationConfig.pageSize,
info: info.value, info: info.value,
}; };
const res = await getCommandPage(params); const res = await getCommandPage(params);
data.value = res.data.items; data.value = res.data.items || [];
paginationConfig.total = res.data.total; paginationConfig.total = res.data.total;
}; };