分页100
This commit is contained in:
parent
6de7cbbff2
commit
e65f57f387
@ -12,6 +12,7 @@ import {
|
|||||||
DatePicker,
|
DatePicker,
|
||||||
Input,
|
Input,
|
||||||
message,
|
message,
|
||||||
|
Pagination,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Table,
|
Table,
|
||||||
@ -52,6 +53,7 @@ const sysOriginOptions = computed(() => {
|
|||||||
return options.length > 0 ? options : getAllowedSysOrigins([]);
|
return options.length > 0 ? options : getAllowedSysOrigins([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const DEFAULT_PAGE_SIZE = 100;
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const loadMoreLoading = ref(false);
|
const loadMoreLoading = ref(false);
|
||||||
const list = ref<Array<Record<string, any>>>([]);
|
const list = ref<Array<Record<string, any>>>([]);
|
||||||
@ -59,12 +61,13 @@ const notMore = ref(false);
|
|||||||
const originKeyword = ref('');
|
const originKeyword = ref('');
|
||||||
const sysOrigins = ref<string[]>([]);
|
const sysOrigins = ref<string[]>([]);
|
||||||
const rangeDate = ref<[string, string] | null>(null);
|
const rangeDate = ref<[string, string] | null>(null);
|
||||||
|
const currentPage = ref(1);
|
||||||
|
|
||||||
const query = reactive<Record<string, any>>({
|
const query = reactive<Record<string, any>>({
|
||||||
context: '',
|
context: '',
|
||||||
endTime: '',
|
endTime: '',
|
||||||
id: '',
|
id: '',
|
||||||
limit: 20,
|
limit: DEFAULT_PAGE_SIZE,
|
||||||
origin: '',
|
origin: '',
|
||||||
startTime: '',
|
startTime: '',
|
||||||
sysOrigin: '',
|
sysOrigin: '',
|
||||||
@ -98,6 +101,20 @@ const originOptions = computed(() => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const currentPageList = computed(() => {
|
||||||
|
const pageSize = Number(query.limit || DEFAULT_PAGE_SIZE);
|
||||||
|
const startIndex = (currentPage.value - 1) * pageSize;
|
||||||
|
return list.value.slice(startIndex, startIndex + pageSize);
|
||||||
|
});
|
||||||
|
|
||||||
|
const paginationTotal = computed(() => {
|
||||||
|
const pageSize = Number(query.limit || DEFAULT_PAGE_SIZE);
|
||||||
|
if (notMore.value) {
|
||||||
|
return list.value.length;
|
||||||
|
}
|
||||||
|
return Math.max(list.value.length + pageSize, (currentPage.value + 1) * pageSize);
|
||||||
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
rangeDate,
|
rangeDate,
|
||||||
(value) => {
|
(value) => {
|
||||||
@ -185,6 +202,7 @@ async function loadData(reset = false) {
|
|||||||
list.value = [];
|
list.value = [];
|
||||||
notMore.value = false;
|
notMore.value = false;
|
||||||
query.context = '';
|
query.context = '';
|
||||||
|
currentPage.value = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
normalizeOriginValue();
|
normalizeOriginValue();
|
||||||
@ -204,15 +222,39 @@ async function loadData(reset = false) {
|
|||||||
const waters = result?.waters || [];
|
const waters = result?.waters || [];
|
||||||
list.value = reset ? waters : [...list.value, ...waters];
|
list.value = reset ? waters : [...list.value, ...waters];
|
||||||
query.context = result?.context || '';
|
query.context = result?.context || '';
|
||||||
notMore.value = Boolean(result?.listOver);
|
notMore.value = Boolean(result?.listOver) || !query.context;
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
loadMoreLoading.value = false;
|
loadMoreLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSearch() {
|
async function ensurePageLoaded(page: number) {
|
||||||
void loadData(true);
|
const pageSize = Number(query.limit || DEFAULT_PAGE_SIZE);
|
||||||
|
let guard = 0;
|
||||||
|
while (!notMore.value && list.value.length < page * pageSize && guard < page) {
|
||||||
|
const beforeLength = list.value.length;
|
||||||
|
const beforeContext = query.context;
|
||||||
|
await loadData(false);
|
||||||
|
guard += 1;
|
||||||
|
if (list.value.length === beforeLength && query.context === beforeContext) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handlePageChange(page: number) {
|
||||||
|
await ensurePageLoaded(page);
|
||||||
|
if (notMore.value) {
|
||||||
|
const maxPage = Math.max(1, Math.ceil(list.value.length / Number(query.limit || DEFAULT_PAGE_SIZE)));
|
||||||
|
currentPage.value = Math.min(page, maxPage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentPage.value = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSearch() {
|
||||||
|
await loadData(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openUserDetails(record: Record<string, any>) {
|
function openUserDetails(record: Record<string, any>) {
|
||||||
@ -294,7 +336,7 @@ void loadData(true);
|
|||||||
|
|
||||||
<Table
|
<Table
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:data-source="list"
|
:data-source="currentPageList"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:pagination="false"
|
:pagination="false"
|
||||||
row-key="id"
|
row-key="id"
|
||||||
@ -344,16 +386,15 @@ void loadData(true);
|
|||||||
</template>
|
</template>
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
<div v-if="list.length > 0" class="load-more">
|
<div v-if="list.length > 0" class="pagination">
|
||||||
<Button
|
<Pagination
|
||||||
v-if="!notMore"
|
:current="currentPage"
|
||||||
:loading="loadMoreLoading"
|
:disabled="loading || loadMoreLoading"
|
||||||
size="small"
|
:page-size="query.limit"
|
||||||
@click="loadData(false)"
|
:total="paginationTotal"
|
||||||
>
|
show-less-items
|
||||||
加载更多
|
@change="handlePageChange"
|
||||||
</Button>
|
/>
|
||||||
<span v-else>已加载全部</span>
|
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</component>
|
||||||
</component>
|
</component>
|
||||||
@ -384,9 +425,9 @@ void loadData(true);
|
|||||||
color: #262626;
|
color: #262626;
|
||||||
}
|
}
|
||||||
|
|
||||||
.load-more {
|
.pagination {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: flex-end;
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user