feat: 优化后台列表高度与分页容量
This commit is contained in:
@@ -72,10 +72,12 @@
|
||||
:data="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
class="table-fill"
|
||||
flex-height
|
||||
paginate-single-page
|
||||
remote
|
||||
:row-key="(r) => r.id"
|
||||
v-model:checked-row-keys="checkedKeys"
|
||||
@update:page="onPage"
|
||||
/>
|
||||
|
||||
<n-modal v-model:show="genModal" preset="card" :title="t('pages.traceCode.generate')" style="width: 440px">
|
||||
@@ -153,6 +155,7 @@ import { useAuthStore } from '@/stores/auth';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { downloadFile } from '@/utils/download';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
|
||||
const props = defineProps<{
|
||||
artworkId?: number;
|
||||
@@ -175,18 +178,14 @@ const query = reactive<{
|
||||
batchId: number | null;
|
||||
status: string | null;
|
||||
keyword: string;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}>({
|
||||
artworkId: fixedArtworkId.value,
|
||||
groupId: null,
|
||||
batchId: null,
|
||||
status: null,
|
||||
keyword: '',
|
||||
page: 1,
|
||||
pageSize: embedded.value ? 8 : 10,
|
||||
});
|
||||
const pagination = reactive({ page: 1, pageSize: query.pageSize, itemCount: 0 });
|
||||
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load, embedded.value ? 20 : 20);
|
||||
const statusOptions = Object.values(TraceCodeStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
||||
|
||||
const batchOptions = ref<{ label: string; value: number }[]>([]);
|
||||
@@ -290,24 +289,18 @@ async function load() {
|
||||
batchId: query.batchId || undefined,
|
||||
status: query.status || undefined,
|
||||
keyword: query.keyword || undefined,
|
||||
page: query.page,
|
||||
pageSize: query.pageSize,
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
});
|
||||
rows.value = res.list;
|
||||
pagination.itemCount = res.total;
|
||||
pagination.page = res.page;
|
||||
setPageResult(res);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
query.page = 1;
|
||||
load();
|
||||
}
|
||||
|
||||
function onPage(p: number) {
|
||||
query.page = p;
|
||||
resetPage();
|
||||
load();
|
||||
}
|
||||
|
||||
@@ -452,7 +445,7 @@ watch(
|
||||
query.artworkId = aid;
|
||||
genForm.artworkId = aid;
|
||||
query.batchId = null;
|
||||
query.page = 1;
|
||||
resetPage();
|
||||
await loadBatches();
|
||||
await load();
|
||||
},
|
||||
@@ -474,6 +467,10 @@ onMounted(async () => {
|
||||
<style scoped>
|
||||
.trace-code-panel {
|
||||
min-width: 0;
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.panel-toolbar {
|
||||
display: flex;
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { computed, h, reactive, ref, watch } from 'vue';
|
||||
import { NButton, NInputNumber } from 'naive-ui';
|
||||
import type { PaginationProps } from 'naive-ui';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
export const TABLE_PAGE_SIZE_ALL = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
export function useTablePage(load: () => void | Promise<void>, initialPageSize = 20) {
|
||||
const { t, locale } = useI18n();
|
||||
const customPageSize = ref<number | null>(null);
|
||||
|
||||
function pageSizeOptions() {
|
||||
return [
|
||||
{ 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 },
|
||||
];
|
||||
}
|
||||
|
||||
const pagination = reactive<PaginationProps>({
|
||||
page: 1,
|
||||
pageSize: initialPageSize,
|
||||
itemCount: 0,
|
||||
showSizePicker: true,
|
||||
showQuickJumper: true,
|
||||
pageSizes: pageSizeOptions(),
|
||||
displayOrder: ['pages', 'size-picker', 'quick-jumper'],
|
||||
suffix: () =>
|
||||
h('span', { class: 'table-pagination-extra' }, [
|
||||
h(NInputNumber, {
|
||||
value: customPageSize.value,
|
||||
min: 1,
|
||||
precision: 0,
|
||||
size: 'small',
|
||||
placeholder: t('common.pagination.customPageSize'),
|
||||
style: 'width: 116px',
|
||||
showButton: false,
|
||||
onUpdateValue: (value: number | null) => {
|
||||
customPageSize.value = value;
|
||||
},
|
||||
onKeyup: (event: KeyboardEvent) => {
|
||||
if (event.key === 'Enter') applyCustomPageSize(customPageSize.value);
|
||||
},
|
||||
}),
|
||||
h(
|
||||
NButton,
|
||||
{
|
||||
size: 'small',
|
||||
disabled: !customPageSize.value || customPageSize.value < 1,
|
||||
onClick: () => applyCustomPageSize(customPageSize.value),
|
||||
},
|
||||
{ default: () => t('common.pagination.apply') },
|
||||
),
|
||||
]),
|
||||
onUpdatePage: (page: number) => {
|
||||
pagination.page = page;
|
||||
void load();
|
||||
},
|
||||
onUpdatePageSize: (pageSize: number) => {
|
||||
pagination.page = 1;
|
||||
pagination.pageSize = pageSize;
|
||||
void load();
|
||||
},
|
||||
});
|
||||
|
||||
const page = computed(() => pagination.page || 1);
|
||||
const pageSize = computed(() => ((pagination.pageSize ?? initialPageSize) === TABLE_PAGE_SIZE_ALL ? 0 : (pagination.pageSize ?? initialPageSize)));
|
||||
|
||||
function resetPage() {
|
||||
pagination.page = 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function applyCustomPageSize(value: number | null) {
|
||||
if (!value || value < 1) return;
|
||||
pagination.page = 1;
|
||||
pagination.pageSize = Math.floor(value);
|
||||
customPageSize.value = null;
|
||||
void load();
|
||||
}
|
||||
|
||||
watch(locale, () => {
|
||||
pagination.pageSizes = pageSizeOptions();
|
||||
});
|
||||
|
||||
return { pagination, page, pageSize, resetPage, setPageResult, applyCustomPageSize };
|
||||
}
|
||||
@@ -74,6 +74,12 @@
|
||||
"DISABLED": "Disabled",
|
||||
"ABNORMAL": "Abnormal"
|
||||
},
|
||||
"pagination": {
|
||||
"perPage": "{n} / page",
|
||||
"unlimited": "Unlimited",
|
||||
"customPageSize": "Custom size",
|
||||
"apply": "Apply"
|
||||
},
|
||||
"auditStatus": {
|
||||
"PENDING": "Pending",
|
||||
"APPROVED": "Approved",
|
||||
|
||||
@@ -74,6 +74,12 @@
|
||||
"DISABLED": "停用",
|
||||
"ABNORMAL": "异常"
|
||||
},
|
||||
"pagination": {
|
||||
"perPage": "{n} / 页",
|
||||
"unlimited": "不限制",
|
||||
"customPageSize": "自定义条数",
|
||||
"apply": "应用"
|
||||
},
|
||||
"auditStatus": {
|
||||
"PENDING": "待审核",
|
||||
"APPROVED": "已通过",
|
||||
|
||||
@@ -18,6 +18,13 @@ body,
|
||||
}
|
||||
.page {
|
||||
padding: 16px;
|
||||
min-height: 100%;
|
||||
}
|
||||
.page.table-page {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
.page-toolbar {
|
||||
display: flex;
|
||||
@@ -29,6 +36,19 @@ body,
|
||||
.page-toolbar .spacer {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
.table-fill {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
}
|
||||
.table-fill .n-data-table-wrapper {
|
||||
min-height: 0;
|
||||
}
|
||||
.table-pagination-extra {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.text-ellipsis {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="page table-page">
|
||||
<div class="page-toolbar">
|
||||
<n-button quaternary @click="router.back()">
|
||||
<template #icon><n-icon :component="ArrowBackOutline" /></template>
|
||||
@@ -25,7 +25,7 @@
|
||||
</n-descriptions>
|
||||
</n-card>
|
||||
|
||||
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false">
|
||||
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false" class="table-card">
|
||||
<trace-code-panel :artwork-id="artworkId" />
|
||||
</n-card>
|
||||
</div>
|
||||
@@ -65,6 +65,19 @@ onMounted(loadArtwork);
|
||||
}
|
||||
.summary-card {
|
||||
margin-bottom: 16px;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
.table-card {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.table-card :deep(.n-card__content) {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.summary-title {
|
||||
display: flex;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="page table-page">
|
||||
<div class="page-toolbar">
|
||||
<n-input
|
||||
v-model:value="query.keyword"
|
||||
@@ -32,9 +32,11 @@
|
||||
:data="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
class="table-fill"
|
||||
flex-height
|
||||
paginate-single-page
|
||||
remote
|
||||
:row-key="(r) => r.id"
|
||||
@update:page="onPage"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -49,6 +51,7 @@ import { ArtworkStatus } from '@artveris/shared';
|
||||
import { artworkApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
@@ -56,13 +59,11 @@ const auth = useAuthStore();
|
||||
|
||||
const rows = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const query = reactive<{ keyword: string; status: string | null; page: number; pageSize: number }>({
|
||||
const query = reactive<{ keyword: string; status: string | null }>({
|
||||
keyword: '',
|
||||
status: null,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
|
||||
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load);
|
||||
const statusOptions = Object.values(ArtworkStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
||||
|
||||
const columns: DataTableColumns<any> = [
|
||||
@@ -137,22 +138,17 @@ async function load() {
|
||||
const res: any = await artworkApi.list({
|
||||
keyword: query.keyword,
|
||||
status: query.status || undefined,
|
||||
page: query.page,
|
||||
pageSize: query.pageSize,
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
});
|
||||
rows.value = res.list;
|
||||
pagination.itemCount = res.total;
|
||||
pagination.page = res.page;
|
||||
setPageResult(res);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
function onSearch() {
|
||||
query.page = 1;
|
||||
load();
|
||||
}
|
||||
function onPage(p: number) {
|
||||
query.page = p;
|
||||
resetPage();
|
||||
load();
|
||||
}
|
||||
function goCreate() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="page table-page">
|
||||
<div class="page-toolbar">
|
||||
<n-input
|
||||
v-model:value="query.keyword"
|
||||
@@ -27,9 +27,11 @@
|
||||
:data="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
class="table-fill"
|
||||
flex-height
|
||||
paginate-single-page
|
||||
remote
|
||||
:row-key="(r) => r.id"
|
||||
@update:page="onPage"
|
||||
/>
|
||||
|
||||
<n-modal v-model:show="rejectModal" preset="card" :title="t('pages.audit.reject')" style="width: 420px">
|
||||
@@ -58,6 +60,7 @@ import { AuditStatus } from '@artveris/shared';
|
||||
import { auditApi } from '@/api';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt } from '@/utils/format';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
@@ -65,13 +68,11 @@ const router = useRouter();
|
||||
const rows = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const acting = ref(false);
|
||||
const query = reactive<{ keyword: string; auditStatus: string | null; page: number; pageSize: number }>({
|
||||
const query = reactive<{ keyword: string; auditStatus: string | null }>({
|
||||
keyword: '',
|
||||
auditStatus: AuditStatus.PENDING,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
|
||||
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load);
|
||||
const auditStatusOptions = Object.values(AuditStatus).map((v) => ({ label: t(`common.auditStatus.${v}`), value: v }));
|
||||
|
||||
function auditTagType(s: string) {
|
||||
@@ -121,22 +122,17 @@ async function load() {
|
||||
const res: any = await auditApi.list({
|
||||
keyword: query.keyword || undefined,
|
||||
auditStatus: query.auditStatus || undefined,
|
||||
page: query.page,
|
||||
pageSize: query.pageSize,
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
});
|
||||
rows.value = res.list;
|
||||
pagination.itemCount = res.total;
|
||||
pagination.page = res.page;
|
||||
setPageResult(res);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
function onSearch() {
|
||||
query.page = 1;
|
||||
load();
|
||||
}
|
||||
function onPage(p: number) {
|
||||
query.page = p;
|
||||
resetPage();
|
||||
load();
|
||||
}
|
||||
function approve(r: any) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="page table-page">
|
||||
<div class="page-toolbar">
|
||||
<n-input
|
||||
v-model:value="query.keyword"
|
||||
@@ -48,9 +48,11 @@
|
||||
:data="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
class="table-fill"
|
||||
flex-height
|
||||
paginate-single-page
|
||||
remote
|
||||
:row-key="(r) => r.id"
|
||||
@update:page="onPage"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -64,20 +66,19 @@ import dayjs from 'dayjs';
|
||||
import { QueryResult } from '@artveris/shared';
|
||||
import { queryLogApi } from '@/api';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
|
||||
const { t } = useI18n();
|
||||
const rows = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const range = ref<[number, number] | null>(null);
|
||||
const query = reactive<{ keyword: string; archiveNo: string; batchNo: string; result: string | null; startTime?: string; endTime?: string; page: number; pageSize: number }>({
|
||||
const query = reactive<{ keyword: string; archiveNo: string; batchNo: string; result: string | null; startTime?: string; endTime?: string }>({
|
||||
keyword: '',
|
||||
archiveNo: '',
|
||||
batchNo: '',
|
||||
result: null,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
|
||||
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load);
|
||||
const resultOptions = Object.values(QueryResult).map((v) => ({ label: t(`common.queryResult.${v}`), value: v }));
|
||||
|
||||
const columns: DataTableColumns<any> = [
|
||||
@@ -117,12 +118,11 @@ async function load() {
|
||||
result: query.result || undefined,
|
||||
startTime: query.startTime,
|
||||
endTime: query.endTime,
|
||||
page: query.page,
|
||||
pageSize: query.pageSize,
|
||||
page: page.value,
|
||||
pageSize: pageSize.value,
|
||||
});
|
||||
rows.value = res.list;
|
||||
pagination.itemCount = res.total;
|
||||
pagination.page = res.page;
|
||||
setPageResult(res);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
@@ -138,11 +138,7 @@ function onRange(val: [number, number] | null) {
|
||||
onSearch();
|
||||
}
|
||||
function onSearch() {
|
||||
query.page = 1;
|
||||
load();
|
||||
}
|
||||
function onPage(p: number) {
|
||||
query.page = p;
|
||||
resetPage();
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="page table-page">
|
||||
<div class="page-toolbar">
|
||||
<n-input
|
||||
v-model:value="query.keyword"
|
||||
:placeholder="t('common.label.keyword')"
|
||||
clearable
|
||||
style="width: 220px"
|
||||
@keyup.enter="load"
|
||||
@keyup.enter="onSearch"
|
||||
/>
|
||||
<n-button type="primary" @click="load">
|
||||
<n-button type="primary" @click="onSearch">
|
||||
<template #icon><n-icon :component="SearchOutline" /></template>
|
||||
{{ t('common.action.search') }}
|
||||
</n-button>
|
||||
@@ -24,9 +24,11 @@
|
||||
:data="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
class="table-fill"
|
||||
flex-height
|
||||
paginate-single-page
|
||||
remote
|
||||
:row-key="(r) => r.id"
|
||||
@update:page="onPage"
|
||||
/>
|
||||
|
||||
<n-modal
|
||||
@@ -104,14 +106,15 @@ import { templateApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
|
||||
const { t } = useI18n();
|
||||
const auth = useAuthStore();
|
||||
|
||||
const rows = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const query = reactive({ keyword: '', page: 1, pageSize: 10 });
|
||||
const pagination = reactive({ page: 1, pageCount: 1, pageSize: 10, itemCount: 0 });
|
||||
const query = reactive({ keyword: '' });
|
||||
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load);
|
||||
|
||||
const fieldTypeOptions = Object.values(FieldType).map((v) => ({ label: t(`common.fieldType.${v}`), value: v }));
|
||||
|
||||
@@ -182,17 +185,15 @@ async function toggleStatus(r: any) {
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res: any = await templateApi.list({ keyword: query.keyword, page: query.page, pageSize: query.pageSize });
|
||||
const res: any = await templateApi.list({ keyword: query.keyword, page: page.value, pageSize: pageSize.value });
|
||||
rows.value = res.list;
|
||||
pagination.itemCount = res.total;
|
||||
pagination.page = res.page;
|
||||
pagination.pageSize = res.pageSize;
|
||||
setPageResult(res);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
function onPage(p: number) {
|
||||
query.page = p;
|
||||
function onSearch() {
|
||||
resetPage();
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="page table-page">
|
||||
<div class="page-toolbar">
|
||||
<n-input v-model:value="query.keyword" :placeholder="t('common.label.keyword')" clearable style="width: 200px" @keyup.enter="onSearch" />
|
||||
<n-button type="primary" @click="onSearch">
|
||||
@@ -13,7 +13,17 @@
|
||||
</n-button>
|
||||
</div>
|
||||
|
||||
<n-data-table :columns="columns" :data="rows" :loading="loading" :pagination="pagination" remote :row-key="(r) => r.id" @update:page="onPage" />
|
||||
<n-data-table
|
||||
:columns="columns"
|
||||
:data="rows"
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
class="table-fill"
|
||||
flex-height
|
||||
paginate-single-page
|
||||
remote
|
||||
:row-key="(r) => r.id"
|
||||
/>
|
||||
|
||||
<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">
|
||||
@@ -62,12 +72,13 @@ import { RoleType, UserStatus } from '@artveris/shared';
|
||||
import { userApi } from '@/api';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
|
||||
const { t } = useI18n();
|
||||
const rows = ref<any[]>([]);
|
||||
const loading = ref(false);
|
||||
const query = reactive({ keyword: '', page: 1, pageSize: 10 });
|
||||
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
|
||||
const query = reactive({ keyword: '' });
|
||||
const { pagination, page, pageSize, resetPage, setPageResult } = useTablePage(load);
|
||||
const roleOptions = Object.values(RoleType).map((v) => ({ label: t(`common.role.${v}`), value: v }));
|
||||
const statusOptions = Object.values(UserStatus).map((v) => ({ label: t(`common.status.${v}`), value: v }));
|
||||
|
||||
@@ -113,20 +124,15 @@ const columns: DataTableColumns<any> = [
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res: any = await userApi.list({ keyword: query.keyword, page: query.page, pageSize: query.pageSize });
|
||||
const res: any = await userApi.list({ keyword: query.keyword, page: page.value, pageSize: pageSize.value });
|
||||
rows.value = res.list;
|
||||
pagination.itemCount = res.total;
|
||||
pagination.page = res.page;
|
||||
setPageResult(res);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
function onSearch() {
|
||||
query.page = 1;
|
||||
load();
|
||||
}
|
||||
function onPage(p: number) {
|
||||
query.page = p;
|
||||
resetPage();
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsInt, IsOptional, Max, Min } from 'class-validator';
|
||||
import { IsInt, IsOptional, Min } from 'class-validator';
|
||||
|
||||
export class PaginationDto {
|
||||
@ApiPropertyOptional({ description: '页码,从 1 开始', default: 1 })
|
||||
@@ -14,15 +14,15 @@ export class PaginationDto {
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
@Max(200)
|
||||
pageSize = 10;
|
||||
@Min(0)
|
||||
pageSize = 20;
|
||||
|
||||
get skip(): number {
|
||||
return (this.page - 1) * this.pageSize;
|
||||
}
|
||||
|
||||
get take(): number {
|
||||
get take(): number | undefined {
|
||||
if (this.pageSize === 0) return undefined;
|
||||
return this.pageSize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PageResult } from '@artveris/shared';
|
||||
|
||||
export function buildPage<T>(list: T[], total: number, page: number, pageSize: number): PageResult<T> {
|
||||
return { list, total, page, pageSize };
|
||||
return { list, total, page: pageSize === 0 ? 1 : page, pageSize };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user