fix: request logs pagination
This commit is contained in:
@@ -107,7 +107,7 @@ export const authApi = {
|
|||||||
|
|
||||||
// Logs API
|
// Logs API
|
||||||
export const logsApi = {
|
export const logsApi = {
|
||||||
list: (params?: { method?: string; search?: string; page: number; limit: number }) => {
|
list: (params: { method?: string; search?: string; page: number; limit: number }) => {
|
||||||
const query = new URLSearchParams();
|
const query = new URLSearchParams();
|
||||||
if (params?.method) {
|
if (params?.method) {
|
||||||
query.set("method", params.method);
|
query.set("method", params.method);
|
||||||
@@ -115,8 +115,10 @@ export const logsApi = {
|
|||||||
if (params?.search) {
|
if (params?.search) {
|
||||||
query.set("search", params.search);
|
query.set("search", params.search);
|
||||||
}
|
}
|
||||||
|
query.set("page", params.page.toString());
|
||||||
|
query.set("limit", params.limit.toString());
|
||||||
const queryString = query.toString();
|
const queryString = query.toString();
|
||||||
return request<RequestLogs>(`/logs${queryString ? `?${queryString}` : ""}`);
|
return request<RequestLogs>(`/logs?${queryString}`);
|
||||||
},
|
},
|
||||||
methods: () => {
|
methods: () => {
|
||||||
return request<string[]>("/logs/methods");
|
return request<string[]>("/logs/methods");
|
||||||
|
|||||||
@@ -61,12 +61,10 @@ const RequestLogs: Component = () => {
|
|||||||
return new Date(dateStr).toLocaleString();
|
return new Date(dateStr).toLocaleString();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 辅助计算
|
|
||||||
const totalLogs = () => logsData()?.total || 0;
|
const totalLogs = () => logsData()?.total || 0;
|
||||||
const currentLogs = () => logsData()?.data || [];
|
const currentLogs = () => logsData()?.data || [];
|
||||||
const totalPages = () => Math.ceil(totalLogs() / PAGE_SIZE);
|
const totalPages = () => Math.ceil(totalLogs() / PAGE_SIZE);
|
||||||
|
|
||||||
// 分页操作
|
|
||||||
const goNext = () => {
|
const goNext = () => {
|
||||||
if (page() < totalPages()) setPage((p) => p + 1);
|
if (page() < totalPages()) setPage((p) => p + 1);
|
||||||
};
|
};
|
||||||
@@ -161,7 +159,6 @@ const RequestLogs: Component = () => {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 5. 底部添加分页控制条 */}
|
|
||||||
<Show when={totalLogs() > 0}>
|
<Show when={totalLogs() > 0}>
|
||||||
<div class="p-4 border-t flex items-center justify-between bg-gray-50">
|
<div class="p-4 border-t flex items-center justify-between bg-gray-50">
|
||||||
<div class="text-sm text-gray-500">
|
<div class="text-sm text-gray-500">
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ pub async fn list(
|
|||||||
total_builder.push(")");
|
total_builder.push(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
builder.push(" ORDER BY created_at DESC");
|
||||||
|
|
||||||
if let Some(limit) = limit {
|
if let Some(limit) = limit {
|
||||||
builder.push(" LIMIT ");
|
builder.push(" LIMIT ");
|
||||||
builder.push(limit);
|
builder.push(limit);
|
||||||
@@ -53,11 +55,9 @@ pub async fn list(
|
|||||||
builder.push(offset);
|
builder.push(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.push(" ORDER BY created_at DESC");
|
|
||||||
|
|
||||||
let query = builder.build_query_as();
|
let query = builder.build_query_as();
|
||||||
let logs = query.fetch_all(&mut *tx).await?;
|
let logs = query.fetch_all(&mut *tx).await?;
|
||||||
let total = builder
|
let total = total_builder
|
||||||
.build_query_scalar::<i64>()
|
.build_query_scalar::<i64>()
|
||||||
.fetch_one(&mut *tx)
|
.fetch_one(&mut *tx)
|
||||||
.await? as usize;
|
.await? as usize;
|
||||||
|
|||||||
Reference in New Issue
Block a user