feat: 优化后台列表高度与分页容量

This commit is contained in:
Nixevol
2026-07-03 04:45:01 +08:00
parent 0e817c453e
commit 5c564e9f24
14 changed files with 227 additions and 94 deletions
+18 -12
View File
@@ -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();
}