|
|
@@ -10,8 +10,8 @@ import {
|
|
|
|
|
|
/**
|
|
|
* 服务端列条件:管理 state、toQueryParams、藏列清条件。
|
|
|
- * toQueryParams 本页(报销申请)YAGNI 写死映射 applyDateFrom / amountOp / statusIn 等;
|
|
|
- * 日后推广可在 ColumnFilterDef 增加可选 queryKey。
|
|
|
+ * toQueryParams 按 ColumnFilterDef 的 queryKey / queryKeyFrom|To / queryKeyPrefix 映射;
|
|
|
+ * 未配置时回退 prop(枚举 → `${key}In`,日期 → `${key}From|To`,数字 → `${prefix}Op` 等)。
|
|
|
*/
|
|
|
export function useServerColumnFilters(
|
|
|
columnDefs: ColumnFilterDef[],
|
|
|
@@ -90,35 +90,36 @@ export function useServerColumnFilters(
|
|
|
const state = filters[prop]
|
|
|
if (!def || !isColumnFilterActive(def.type, state)) continue
|
|
|
|
|
|
+ const key = def.queryKey || prop
|
|
|
+
|
|
|
if (def.type === 'datetime') {
|
|
|
- // 本页仅 applyTime → applyDateFrom / applyDateTo
|
|
|
const s = state as DatetimeColumnFilterState
|
|
|
- if (s.from) q.applyDateFrom = s.from
|
|
|
- if (s.to) q.applyDateTo = s.to
|
|
|
+ const fromKey = def.queryKeyFrom || `${key}From`
|
|
|
+ const toKey = def.queryKeyTo || `${key}To`
|
|
|
+ if (s.from) q[fromKey] = s.from
|
|
|
+ if (s.to) q[toKey] = s.to
|
|
|
continue
|
|
|
}
|
|
|
if (def.type === 'number') {
|
|
|
- // 本页仅 amount → amountOp / amountMin|amountMax|amount
|
|
|
const s = state as NumberColumnFilterState
|
|
|
- q.amountOp = s.op || 'between'
|
|
|
+ const prefix = def.queryKeyPrefix || key
|
|
|
+ q[`${prefix}Op`] = s.op || 'between'
|
|
|
if (s.op === 'between') {
|
|
|
- if (s.min !== '' && s.min != null) q.amountMin = String(s.min)
|
|
|
- if (s.max !== '' && s.max != null) q.amountMax = String(s.max)
|
|
|
+ if (s.min !== '' && s.min != null) q[`${prefix}Min`] = String(s.min)
|
|
|
+ if (s.max !== '' && s.max != null) q[`${prefix}Max`] = String(s.max)
|
|
|
} else if (s.value !== '' && s.value != null) {
|
|
|
- q.amount = String(s.value)
|
|
|
+ q[prefix] = String(s.value)
|
|
|
}
|
|
|
continue
|
|
|
}
|
|
|
if (def.type === 'enum') {
|
|
|
- // 本页仅 status → statusIn
|
|
|
const s = state as TextColumnFilterState
|
|
|
- if (s.selected?.length) q.statusIn = s.selected.join(',')
|
|
|
+ if (s.selected?.length) q[`${key}In`] = s.selected.join(',')
|
|
|
continue
|
|
|
}
|
|
|
- // text:prop 直接作为 query key(applyCode/title/expenseName/currentNode)
|
|
|
const s = state as TextColumnFilterState
|
|
|
const text = String(s.text || '').trim()
|
|
|
- if (text) q[prop] = text
|
|
|
+ if (text) q[key] = text
|
|
|
}
|
|
|
return q
|
|
|
}
|