/** 装货/送货客户列过滤 → 合并为服务端 stopCustomers / customerKeyword */ export function parseCustomerQueryParam(raw: unknown): string[] { if (raw == null || raw === '') return [] if (Array.isArray(raw)) { return raw.map((value) => String(value || '').trim()).filter(Boolean) } const text = String(raw).trim() if (!text) return [] if (text.startsWith('[')) { try { const parsed = JSON.parse(text) if (Array.isArray(parsed)) { return parsed.map((value) => String(value || '').trim()).filter(Boolean) } } catch { /* fall through */ } } return [text] } /** * 从 params 取出 loadCustomers / deliveryCustomers,合并写入 targetKey 后删除原键。 * @param targetKey 默认 stopCustomers;合同完善页可用 customerKeyword * @param asJson 为 true 时写入 JSON 数组字符串;否则写入首个关键字(兼容单字符串模糊匹配) */ export function applyMergedCustomerQueryParams( params: Record, options?: { targetKey?: string; asJson?: boolean } ): void { const targetKey = options?.targetKey || 'stopCustomers' const asJson = options?.asJson !== false const merged = [ ...parseCustomerQueryParam(params.loadCustomers), ...parseCustomerQueryParam(params.deliveryCustomers) ] delete params.loadCustomers delete params.deliveryCustomers if (!merged.length) return params[targetKey] = asJson ? JSON.stringify(merged) : merged[0] } export function selectedKeywordsFromFilter( filterState: { selected?: string[] } | null | undefined ): string[] | null { const selected = (filterState?.selected || []) .map((value) => String(value || '').trim()) .filter(Boolean) return selected.length ? selected : null }