fix: 修复后台列表分页交互

This commit is contained in:
Nixevol
2026-07-03 05:09:32 +08:00
parent 5c564e9f24
commit 80cdcaddea
10 changed files with 90 additions and 23 deletions
+4 -2
View File
@@ -71,14 +71,16 @@
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
:pagination="false"
class="table-fill"
flex-height
paginate-single-page
remote
:row-key="(r) => r.id"
v-model:checked-row-keys="checkedKeys"
/>
<div class="table-pagination">
<n-pagination v-bind="pagination" :disabled="loading" />
</div>
<n-modal v-model:show="genModal" preset="card" :title="t('pages.traceCode.generate')" style="width: 440px">
<n-form :model="genForm" label-placement="top">
+34 -6
View File
@@ -4,19 +4,30 @@ import type { PaginationProps } from 'naive-ui';
import { useI18n } from 'vue-i18n';
export const TABLE_PAGE_SIZE_ALL = Number.MAX_SAFE_INTEGER;
const TABLE_PAGE_SIZE_CUSTOM = Number.MAX_SAFE_INTEGER - 1;
export function useTablePage(load: () => void | Promise<void>, initialPageSize = 20) {
const { t, locale } = useI18n();
const showCustomPageSize = ref(false);
const customPageSize = ref<number | null>(null);
const appliedCustomPageSize = ref<number | null>(null);
function pageSizeOptions() {
return [
const options = [
{ label: t('common.pagination.perPage', { n: 20 }), value: 20 },
{ label: t('common.pagination.perPage', { n: 50 }), value: 50 },
{ label: t('common.pagination.perPage', { n: 100 }), value: 100 },
{ label: t('common.pagination.perPage', { n: 200 }), value: 200 },
{ label: t('common.pagination.unlimited'), value: TABLE_PAGE_SIZE_ALL },
{ label: t('common.pagination.customPageSize'), value: TABLE_PAGE_SIZE_CUSTOM },
];
if (appliedCustomPageSize.value && !options.some((item) => item.value === appliedCustomPageSize.value)) {
options.splice(options.length - 1, 0, {
label: t('common.pagination.perPage', { n: appliedCustomPageSize.value }),
value: appliedCustomPageSize.value,
});
}
return options;
}
const pagination = reactive<PaginationProps>({
@@ -27,8 +38,9 @@ export function useTablePage(load: () => void | Promise<void>, initialPageSize =
showQuickJumper: true,
pageSizes: pageSizeOptions(),
displayOrder: ['pages', 'size-picker', 'quick-jumper'],
suffix: () =>
h('span', { class: 'table-pagination-extra' }, [
suffix: () => {
if (!showCustomPageSize.value) return null;
return h('span', { class: 'table-pagination-extra' }, [
h(NInputNumber, {
value: customPageSize.value,
min: 1,
@@ -53,12 +65,20 @@ export function useTablePage(load: () => void | Promise<void>, initialPageSize =
},
{ default: () => t('common.pagination.apply') },
),
]),
]);
},
onUpdatePage: (page: number) => {
pagination.page = page;
void load();
},
onUpdatePageSize: (pageSize: number) => {
if (pageSize === TABLE_PAGE_SIZE_CUSTOM) {
showCustomPageSize.value = true;
customPageSize.value = appliedCustomPageSize.value || 20;
pagination.pageSize = appliedCustomPageSize.value || initialPageSize;
return;
}
showCustomPageSize.value = false;
pagination.page = 1;
pagination.pageSize = pageSize;
void load();
@@ -75,13 +95,21 @@ export function useTablePage(load: () => void | Promise<void>, initialPageSize =
function setPageResult(result: { total: number; page: number; pageSize: number }) {
pagination.itemCount = result.total;
pagination.page = result.page;
pagination.pageSize = result.pageSize === 0 ? TABLE_PAGE_SIZE_ALL : result.pageSize;
const nextPageSize = result.pageSize === 0 ? TABLE_PAGE_SIZE_ALL : result.pageSize;
if (nextPageSize !== TABLE_PAGE_SIZE_ALL && ![20, 50, 100, 200].includes(nextPageSize)) {
appliedCustomPageSize.value = nextPageSize;
pagination.pageSizes = pageSizeOptions();
}
pagination.pageSize = nextPageSize;
}
function applyCustomPageSize(value: number | null) {
if (!value || value < 1) return;
appliedCustomPageSize.value = Math.floor(value);
pagination.pageSizes = pageSizeOptions();
showCustomPageSize.value = false;
pagination.page = 1;
pagination.pageSize = Math.floor(value);
pagination.pageSize = appliedCustomPageSize.value;
customPageSize.value = null;
void load();
}
+20 -2
View File
@@ -21,7 +21,8 @@ body,
min-height: 100%;
}
.page.table-page {
height: 100%;
height: calc(100vh - 56px);
max-height: calc(100vh - 56px);
display: flex;
flex-direction: column;
overflow: hidden;
@@ -37,12 +38,29 @@ body,
flex: 1 1 auto;
}
.table-fill {
flex: 1 1 auto;
flex: 1 1 0;
height: 0;
min-height: 0;
}
.table-fill .n-data-table-wrapper {
flex: 1 1 auto;
min-height: 0;
}
.table-fill .n-data-table-base-table {
min-height: 0;
}
.table-fill .n-data-table-base-table-body {
flex: 1 1 auto !important;
min-height: 0;
}
.table-pagination {
flex: 0 0 auto;
display: flex;
justify-content: flex-end;
align-items: center;
padding-top: 12px;
overflow-x: auto;
}
.table-pagination-extra {
display: inline-flex;
align-items: center;
+11 -2
View File
@@ -26,7 +26,9 @@
</n-card>
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false" class="table-card">
<trace-code-panel :artwork-id="artworkId" />
<div class="trace-table-wrap">
<trace-code-panel :artwork-id="artworkId" />
</div>
</n-card>
</div>
</template>
@@ -73,7 +75,7 @@ onMounted(loadArtwork);
display: flex;
flex-direction: column;
}
.table-card :deep(.n-card__content) {
.table-card :deep(.n-card-content) {
flex: 1 1 auto;
min-height: 0;
display: flex;
@@ -85,4 +87,11 @@ onMounted(loadArtwork);
gap: 10px;
min-width: 0;
}
.trace-table-wrap {
flex: 1 1 auto;
height: 100%;
min-height: 0;
display: flex;
flex-direction: column;
}
</style>
+4 -2
View File
@@ -31,13 +31,15 @@
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
:pagination="false"
class="table-fill"
flex-height
paginate-single-page
remote
:row-key="(r) => r.id"
/>
<div class="table-pagination">
<n-pagination v-bind="pagination" :disabled="loading" />
</div>
</div>
</template>
+4 -2
View File
@@ -26,13 +26,15 @@
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
:pagination="false"
class="table-fill"
flex-height
paginate-single-page
remote
:row-key="(r) => r.id"
/>
<div class="table-pagination">
<n-pagination v-bind="pagination" :disabled="loading" />
</div>
<n-modal v-model:show="rejectModal" preset="card" :title="t('pages.audit.reject')" style="width: 420px">
<n-form label-placement="top">
+4 -2
View File
@@ -47,13 +47,15 @@
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
:pagination="false"
class="table-fill"
flex-height
paginate-single-page
remote
:row-key="(r) => r.id"
/>
<div class="table-pagination">
<n-pagination v-bind="pagination" :disabled="loading" />
</div>
</div>
</template>
+4 -2
View File
@@ -23,13 +23,15 @@
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
:pagination="false"
class="table-fill"
flex-height
paginate-single-page
remote
:row-key="(r) => r.id"
/>
<div class="table-pagination">
<n-pagination v-bind="pagination" :disabled="loading" />
</div>
<n-modal
v-model:show="showModal"
+4 -2
View File
@@ -17,13 +17,15 @@
:columns="columns"
:data="rows"
:loading="loading"
:pagination="pagination"
:pagination="false"
class="table-fill"
flex-height
paginate-single-page
remote
:row-key="(r) => r.id"
/>
<div class="table-pagination">
<n-pagination v-bind="pagination" :disabled="loading" />
</div>
<n-modal v-model:show="showModal" preset="card" :title="editing ? t('pages.user.edit') : t('pages.user.create')" style="width: 460px">
<n-form ref="formRef" :model="form" :rules="rules" label-placement="top">