task-63(ASIN 数据中心): 实现去重汇总日期和国家筛选
新增 dedupe-total-filter.ts 纯局部筛选态:createDedupeTotalFilterState 默认空、 dedupeTotalFilterActive 判定任一激活、toDedupeListParams 过滤态+页码 → AsinListParams (空白/非法日期不下发),复用共享 asin-filter 类型。8 用例全过,459 单测 + build 绿。
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/** 去重汇总页面局部筛选状态(任务 63):日期区间/国家/分组/关键字,纯逻辑复用共享筛选类型。 */
|
||||
import { validIsoDateOrUndefined, type AsinListParams } from './asin-filter.ts'
|
||||
|
||||
export interface DedupeTotalFilterState {
|
||||
keyword: string
|
||||
username: string
|
||||
/** ISO yyyy-MM-dd;空串表示不限。 */
|
||||
startDate: string
|
||||
endDate: string
|
||||
groupId: number | null
|
||||
country: string
|
||||
}
|
||||
|
||||
export function createDedupeTotalFilterState(): DedupeTotalFilterState {
|
||||
return { keyword: '', username: '', startDate: '', endDate: '', groupId: null, country: '' }
|
||||
}
|
||||
|
||||
/** 是否有任一激活筛选条件。 */
|
||||
export function dedupeTotalFilterActive(state: DedupeTotalFilterState): boolean {
|
||||
if ((state.keyword || '').trim()) return true
|
||||
if ((state.username || '').trim()) return true
|
||||
if ((state.country || '').trim()) return true
|
||||
if (typeof state.groupId === 'number' && state.groupId >= 1) return true
|
||||
if (validIsoDateOrUndefined(state.startDate) || validIsoDateOrUndefined(state.endDate)) return true
|
||||
return false
|
||||
}
|
||||
|
||||
/** 过滤态 + 页码 → 列表查询参数;空白/非法日期不下发。 */
|
||||
export function toDedupeListParams(
|
||||
state: DedupeTotalFilterState,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
): AsinListParams {
|
||||
const params: AsinListParams = { page, pageSize }
|
||||
const keyword = (state.keyword || '').trim()
|
||||
const username = (state.username || '').trim()
|
||||
const country = (state.country || '').trim()
|
||||
if (keyword) params.keyword = keyword
|
||||
if (username) params.username = username
|
||||
if (country) params.country = country
|
||||
const startDate = validIsoDateOrUndefined(state.startDate)
|
||||
const endDate = validIsoDateOrUndefined(state.endDate)
|
||||
if (startDate) params.startDate = startDate
|
||||
if (endDate) params.endDate = endDate
|
||||
if (typeof state.groupId === 'number' && state.groupId >= 1) params.groupId = state.groupId
|
||||
return params
|
||||
}
|
||||
Reference in New Issue
Block a user