fix: 优化后台体验与导出日志交互
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
export type SortOrderInput = 'ascend' | 'descend' | 'asc' | 'desc' | undefined;
|
||||
|
||||
export function normalizeSortOrder(order: SortOrderInput): 'asc' | 'desc' | null {
|
||||
if (order === 'asc' || order === 'ascend') return 'asc';
|
||||
if (order === 'desc' || order === 'descend') return 'desc';
|
||||
return null;
|
||||
}
|
||||
|
||||
export function buildOrderBy<T extends string>(
|
||||
field: string | undefined,
|
||||
order: SortOrderInput,
|
||||
allowed: readonly T[],
|
||||
fallback: Record<string, 'asc' | 'desc'>,
|
||||
): Record<string, 'asc' | 'desc'> {
|
||||
const normalized = normalizeSortOrder(order);
|
||||
if (!field || !normalized || !allowed.includes(field as T)) return fallback;
|
||||
return { [field]: normalized };
|
||||
}
|
||||
Reference in New Issue
Block a user