刘光辉
11 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
export interface TrendPopupOption {
  label: string;
  value: string;
}
 
export interface TrendTableColumn {
  dataIndex: string;
  key: string;
  title: string;
  width?: number;
}
 
export interface TrendTableOption extends TrendPopupOption {
  [key: string]: unknown;
}
 
export function normalizeTrendOptionValue(value?: string | string[]): string[] {
  if (Array.isArray(value)) return value.filter(Boolean);
  return value ? [value] : [];
}
 
export function filterTrendOptions(options: TrendPopupOption[], keyword: string): TrendPopupOption[] {
  const normalizedKeyword = keyword.trim().toLocaleLowerCase();
  if (!normalizedKeyword) return options;
  return options.filter(({ label, value }) => `${label}\n${value}`.toLocaleLowerCase().includes(normalizedKeyword));
}
 
export function filterTrendTableOptions<T extends TrendPopupOption>(options: T[], keyword: string, columnKeys: string[]): T[] {
  const normalizedKeyword = keyword.trim().toLocaleLowerCase();
  if (!normalizedKeyword) return options;
  return options.filter((option) => {
    const row = option as Record<string, unknown> & TrendPopupOption;
    return [option.label, option.value, ...columnKeys.map((key) => row[key])]
      .filter((value) => value !== undefined && value !== null)
      .some((value) => String(value).toLocaleLowerCase().includes(normalizedKeyword));
  });
}
 
export function getTrendOptionSummary(value: string | string[] | undefined, options: TrendPopupOption[]): string {
  const labelMap = new Map(options.map((option) => [option.value, option.label]));
  return normalizeTrendOptionValue(value)
    .map((key) => labelMap.get(key) || key)
    .join(', ');
}