优化物品规则分页加载
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
countWorkerActiveOrders,
|
||||
countWorkCategoryUsages,
|
||||
countWorkerLevelUsages,
|
||||
countWorkProductRulesByCategory,
|
||||
countWorkOrderPendingSharingSubmissions,
|
||||
countTimeoutEventsByWorkerIds,
|
||||
createWorkOrder,
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
listWorkOrders,
|
||||
listWorkOrderEventsByOrderId,
|
||||
listWorkProductRules,
|
||||
listWorkProductRulesPage,
|
||||
listWorkerLevels,
|
||||
listWorkerUsers,
|
||||
listWorkerWithdrawalAccounts,
|
||||
@@ -232,15 +234,32 @@ export async function deleteAdminWorkerLevel(levelId: number | string) {
|
||||
|
||||
export async function listAdminWorkProductRules(query: JsonObject = {}) {
|
||||
await ensureWorkerPlatformDefaults()
|
||||
const page = normalizePage(query.page)
|
||||
const pageSize = normalizePageSize(query.pageSize)
|
||||
const enabledValue = String(query.enabled ?? '').trim()
|
||||
const enabled = enabledValue
|
||||
? ['true', '1', 'enabled', 'active'].includes(enabledValue.toLowerCase())
|
||||
: null
|
||||
const items = await listWorkProductRules({
|
||||
enabled,
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
})
|
||||
return { items: items.map(mapWorkProductRule) }
|
||||
const keyword = String(query.keyword || '').trim()
|
||||
const categoryId = normalizeOptionalId(query.categoryId ?? query.category_id) || 0
|
||||
const [{ items, total }, categoryRows] = await Promise.all([
|
||||
listWorkProductRulesPage({
|
||||
page,
|
||||
pageSize,
|
||||
enabled,
|
||||
keyword,
|
||||
categoryId,
|
||||
}),
|
||||
countWorkProductRulesByCategory({ enabled, keyword }),
|
||||
])
|
||||
return {
|
||||
items: items.map(mapWorkProductRule),
|
||||
pagination: { page, pageSize, total },
|
||||
categoryCounts: categoryRows.map((row) => ({
|
||||
categoryId: row.categoryId,
|
||||
total: row.total,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveAdminWorkProductRule(payload: JsonObject = {}) {
|
||||
|
||||
Reference in New Issue
Block a user