@visactor/vtable-plugins 1.22.4-alpha.4 → 1.22.4-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/contextmenu/menu-manager.js +2 -1
- package/cjs/filter/condition-filter.d.ts +3 -3
- package/cjs/filter/condition-filter.js +7 -120
- package/cjs/filter/condition-filter.js.map +1 -1
- package/cjs/filter/constants.d.ts +7 -0
- package/cjs/filter/constants.js +124 -0
- package/cjs/filter/constants.js.map +1 -0
- package/cjs/filter/filter-state-manager.d.ts +2 -2
- package/cjs/filter/filter-state-manager.js +3 -3
- package/cjs/filter/filter-state-manager.js.map +1 -1
- package/cjs/filter/filter-toolbar.d.ts +2 -2
- package/cjs/filter/filter-toolbar.js +3 -3
- package/cjs/filter/filter-toolbar.js.map +1 -1
- package/cjs/filter/filter.d.ts +1 -0
- package/cjs/filter/filter.js +30 -16
- package/cjs/filter/filter.js.map +1 -1
- package/cjs/filter/types.d.ts +6 -0
- package/cjs/filter/types.js.map +1 -1
- package/cjs/filter/value-filter.d.ts +1 -0
- package/cjs/filter/value-filter.js +3 -0
- package/cjs/filter/value-filter.js.map +1 -1
- package/cjs/focus-highlight.js +1 -1
- package/cjs/focus-highlight.js.map +1 -1
- package/cjs/master-detail-plugin/config.js +1 -2
- package/cjs/master-detail-plugin/core.js +2 -1
- package/cjs/table-export/index.js +1 -1
- package/dist/vtable-plugins.js +91 -57
- package/dist/vtable-plugins.min.js +1 -1
- package/es/contextmenu/menu-manager.js +2 -1
- package/es/filter/condition-filter.d.ts +3 -3
- package/es/filter/condition-filter.js +8 -119
- package/es/filter/condition-filter.js.map +1 -1
- package/es/filter/constants.d.ts +7 -0
- package/es/filter/constants.js +120 -0
- package/es/filter/constants.js.map +1 -0
- package/es/filter/filter-state-manager.d.ts +2 -2
- package/es/filter/filter-state-manager.js +3 -3
- package/es/filter/filter-state-manager.js.map +1 -1
- package/es/filter/filter-toolbar.d.ts +2 -2
- package/es/filter/filter-toolbar.js +3 -3
- package/es/filter/filter-toolbar.js.map +1 -1
- package/es/filter/filter.d.ts +1 -0
- package/es/filter/filter.js +30 -15
- package/es/filter/filter.js.map +1 -1
- package/es/filter/types.d.ts +6 -0
- package/es/filter/types.js.map +1 -1
- package/es/filter/value-filter.d.ts +1 -0
- package/es/filter/value-filter.js +3 -0
- package/es/filter/value-filter.js.map +1 -1
- package/es/focus-highlight.js +1 -1
- package/es/focus-highlight.js.map +1 -1
- package/es/master-detail-plugin/config.js +1 -2
- package/es/master-detail-plugin/core.js +2 -1
- package/es/table-export/index.js +1 -1
- package/package.json +7 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ListTable, PivotTable } from '@visactor/vtable';
|
|
2
2
|
import type { FilterStateManager } from './filter-state-manager';
|
|
3
|
-
import type { FilterStyles } from './types';
|
|
3
|
+
import type { OperatorOption, FilterStyles, FilterOperatorCategoryOption } from './types';
|
|
4
4
|
export declare class ConditionFilter {
|
|
5
5
|
private table;
|
|
6
6
|
private filterStateManager;
|
|
@@ -12,9 +12,9 @@ export declare class ConditionFilter {
|
|
|
12
12
|
private valueInputMax;
|
|
13
13
|
private categorySelect;
|
|
14
14
|
private currentCategory;
|
|
15
|
-
private operators;
|
|
16
15
|
private categories;
|
|
17
|
-
|
|
16
|
+
protected operators: OperatorOption[];
|
|
17
|
+
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, styles: FilterStyles, conditionCategories: FilterOperatorCategoryOption[]);
|
|
18
18
|
setSelectedField(fieldId: string | number): void;
|
|
19
19
|
private updateOperatorOptions;
|
|
20
20
|
private handleCategoryChange;
|
|
@@ -4,125 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.ConditionFilter = void 0;
|
|
6
6
|
|
|
7
|
-
const styles_1 = require("./styles"), types_1 = require("./types");
|
|
7
|
+
const styles_1 = require("./styles"), types_1 = require("./types"), constants_1 = require("./constants");
|
|
8
8
|
|
|
9
9
|
class ConditionFilter {
|
|
10
|
-
constructor(table, filterStateManager, styles) {
|
|
11
|
-
this.currentCategory = types_1.FilterOperatorCategory.ALL, this.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
category: types_1.FilterOperatorCategory.ALL
|
|
15
|
-
}, {
|
|
16
|
-
value: "notEquals",
|
|
17
|
-
label: "不等于",
|
|
18
|
-
category: types_1.FilterOperatorCategory.ALL
|
|
19
|
-
}, {
|
|
20
|
-
value: "equals",
|
|
21
|
-
label: "等于",
|
|
22
|
-
category: types_1.FilterOperatorCategory.NUMBER
|
|
23
|
-
}, {
|
|
24
|
-
value: "notEquals",
|
|
25
|
-
label: "不等于",
|
|
26
|
-
category: types_1.FilterOperatorCategory.NUMBER
|
|
27
|
-
}, {
|
|
28
|
-
value: "greaterThan",
|
|
29
|
-
label: "大于",
|
|
30
|
-
category: types_1.FilterOperatorCategory.NUMBER
|
|
31
|
-
}, {
|
|
32
|
-
value: "lessThan",
|
|
33
|
-
label: "小于",
|
|
34
|
-
category: types_1.FilterOperatorCategory.NUMBER
|
|
35
|
-
}, {
|
|
36
|
-
value: "greaterThanOrEqual",
|
|
37
|
-
label: "大于等于",
|
|
38
|
-
category: types_1.FilterOperatorCategory.NUMBER
|
|
39
|
-
}, {
|
|
40
|
-
value: "lessThanOrEqual",
|
|
41
|
-
label: "小于等于",
|
|
42
|
-
category: types_1.FilterOperatorCategory.NUMBER
|
|
43
|
-
}, {
|
|
44
|
-
value: "between",
|
|
45
|
-
label: "介于",
|
|
46
|
-
category: types_1.FilterOperatorCategory.NUMBER
|
|
47
|
-
}, {
|
|
48
|
-
value: "notBetween",
|
|
49
|
-
label: "不介于",
|
|
50
|
-
category: types_1.FilterOperatorCategory.NUMBER
|
|
51
|
-
}, {
|
|
52
|
-
value: "equals",
|
|
53
|
-
label: "等于",
|
|
54
|
-
category: types_1.FilterOperatorCategory.TEXT
|
|
55
|
-
}, {
|
|
56
|
-
value: "notEquals",
|
|
57
|
-
label: "不等于",
|
|
58
|
-
category: types_1.FilterOperatorCategory.TEXT
|
|
59
|
-
}, {
|
|
60
|
-
value: "contains",
|
|
61
|
-
label: "包含",
|
|
62
|
-
category: types_1.FilterOperatorCategory.TEXT
|
|
63
|
-
}, {
|
|
64
|
-
value: "notContains",
|
|
65
|
-
label: "不包含",
|
|
66
|
-
category: types_1.FilterOperatorCategory.TEXT
|
|
67
|
-
}, {
|
|
68
|
-
value: "startsWith",
|
|
69
|
-
label: "开头是",
|
|
70
|
-
category: types_1.FilterOperatorCategory.TEXT
|
|
71
|
-
}, {
|
|
72
|
-
value: "notStartsWith",
|
|
73
|
-
label: "开头不是",
|
|
74
|
-
category: types_1.FilterOperatorCategory.TEXT
|
|
75
|
-
}, {
|
|
76
|
-
value: "endsWith",
|
|
77
|
-
label: "结尾是",
|
|
78
|
-
category: types_1.FilterOperatorCategory.TEXT
|
|
79
|
-
}, {
|
|
80
|
-
value: "notEndsWith",
|
|
81
|
-
label: "结尾不是",
|
|
82
|
-
category: types_1.FilterOperatorCategory.TEXT
|
|
83
|
-
}, {
|
|
84
|
-
value: "equals",
|
|
85
|
-
label: "等于",
|
|
86
|
-
category: types_1.FilterOperatorCategory.COLOR
|
|
87
|
-
}, {
|
|
88
|
-
value: "notEquals",
|
|
89
|
-
label: "不等于",
|
|
90
|
-
category: types_1.FilterOperatorCategory.COLOR
|
|
91
|
-
}, {
|
|
92
|
-
value: "isChecked",
|
|
93
|
-
label: "已选中",
|
|
94
|
-
category: types_1.FilterOperatorCategory.CHECKBOX
|
|
95
|
-
}, {
|
|
96
|
-
value: "isUnchecked",
|
|
97
|
-
label: "未选中",
|
|
98
|
-
category: types_1.FilterOperatorCategory.CHECKBOX
|
|
99
|
-
}, {
|
|
100
|
-
value: "isChecked",
|
|
101
|
-
label: "已选中",
|
|
102
|
-
category: types_1.FilterOperatorCategory.RADIO
|
|
103
|
-
}, {
|
|
104
|
-
value: "isUnchecked",
|
|
105
|
-
label: "未选中",
|
|
106
|
-
category: types_1.FilterOperatorCategory.RADIO
|
|
107
|
-
} ], this.categories = [ {
|
|
108
|
-
value: types_1.FilterOperatorCategory.ALL,
|
|
109
|
-
label: "全部"
|
|
110
|
-
}, {
|
|
111
|
-
value: types_1.FilterOperatorCategory.TEXT,
|
|
112
|
-
label: "文本"
|
|
113
|
-
}, {
|
|
114
|
-
value: types_1.FilterOperatorCategory.NUMBER,
|
|
115
|
-
label: "数值"
|
|
116
|
-
}, {
|
|
117
|
-
value: types_1.FilterOperatorCategory.COLOR,
|
|
118
|
-
label: "颜色"
|
|
119
|
-
}, {
|
|
120
|
-
value: types_1.FilterOperatorCategory.CHECKBOX,
|
|
121
|
-
label: "复选框"
|
|
122
|
-
}, {
|
|
123
|
-
value: types_1.FilterOperatorCategory.RADIO,
|
|
124
|
-
label: "单选框"
|
|
125
|
-
} ], this.table = table, this.styles = styles, this.filterStateManager = filterStateManager;
|
|
10
|
+
constructor(table, filterStateManager, styles, conditionCategories) {
|
|
11
|
+
this.currentCategory = types_1.FilterOperatorCategory.ALL, this.categories = [],
|
|
12
|
+
this.operators = [], this.table = table, this.styles = styles, this.filterStateManager = filterStateManager,
|
|
13
|
+
this.categories = conditionCategories, this.operators = constants_1.operators;
|
|
126
14
|
}
|
|
127
15
|
setSelectedField(fieldId) {
|
|
128
16
|
this.selectedField = fieldId, this.updateOperatorOptions(), this.loadCurrentFilterState();
|
|
@@ -132,7 +20,7 @@ class ConditionFilter {
|
|
|
132
20
|
let filteredOperators;
|
|
133
21
|
if (this.operatorSelect.innerHTML = "", this.currentCategory === types_1.FilterOperatorCategory.ALL) {
|
|
134
22
|
const uniqueOperators = new Map;
|
|
135
|
-
this.operators.forEach((op => {
|
|
23
|
+
this.operators.filter((op => this.categories.map((cat => cat.value)).includes(op.category))).forEach((op => {
|
|
136
24
|
uniqueOperators.has(op.value) || uniqueOperators.set(op.value, op);
|
|
137
25
|
})), filteredOperators = Array.from(uniqueOperators.values());
|
|
138
26
|
} else filteredOperators = this.operators.filter((op => op.category === this.currentCategory));
|
|
@@ -267,5 +155,4 @@ class ConditionFilter {
|
|
|
267
155
|
}
|
|
268
156
|
}
|
|
269
157
|
|
|
270
|
-
exports.ConditionFilter = ConditionFilter;
|
|
271
|
-
//# sourceMappingURL=condition-filter.js.map
|
|
158
|
+
exports.ConditionFilter = ConditionFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/condition-filter.ts"],"names":[],"mappings":";;;AAEA,qCAAsD;AAEtD,mCAAmE;AAKnE,MAAa,eAAe;IA8D1B,YAAY,KAA6B,EAAE,kBAAsC,EAAE,MAAoB;QAnD/F,oBAAe,GAA2B,8BAAsB,CAAC,GAAG,CAAC;QAGrE,cAAS,GAAqB;YAEpC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,GAAG,EAAE;YACtE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,GAAG,EAAE;YAG1E,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,MAAM,EAAE;YACzE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,MAAM,EAAE;YAC7E,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,MAAM,EAAE;YAC9E,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,MAAM,EAAE;YAC3E,EAAE,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAAsB,CAAC,MAAM,EAAE;YACvF,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAA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CAAC,OAAO,GAAG,cAAc,CAAC;aACzC;iBAAM;gBACL,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,QAAQ,CAAC;gBACvC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;gBAC1C,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;aACjC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAKD,IAAI;QACF,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAC/B,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;YACpD,IAAI,CAAC,sBAAsB,EAAE,CAAC;SAC/B;IACH,CAAC;IAKD,IAAI;QACF,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAC/B,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;SACpD;IACH,CAAC;CACF;AA7bD,0CA6bC","file":"condition-filter.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { FilterStateManager } from './filter-state-manager';\nimport { applyStyles, createElement } from './styles';\nimport type { FilterOperator, OperatorOption, FilterStyles } from './types';\nimport { FilterActionType, FilterOperatorCategory } from './types';\n\n/**\n * 按条件筛选组件\n */\nexport class ConditionFilter {\n private table: ListTable | PivotTable;\n private filterStateManager: FilterStateManager;\n private styles: FilterStyles;\n\n private filterByConditionPanel: HTMLElement;\n private selectedField: string | number;\n private operatorSelect: HTMLSelectElement;\n private valueInput: HTMLInputElement;\n private valueInputMax: HTMLInputElement;\n private categorySelect: HTMLSelectElement;\n private currentCategory: FilterOperatorCategory = FilterOperatorCategory.ALL;\n\n // 按分类组织的操作符选项\n private operators: OperatorOption[] = [\n // 通用操作符 (全部分类中显示)\n { value: 'equals', label: '等于', category: FilterOperatorCategory.ALL },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.ALL },\n\n // 数值操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.NUMBER },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.NUMBER },\n { value: 'greaterThan', label: '大于', category: FilterOperatorCategory.NUMBER },\n { value: 'lessThan', label: '小于', category: FilterOperatorCategory.NUMBER },\n { value: 'greaterThanOrEqual', label: '大于等于', category: FilterOperatorCategory.NUMBER },\n { value: 'lessThanOrEqual', label: '小于等于', category: FilterOperatorCategory.NUMBER },\n { value: 'between', label: '介于', category: FilterOperatorCategory.NUMBER },\n { value: 'notBetween', label: '不介于', category: FilterOperatorCategory.NUMBER },\n\n // 文本操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.TEXT },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.TEXT },\n { value: 'contains', label: '包含', category: FilterOperatorCategory.TEXT },\n { value: 'notContains', label: '不包含', category: FilterOperatorCategory.TEXT },\n { value: 'startsWith', label: '开头是', category: FilterOperatorCategory.TEXT },\n { value: 'notStartsWith', label: '开头不是', category: FilterOperatorCategory.TEXT },\n { value: 'endsWith', label: '结尾是', category: FilterOperatorCategory.TEXT },\n { value: 'notEndsWith', label: '结尾不是', category: FilterOperatorCategory.TEXT },\n\n // 颜色操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.COLOR },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.COLOR },\n\n // 复选框操作符\n { value: 'isChecked', label: '已选中', category: FilterOperatorCategory.CHECKBOX },\n { value: 'isUnchecked', label: '未选中', category: FilterOperatorCategory.CHECKBOX },\n\n // 单选框操作符\n { value: 'isChecked', label: '已选中', category: FilterOperatorCategory.RADIO },\n { value: 'isUnchecked', label: '未选中', category: FilterOperatorCategory.RADIO }\n ];\n\n // 分类下拉选项\n private categories = [\n { value: FilterOperatorCategory.ALL, label: '全部' },\n { value: FilterOperatorCategory.TEXT, label: '文本' },\n { value: FilterOperatorCategory.NUMBER, label: '数值' },\n { value: FilterOperatorCategory.COLOR, label: '颜色' },\n { value: FilterOperatorCategory.CHECKBOX, label: '复选框' },\n { value: FilterOperatorCategory.RADIO, label: '单选框' }\n ];\n\n constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, styles: FilterStyles) {\n this.table = table;\n this.styles = styles;\n this.filterStateManager = filterStateManager;\n }\n\n setSelectedField(fieldId: string | number): void {\n this.selectedField = fieldId;\n this.updateOperatorOptions();\n this.loadCurrentFilterState();\n }\n\n /**\n * 更新操作符下拉选项\n */\n private updateOperatorOptions(): void {\n if (!this.operatorSelect) {\n return;\n }\n this.operatorSelect.innerHTML = '';\n let filteredOperators: OperatorOption[];\n\n if (this.currentCategory === FilterOperatorCategory.ALL) {\n // 当选择\"全部\"时,收集所有不重复的操作符\n const uniqueOperators = new Map<string, OperatorOption>();\n this.operators.forEach(op => {\n if (!uniqueOperators.has(op.value)) {\n uniqueOperators.set(op.value, op);\n }\n });\n filteredOperators = Array.from(uniqueOperators.values());\n } else {\n // 其他类别正常筛选\n filteredOperators = this.operators.filter(op => op.category === this.currentCategory);\n }\n\n // 添加新选项\n filteredOperators.forEach(op => {\n const option = document.createElement('option');\n option.value = op.value;\n option.textContent = op.label;\n this.operatorSelect.appendChild(option);\n });\n }\n\n private handleCategoryChange(): void {\n if (!this.categorySelect) {\n return;\n }\n\n this.currentCategory = this.categorySelect.value as FilterOperatorCategory;\n this.updateOperatorOptions();\n\n // 分类切换后也需要同步UI状态\n this.syncUIState();\n }\n\n /**\n * 加载当前的筛选状态\n */\n private loadCurrentFilterState(): void {\n const filter = this.filterStateManager.getFilterState(this.selectedField);\n\n if (filter && filter.type === 'byCondition') {\n // 设置操作符\n if (filter.operator && this.operatorSelect) {\n this.operatorSelect.value = filter.operator;\n }\n\n // 设置条件值\n if (filter.condition !== undefined && this.valueInput) {\n if (Array.isArray(filter.condition)) {\n this.valueInput.value = String(filter.condition[0]);\n if (this.valueInputMax) {\n this.valueInputMax.value = String(filter.condition[1]);\n }\n } else {\n this.valueInput.value = String(filter.condition);\n if (this.valueInputMax) {\n this.valueInputMax.value = '';\n }\n }\n }\n\n // 同步UI状态:根据当前操作符显示/隐藏范围输入框\n this.syncUIState();\n } else {\n // 重置为默认值\n this.reset();\n }\n }\n\n /**\n * 重置筛选条件到默认状态\n */\n reset(): void {\n // 重置操作符选择\n if (this.operatorSelect) {\n this.operatorSelect.selectedIndex = 0;\n }\n\n // 重置所有输入框\n if (this.valueInput) {\n this.valueInput.value = '';\n this.valueInput.placeholder = '请输入筛选值';\n }\n\n if (this.valueInputMax) {\n this.valueInputMax.value = '';\n }\n\n // 重置分类选择\n this.currentCategory = FilterOperatorCategory.ALL;\n if (this.categorySelect) {\n this.categorySelect.value = FilterOperatorCategory.ALL;\n }\n\n // 更新操作符选项\n this.updateOperatorOptions();\n\n // 同步UI状态\n this.syncUIState();\n }\n\n /**\n * 同步UI状态:根据当前选择的操作符调整UI显示\n */\n private syncUIState(): void {\n if (!this.operatorSelect || !this.valueInput) {\n return;\n }\n\n const selectedOperator = this.operatorSelect.value as FilterOperator;\n const andLabel = this.valueInput.nextElementSibling as HTMLElement;\n\n if (this.isRangeOperator(selectedOperator)) {\n // 显示范围输入相关UI\n this.valueInput.placeholder = '最小值';\n if (this.valueInputMax) {\n this.valueInputMax.style.display = 'inline-block';\n }\n if (andLabel) {\n andLabel.style.display = 'inline-block';\n }\n } else {\n // 隐藏范围输入相关UI\n this.valueInput.placeholder = '请输入筛选值';\n if (this.valueInputMax) {\n this.valueInputMax.style.display = 'none';\n }\n if (andLabel) {\n andLabel.style.display = 'none';\n }\n }\n }\n\n private isBooleanOperator(operator: FilterOperator): boolean {\n const booleanCondition = ['isChecked', 'isUnchecked'];\n return booleanCondition.includes(operator);\n }\n\n private isRangeOperator(operator: FilterOperator): boolean {\n return operator === 'between' || operator === 'notBetween';\n }\n\n /**\n * 应用筛选条件\n */\n applyFilter(fieldId: string | number = this.selectedField): void {\n if (!this.operatorSelect || !this.valueInput) {\n return;\n }\n\n const operator = this.operatorSelect?.value as FilterOperator;\n let conditionValue: any = this.valueInput?.value;\n\n // 根据所选操作符和分类尝试转换输入值\n if (this.currentCategory === FilterOperatorCategory.NUMBER) {\n conditionValue = parseFloat(conditionValue);\n if (isNaN(conditionValue)) {\n console.warn('请输入有效的数字');\n return;\n }\n }\n\n // 处理范围操作符的双值输入\n if (this.isRangeOperator(operator)) {\n const minValue = conditionValue;\n let maxValue: string | number = this.valueInputMax.value.trim();\n\n // 尝试将最大值也转换为数字\n if (this.currentCategory === FilterOperatorCategory.NUMBER) {\n const numMaxValue = parseFloat(maxValue);\n if (!isNaN(numMaxValue)) {\n maxValue = numMaxValue;\n } else {\n console.warn('请输入有效的最大值');\n return;\n }\n }\n\n // 使用数组形式传递范围值\n conditionValue = [minValue, maxValue];\n }\n\n if (!conditionValue && conditionValue !== false && conditionValue !== 0 && !this.isBooleanOperator(operator)) {\n this.clearFilter(fieldId);\n return;\n }\n\n // TODO:处理单元格颜色和字体颜色的筛选\n\n this.filterStateManager.dispatch({\n type: FilterActionType.APPLY_FILTERS,\n payload: {\n field: fieldId,\n type: 'byCondition',\n operator,\n condition: conditionValue,\n enable: true\n }\n });\n\n this.hide();\n }\n\n /**\n * 清除筛选\n */\n clearFilter(fieldId: string | number): void {\n this.filterStateManager.dispatch({\n type: FilterActionType.REMOVE_FILTER,\n payload: {\n field: fieldId\n }\n });\n\n this.hide();\n }\n\n /**\n * 渲染条件筛选面板\n */\n render(container: HTMLElement): void {\n // 按条件筛选面板\n this.filterByConditionPanel = document.createElement('div');\n applyStyles(this.filterByConditionPanel, this.styles.filterPanel);\n\n // 条件选择区域\n const conditionContainer = document.createElement('div');\n applyStyles(conditionContainer, this.styles.conditionContainer);\n\n // 分类选择下拉框\n const categoryLabel = createElement('label', {}, ['筛选类型:']);\n applyStyles(categoryLabel, this.styles.formLabel);\n\n this.categorySelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.categorySelect, this.styles.operatorSelect);\n\n // 添加分类选项\n this.categories.forEach(category => {\n const option = document.createElement('option');\n option.value = category.value;\n option.textContent = category.label;\n this.categorySelect.appendChild(option);\n });\n\n // 操作符选择下拉框\n const operatorLabel = createElement('label', {}, ['筛选条件:']);\n applyStyles(operatorLabel, this.styles.formLabel);\n\n this.operatorSelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.operatorSelect, this.styles.operatorSelect);\n\n // 条件值输入框\n const valueLabel = createElement('label', {}, ['筛选值:']);\n applyStyles(valueLabel, this.styles.formLabel);\n\n // 一个容器来包装两个输入框和\"和\"字\n const rangeInputContainer = createElement('div');\n applyStyles(rangeInputContainer, this.styles.rangeInputContainer);\n\n this.valueInput = createElement('input', {\n type: 'text',\n placeholder: '请输入筛选值'\n }) as HTMLInputElement;\n applyStyles(this.valueInput, this.styles.searchInput);\n\n // \"和\"字标签\n const andLabel = createElement('span', {}, ['和']);\n applyStyles(andLabel, this.styles.addLabel);\n andLabel.style.display = 'none'; // 默认隐藏\n\n // 范围筛选的最大值输入框\n this.valueInputMax = createElement('input', {\n type: 'text',\n placeholder: '最大值'\n }) as HTMLInputElement;\n applyStyles(this.valueInputMax, this.styles.searchInput);\n this.valueInputMax.style.display = 'none'; // 默认隐藏\n\n // 将输入框和\"和\"字添加到容器中\n rangeInputContainer.appendChild(this.valueInput);\n rangeInputContainer.appendChild(andLabel);\n rangeInputContainer.appendChild(this.valueInputMax);\n\n // 将元素添加到容器中\n conditionContainer.appendChild(categoryLabel);\n conditionContainer.appendChild(this.categorySelect);\n conditionContainer.appendChild(operatorLabel);\n conditionContainer.appendChild(this.operatorSelect);\n conditionContainer.appendChild(valueLabel);\n conditionContainer.appendChild(rangeInputContainer);\n\n this.filterByConditionPanel.appendChild(conditionContainer);\n container.appendChild(this.filterByConditionPanel);\n\n // 默认隐藏\n this.hide();\n\n // 初始化操作符选项\n this.updateOperatorOptions();\n this.bindEvents();\n }\n\n /**\n * 绑定事件\n */\n private bindEvents(): void {\n // 输入框回车事件\n this.valueInput.addEventListener('keypress', event => {\n if (event.key === 'Enter') {\n this.applyFilter();\n }\n });\n\n // 最大值输入框回车事件\n this.valueInputMax.addEventListener('keypress', event => {\n if (event.key === 'Enter') {\n this.applyFilter();\n }\n });\n\n // 分类切换事件\n this.categorySelect.addEventListener('change', () => {\n this.handleCategoryChange();\n });\n\n // 操作符切换事件\n this.operatorSelect.addEventListener('change', () => {\n const selectedOperator = this.operatorSelect.value as FilterOperator;\n const andLabel = this.valueInput.nextElementSibling as HTMLElement;\n\n if (this.isRangeOperator(selectedOperator)) {\n this.valueInput.placeholder = '最小值';\n this.valueInputMax.style.display = 'inline-block';\n andLabel.style.display = 'inline-block';\n } else {\n this.valueInput.placeholder = '请输入筛选值';\n this.valueInputMax.style.display = 'none';\n andLabel.style.display = 'none';\n }\n });\n }\n\n /**\n * 显示筛选面板\n */\n show(): void {\n if (this.filterByConditionPanel) {\n this.filterByConditionPanel.style.display = 'block';\n this.loadCurrentFilterState();\n }\n }\n\n /**\n * 隐藏筛选面板\n */\n hide(): void {\n if (this.filterByConditionPanel) {\n this.filterByConditionPanel.style.display = 'none';\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/filter/condition-filter.ts"],"names":[],"mappings":";;;AAEA,qCAAsD;AAEtD,mCAAmE;AACnE,2CAAwC;AAKxC,MAAa,eAAe;IAgB1B,YACE,KAA6B,EAC7B,kBAAsC,EACtC,MAAoB,EACpB,mBAAmD;QAT7C,oBAAe,GAA2B,8BAAsB,CAAC,GAAG,CAAC;QAErE,eAAU,GAAmC,EAAE,CAAC;QAC9C,cAAS,GAAqB,EAAE,CAAC;QAQzC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,qBAAS,CAAC;IAC7B,CAAC;IAED,gBAAgB,CAAC,OAAwB;QACvC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;QAC7B,I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rE,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAiC,CAAC;YAEnE,IAAI,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,EAAE;gBAC1C,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,KAAK,CAAC;gBACpC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,GAAG,cAAc,CAAC;gBAClD,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAG,cAAc,CAAC;aACzC;iBAAM;gBACL,IAAI,CAAC,UAAU,CAAC,WAAW,GAAG,QAAQ,CAAC;gBACvC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;gBAC1C,QAAQ,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;aACjC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAKD,IAAI;QACF,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAC/B,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;YACpD,IAAI,CAAC,sBAAsB,EAAE,CAAC;SAC/B;IACH,CAAC;IAKD,IAAI;QACF,IAAI,IAAI,CAAC,sBAAsB,EAAE;YAC/B,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;SACpD;IACH,CAAC;CACF;AAxZD,0CAwZC","file":"condition-filter.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { FilterStateManager } from './filter-state-manager';\nimport { applyStyles, createElement } from './styles';\nimport type { FilterOperator, OperatorOption, FilterStyles, FilterOperatorCategoryOption } from './types';\nimport { FilterActionType, FilterOperatorCategory } from './types';\nimport { operators } from './constants';\n\n/**\n * 按条件筛选组件\n */\nexport class ConditionFilter {\n private table: ListTable | PivotTable;\n private filterStateManager: FilterStateManager;\n private styles: FilterStyles;\n\n private filterByConditionPanel: HTMLElement;\n private selectedField: string | number;\n private operatorSelect: HTMLSelectElement;\n private valueInput: HTMLInputElement;\n private valueInputMax: HTMLInputElement;\n private categorySelect: HTMLSelectElement;\n private currentCategory: FilterOperatorCategory = FilterOperatorCategory.ALL;\n\n private categories: FilterOperatorCategoryOption[] = [];\n protected operators: OperatorOption[] = [];\n\n constructor(\n table: ListTable | PivotTable,\n filterStateManager: FilterStateManager,\n styles: FilterStyles,\n conditionCategories: FilterOperatorCategoryOption[]\n ) {\n this.table = table;\n this.styles = styles;\n this.filterStateManager = filterStateManager;\n this.categories = conditionCategories;\n this.operators = operators;\n }\n\n setSelectedField(fieldId: string | number): void {\n this.selectedField = fieldId;\n this.updateOperatorOptions();\n this.loadCurrentFilterState();\n }\n\n /**\n * 更新操作符下拉选项\n */\n private updateOperatorOptions(): void {\n if (!this.operatorSelect) {\n return;\n }\n this.operatorSelect.innerHTML = '';\n let filteredOperators: OperatorOption[];\n\n if (this.currentCategory === FilterOperatorCategory.ALL) {\n // 当选择\"全部\"时,收集所有配置的分类中, 不重复的操作符\n const uniqueOperators = new Map<string, OperatorOption>();\n this.operators\n .filter(op => this.categories.map(cat => cat.value).includes(op.category))\n .forEach(op => {\n if (!uniqueOperators.has(op.value)) {\n uniqueOperators.set(op.value, op);\n }\n });\n filteredOperators = Array.from(uniqueOperators.values());\n } else {\n // 其他类别正常筛选\n filteredOperators = this.operators.filter(op => op.category === this.currentCategory);\n }\n\n // 添加新选项\n filteredOperators.forEach(op => {\n const option = document.createElement('option');\n option.value = op.value;\n option.textContent = op.label;\n this.operatorSelect.appendChild(option);\n });\n }\n\n private handleCategoryChange(): void {\n if (!this.categorySelect) {\n return;\n }\n\n this.currentCategory = this.categorySelect.value as FilterOperatorCategory;\n this.updateOperatorOptions();\n\n // 分类切换后也需要同步UI状态\n this.syncUIState();\n }\n\n /**\n * 加载当前的筛选状态\n */\n private loadCurrentFilterState(): void {\n const filter = this.filterStateManager.getFilterState(this.selectedField);\n\n if (filter && filter.type === 'byCondition') {\n // 设置操作符\n if (filter.operator && this.operatorSelect) {\n this.operatorSelect.value = filter.operator;\n }\n\n // 设置条件值\n if (filter.condition !== undefined && this.valueInput) {\n if (Array.isArray(filter.condition)) {\n this.valueInput.value = String(filter.condition[0]);\n if (this.valueInputMax) {\n this.valueInputMax.value = String(filter.condition[1]);\n }\n } else {\n this.valueInput.value = String(filter.condition);\n if (this.valueInputMax) {\n this.valueInputMax.value = '';\n }\n }\n }\n\n // 同步UI状态:根据当前操作符显示/隐藏范围输入框\n this.syncUIState();\n } else {\n // 重置为默认值\n this.reset();\n }\n }\n\n /**\n * 重置筛选条件到默认状态\n */\n reset(): void {\n // 重置操作符选择\n if (this.operatorSelect) {\n this.operatorSelect.selectedIndex = 0;\n }\n\n // 重置所有输入框\n if (this.valueInput) {\n this.valueInput.value = '';\n this.valueInput.placeholder = '请输入筛选值';\n }\n\n if (this.valueInputMax) {\n this.valueInputMax.value = '';\n }\n\n // 重置分类选择\n this.currentCategory = FilterOperatorCategory.ALL;\n if (this.categorySelect) {\n this.categorySelect.value = FilterOperatorCategory.ALL;\n }\n\n // 更新操作符选项\n this.updateOperatorOptions();\n\n // 同步UI状态\n this.syncUIState();\n }\n\n /**\n * 同步UI状态:根据当前选择的操作符调整UI显示\n */\n private syncUIState(): void {\n if (!this.operatorSelect || !this.valueInput) {\n return;\n }\n\n const selectedOperator = this.operatorSelect.value as FilterOperator;\n const andLabel = this.valueInput.nextElementSibling as HTMLElement;\n\n if (this.isRangeOperator(selectedOperator)) {\n // 显示范围输入相关UI\n this.valueInput.placeholder = '最小值';\n if (this.valueInputMax) {\n this.valueInputMax.style.display = 'inline-block';\n }\n if (andLabel) {\n andLabel.style.display = 'inline-block';\n }\n } else {\n // 隐藏范围输入相关UI\n this.valueInput.placeholder = '请输入筛选值';\n if (this.valueInputMax) {\n this.valueInputMax.style.display = 'none';\n }\n if (andLabel) {\n andLabel.style.display = 'none';\n }\n }\n }\n\n private isBooleanOperator(operator: FilterOperator): boolean {\n const booleanCondition = ['isChecked', 'isUnchecked'];\n return booleanCondition.includes(operator);\n }\n\n private isRangeOperator(operator: FilterOperator): boolean {\n return operator === 'between' || operator === 'notBetween';\n }\n\n /**\n * 应用筛选条件\n */\n applyFilter(fieldId: string | number = this.selectedField): void {\n if (!this.operatorSelect || !this.valueInput) {\n return;\n }\n\n const operator = this.operatorSelect?.value as FilterOperator;\n let conditionValue: any = this.valueInput?.value;\n\n // 根据所选操作符和分类尝试转换输入值\n if (this.currentCategory === FilterOperatorCategory.NUMBER) {\n conditionValue = parseFloat(conditionValue);\n if (isNaN(conditionValue)) {\n console.warn('请输入有效的数字');\n return;\n }\n }\n\n // 处理范围操作符的双值输入\n if (this.isRangeOperator(operator)) {\n const minValue = conditionValue;\n let maxValue: string | number = this.valueInputMax.value.trim();\n\n // 尝试将最大值也转换为数字\n if (this.currentCategory === FilterOperatorCategory.NUMBER) {\n const numMaxValue = parseFloat(maxValue);\n if (!isNaN(numMaxValue)) {\n maxValue = numMaxValue;\n } else {\n console.warn('请输入有效的最大值');\n return;\n }\n }\n\n // 使用数组形式传递范围值\n conditionValue = [minValue, maxValue];\n }\n\n if (!conditionValue && conditionValue !== false && conditionValue !== 0 && !this.isBooleanOperator(operator)) {\n this.clearFilter(fieldId);\n return;\n }\n\n // TODO:处理单元格颜色和字体颜色的筛选\n\n this.filterStateManager.dispatch({\n type: FilterActionType.APPLY_FILTERS,\n payload: {\n field: fieldId,\n type: 'byCondition',\n operator,\n condition: conditionValue,\n enable: true\n }\n });\n\n this.hide();\n }\n\n /**\n * 清除筛选\n */\n clearFilter(fieldId: string | number): void {\n this.filterStateManager.dispatch({\n type: FilterActionType.REMOVE_FILTER,\n payload: {\n field: fieldId\n }\n });\n\n this.hide();\n }\n\n /**\n * 渲染条件筛选面板\n */\n render(container: HTMLElement): void {\n // 按条件筛选面板\n this.filterByConditionPanel = document.createElement('div');\n applyStyles(this.filterByConditionPanel, this.styles.filterPanel);\n\n // 条件选择区域\n const conditionContainer = document.createElement('div');\n applyStyles(conditionContainer, this.styles.conditionContainer);\n\n // 分类选择下拉框\n const categoryLabel = createElement('label', {}, ['筛选类型:']);\n applyStyles(categoryLabel, this.styles.formLabel);\n\n this.categorySelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.categorySelect, this.styles.operatorSelect);\n\n // 添加分类选项\n this.categories.forEach(category => {\n const option = document.createElement('option');\n option.value = category.value;\n option.textContent = category.label;\n this.categorySelect.appendChild(option);\n });\n\n // 操作符选择下拉框\n const operatorLabel = createElement('label', {}, ['筛选条件:']);\n applyStyles(operatorLabel, this.styles.formLabel);\n\n this.operatorSelect = createElement('select') as HTMLSelectElement;\n applyStyles(this.operatorSelect, this.styles.operatorSelect);\n\n // 条件值输入框\n const valueLabel = createElement('label', {}, ['筛选值:']);\n applyStyles(valueLabel, this.styles.formLabel);\n\n // 一个容器来包装两个输入框和\"和\"字\n const rangeInputContainer = createElement('div');\n applyStyles(rangeInputContainer, this.styles.rangeInputContainer);\n\n this.valueInput = createElement('input', {\n type: 'text',\n placeholder: '请输入筛选值'\n }) as HTMLInputElement;\n applyStyles(this.valueInput, this.styles.searchInput);\n\n // \"和\"字标签\n const andLabel = createElement('span', {}, ['和']);\n applyStyles(andLabel, this.styles.addLabel);\n andLabel.style.display = 'none'; // 默认隐藏\n\n // 范围筛选的最大值输入框\n this.valueInputMax = createElement('input', {\n type: 'text',\n placeholder: '最大值'\n }) as HTMLInputElement;\n applyStyles(this.valueInputMax, this.styles.searchInput);\n this.valueInputMax.style.display = 'none'; // 默认隐藏\n\n // 将输入框和\"和\"字添加到容器中\n rangeInputContainer.appendChild(this.valueInput);\n rangeInputContainer.appendChild(andLabel);\n rangeInputContainer.appendChild(this.valueInputMax);\n\n // 将元素添加到容器中\n conditionContainer.appendChild(categoryLabel);\n conditionContainer.appendChild(this.categorySelect);\n conditionContainer.appendChild(operatorLabel);\n conditionContainer.appendChild(this.operatorSelect);\n conditionContainer.appendChild(valueLabel);\n conditionContainer.appendChild(rangeInputContainer);\n\n this.filterByConditionPanel.appendChild(conditionContainer);\n container.appendChild(this.filterByConditionPanel);\n\n // 默认隐藏\n this.hide();\n\n // 初始化操作符选项\n this.updateOperatorOptions();\n this.bindEvents();\n }\n\n /**\n * 绑定事件\n */\n private bindEvents(): void {\n // 输入框回车事件\n this.valueInput.addEventListener('keypress', event => {\n if (event.key === 'Enter') {\n this.applyFilter();\n }\n });\n\n // 最大值输入框回车事件\n this.valueInputMax.addEventListener('keypress', event => {\n if (event.key === 'Enter') {\n this.applyFilter();\n }\n });\n\n // 分类切换事件\n this.categorySelect.addEventListener('change', () => {\n this.handleCategoryChange();\n });\n\n // 操作符切换事件\n this.operatorSelect.addEventListener('change', () => {\n const selectedOperator = this.operatorSelect.value as FilterOperator;\n const andLabel = this.valueInput.nextElementSibling as HTMLElement;\n\n if (this.isRangeOperator(selectedOperator)) {\n this.valueInput.placeholder = '最小值';\n this.valueInputMax.style.display = 'inline-block';\n andLabel.style.display = 'inline-block';\n } else {\n this.valueInput.placeholder = '请输入筛选值';\n this.valueInputMax.style.display = 'none';\n andLabel.style.display = 'none';\n }\n });\n }\n\n /**\n * 显示筛选面板\n */\n show(): void {\n if (this.filterByConditionPanel) {\n this.filterByConditionPanel.style.display = 'block';\n this.loadCurrentFilterState();\n }\n }\n\n /**\n * 隐藏筛选面板\n */\n hide(): void {\n if (this.filterByConditionPanel) {\n this.filterByConditionPanel.style.display = 'none';\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.operators = exports.categories = void 0;
|
|
6
|
+
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
|
|
9
|
+
exports.categories = [ {
|
|
10
|
+
value: types_1.FilterOperatorCategory.ALL,
|
|
11
|
+
label: "全部"
|
|
12
|
+
}, {
|
|
13
|
+
value: types_1.FilterOperatorCategory.TEXT,
|
|
14
|
+
label: "文本"
|
|
15
|
+
}, {
|
|
16
|
+
value: types_1.FilterOperatorCategory.NUMBER,
|
|
17
|
+
label: "数值"
|
|
18
|
+
}, {
|
|
19
|
+
value: types_1.FilterOperatorCategory.COLOR,
|
|
20
|
+
label: "颜色"
|
|
21
|
+
}, {
|
|
22
|
+
value: types_1.FilterOperatorCategory.CHECKBOX,
|
|
23
|
+
label: "复选框"
|
|
24
|
+
}, {
|
|
25
|
+
value: types_1.FilterOperatorCategory.RADIO,
|
|
26
|
+
label: "单选框"
|
|
27
|
+
} ], exports.operators = [ {
|
|
28
|
+
value: "equals",
|
|
29
|
+
label: "等于",
|
|
30
|
+
category: types_1.FilterOperatorCategory.ALL
|
|
31
|
+
}, {
|
|
32
|
+
value: "notEquals",
|
|
33
|
+
label: "不等于",
|
|
34
|
+
category: types_1.FilterOperatorCategory.ALL
|
|
35
|
+
}, {
|
|
36
|
+
value: "equals",
|
|
37
|
+
label: "等于",
|
|
38
|
+
category: types_1.FilterOperatorCategory.NUMBER
|
|
39
|
+
}, {
|
|
40
|
+
value: "notEquals",
|
|
41
|
+
label: "不等于",
|
|
42
|
+
category: types_1.FilterOperatorCategory.NUMBER
|
|
43
|
+
}, {
|
|
44
|
+
value: "greaterThan",
|
|
45
|
+
label: "大于",
|
|
46
|
+
category: types_1.FilterOperatorCategory.NUMBER
|
|
47
|
+
}, {
|
|
48
|
+
value: "lessThan",
|
|
49
|
+
label: "小于",
|
|
50
|
+
category: types_1.FilterOperatorCategory.NUMBER
|
|
51
|
+
}, {
|
|
52
|
+
value: "greaterThanOrEqual",
|
|
53
|
+
label: "大于等于",
|
|
54
|
+
category: types_1.FilterOperatorCategory.NUMBER
|
|
55
|
+
}, {
|
|
56
|
+
value: "lessThanOrEqual",
|
|
57
|
+
label: "小于等于",
|
|
58
|
+
category: types_1.FilterOperatorCategory.NUMBER
|
|
59
|
+
}, {
|
|
60
|
+
value: "between",
|
|
61
|
+
label: "介于",
|
|
62
|
+
category: types_1.FilterOperatorCategory.NUMBER
|
|
63
|
+
}, {
|
|
64
|
+
value: "notBetween",
|
|
65
|
+
label: "不介于",
|
|
66
|
+
category: types_1.FilterOperatorCategory.NUMBER
|
|
67
|
+
}, {
|
|
68
|
+
value: "equals",
|
|
69
|
+
label: "等于",
|
|
70
|
+
category: types_1.FilterOperatorCategory.TEXT
|
|
71
|
+
}, {
|
|
72
|
+
value: "notEquals",
|
|
73
|
+
label: "不等于",
|
|
74
|
+
category: types_1.FilterOperatorCategory.TEXT
|
|
75
|
+
}, {
|
|
76
|
+
value: "contains",
|
|
77
|
+
label: "包含",
|
|
78
|
+
category: types_1.FilterOperatorCategory.TEXT
|
|
79
|
+
}, {
|
|
80
|
+
value: "notContains",
|
|
81
|
+
label: "不包含",
|
|
82
|
+
category: types_1.FilterOperatorCategory.TEXT
|
|
83
|
+
}, {
|
|
84
|
+
value: "startsWith",
|
|
85
|
+
label: "开头是",
|
|
86
|
+
category: types_1.FilterOperatorCategory.TEXT
|
|
87
|
+
}, {
|
|
88
|
+
value: "notStartsWith",
|
|
89
|
+
label: "开头不是",
|
|
90
|
+
category: types_1.FilterOperatorCategory.TEXT
|
|
91
|
+
}, {
|
|
92
|
+
value: "endsWith",
|
|
93
|
+
label: "结尾是",
|
|
94
|
+
category: types_1.FilterOperatorCategory.TEXT
|
|
95
|
+
}, {
|
|
96
|
+
value: "notEndsWith",
|
|
97
|
+
label: "结尾不是",
|
|
98
|
+
category: types_1.FilterOperatorCategory.TEXT
|
|
99
|
+
}, {
|
|
100
|
+
value: "equals",
|
|
101
|
+
label: "等于",
|
|
102
|
+
category: types_1.FilterOperatorCategory.COLOR
|
|
103
|
+
}, {
|
|
104
|
+
value: "notEquals",
|
|
105
|
+
label: "不等于",
|
|
106
|
+
category: types_1.FilterOperatorCategory.COLOR
|
|
107
|
+
}, {
|
|
108
|
+
value: "isChecked",
|
|
109
|
+
label: "已选中",
|
|
110
|
+
category: types_1.FilterOperatorCategory.CHECKBOX
|
|
111
|
+
}, {
|
|
112
|
+
value: "isUnchecked",
|
|
113
|
+
label: "未选中",
|
|
114
|
+
category: types_1.FilterOperatorCategory.CHECKBOX
|
|
115
|
+
}, {
|
|
116
|
+
value: "isChecked",
|
|
117
|
+
label: "已选中",
|
|
118
|
+
category: types_1.FilterOperatorCategory.RADIO
|
|
119
|
+
}, {
|
|
120
|
+
value: "isUnchecked",
|
|
121
|
+
label: "未选中",
|
|
122
|
+
category: types_1.FilterOperatorCategory.RADIO
|
|
123
|
+
} ];
|
|
124
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/filter/constants.ts"],"names":[],"mappings":";;;AACA,mCAAiD;AAGpC,QAAA,UAAU,GAAG;IACxB,EAAE,KAAK,EAAE,8BAAsB,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE;IAClD,EAAE,KAAK,EAAE,8BAAsB,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;IACnD,EAAE,KAAK,EAAE,8BAAsB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE;IACrD,EAAE,KAAK,EAAE,8BAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE;IACpD,EAAE,KAAK,EAAE,8BAAsB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE;IACxD,EAAE,KAAK,EAAE,8BAAsB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;CACtD,CAAC;AAGW,QAAA,SAAS,GAAqB;IAEzC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,GAAG,EAAE;IACtE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,GAAG,EAAE;IAG1E,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,MAAM,EAAE;IACzE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,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAAsB,CAAC,IAAI,EAAE;IAChF,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,IAAI,EAAE;IAC1E,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAAsB,CAAC,IAAI,EAAE;IAG9E,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,8BAAsB,CAAC,KAAK,EAAE;IACxE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,KAAK,EAAE;IAG5E,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,QAAQ,EAAE;IAC/E,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,QAAQ,EAAE;IAGjF,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,KAAK,EAAE;IAC5E,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,8BAAsB,CAAC,KAAK,EAAE;CAC/E,CAAC","file":"constants.js","sourcesContent":["import type { OperatorOption } from './types';\nimport { FilterOperatorCategory } from './types';\n\n// 分类下拉选项\nexport const categories = [\n { value: FilterOperatorCategory.ALL, label: '全部' },\n { value: FilterOperatorCategory.TEXT, label: '文本' },\n { value: FilterOperatorCategory.NUMBER, label: '数值' },\n { value: FilterOperatorCategory.COLOR, label: '颜色' },\n { value: FilterOperatorCategory.CHECKBOX, label: '复选框' },\n { value: FilterOperatorCategory.RADIO, label: '单选框' }\n];\n\n// 按分类组织的操作符选项\nexport const operators: OperatorOption[] = [\n // 通用操作符 (全部分类中显示)\n { value: 'equals', label: '等于', category: FilterOperatorCategory.ALL },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.ALL },\n\n // 数值操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.NUMBER },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.NUMBER },\n { value: 'greaterThan', label: '大于', category: FilterOperatorCategory.NUMBER },\n { value: 'lessThan', label: '小于', category: FilterOperatorCategory.NUMBER },\n { value: 'greaterThanOrEqual', label: '大于等于', category: FilterOperatorCategory.NUMBER },\n { value: 'lessThanOrEqual', label: '小于等于', category: FilterOperatorCategory.NUMBER },\n { value: 'between', label: '介于', category: FilterOperatorCategory.NUMBER },\n { value: 'notBetween', label: '不介于', category: FilterOperatorCategory.NUMBER },\n\n // 文本操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.TEXT },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.TEXT },\n { value: 'contains', label: '包含', category: FilterOperatorCategory.TEXT },\n { value: 'notContains', label: '不包含', category: FilterOperatorCategory.TEXT },\n { value: 'startsWith', label: '开头是', category: FilterOperatorCategory.TEXT },\n { value: 'notStartsWith', label: '开头不是', category: FilterOperatorCategory.TEXT },\n { value: 'endsWith', label: '结尾是', category: FilterOperatorCategory.TEXT },\n { value: 'notEndsWith', label: '结尾不是', category: FilterOperatorCategory.TEXT },\n\n // 颜色操作符\n { value: 'equals', label: '等于', category: FilterOperatorCategory.COLOR },\n { value: 'notEquals', label: '不等于', category: FilterOperatorCategory.COLOR },\n\n // 复选框操作符\n { value: 'isChecked', label: '已选中', category: FilterOperatorCategory.CHECKBOX },\n { value: 'isUnchecked', label: '未选中', category: FilterOperatorCategory.CHECKBOX },\n\n // 单选框操作符\n { value: 'isChecked', label: '已选中', category: FilterOperatorCategory.RADIO },\n { value: 'isUnchecked', label: '未选中', category: FilterOperatorCategory.RADIO }\n];\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ListTable, PivotTable } from '@visactor/vtable';
|
|
2
|
-
import type { FilterState, FilterAction, FilterConfig } from './types';
|
|
2
|
+
import type { FilterState, FilterAction, FilterConfig, FilterListener } from './types';
|
|
3
3
|
import type { FilterEngine } from './filter-engine';
|
|
4
4
|
export declare class FilterStateManager {
|
|
5
5
|
private state;
|
|
@@ -13,7 +13,7 @@ export declare class FilterStateManager {
|
|
|
13
13
|
getAllFilterStates(): FilterState;
|
|
14
14
|
reapplyCurrentFilters(): void;
|
|
15
15
|
dispatch(action: FilterAction): void;
|
|
16
|
-
subscribe(listener:
|
|
16
|
+
subscribe(listener: FilterListener): () => void;
|
|
17
17
|
private notifyListeners;
|
|
18
18
|
private reduce;
|
|
19
19
|
private applyFilters;
|
|
@@ -29,15 +29,15 @@ class FilterStateManager {
|
|
|
29
29
|
}
|
|
30
30
|
dispatch(action) {
|
|
31
31
|
this.state = this.reduce(this.state, action), this.shouldApplyFilter(action) && this.applyFilters(),
|
|
32
|
-
this.notifyListeners();
|
|
32
|
+
this.notifyListeners(action);
|
|
33
33
|
}
|
|
34
34
|
subscribe(listener) {
|
|
35
35
|
return this.listeners.push(listener), () => {
|
|
36
36
|
this.listeners = this.listeners.filter((l => l !== listener));
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
notifyListeners() {
|
|
40
|
-
this.listeners.forEach((listener => listener(this.state)));
|
|
39
|
+
notifyListeners(action) {
|
|
40
|
+
this.listeners.forEach((listener => listener(this.state, action)));
|
|
41
41
|
}
|
|
42
42
|
reduce(state, action) {
|
|
43
43
|
const {type: type, payload: payload} = action, newFilter = new Map(state.filters);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":";;;AAGA,mCAA2C;AAO3C,MAAa,kBAAkB;IAoB7B,YAAY,KAA6B,EAAE,MAAoB;QAjBvD,cAAS,GAAwC,EAAE,CAAC;QAKpD,qBAAgB,GAUpB,IAAI,GAA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S,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;gBACxG,IAAI,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;oBACnC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;iBAC/B;aACF;SACF;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAKD,uBAAuB,CAAC,OAAwB;;QAC9C,OAAO,CAAA,MAAA,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,0CAAE,oBAAoB,KAAI,EAAE,CAAC;IACxE,CAAC;CACF;AAlND,gDAkNC","file":"filter-state-manager.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { ColumnDefine } from '@visactor/vtable/es/ts-types';\nimport type { FilterState, FilterAction, FilterConfig } from './types';\nimport { FilterActionType } from './types';\nimport type { FilterEngine } from './filter-engine';\nimport type { FilterPlugin } from '../filter';\n\n/**\n * 筛选状态管理器,用于管理筛选状态\n */\nexport class FilterStateManager {\n private state: FilterState;\n private engine: FilterEngine;\n private listeners: Array<(state: FilterState) => void> = [];\n\n private table: ListTable | PivotTable;\n\n // 筛选菜单相关的状态\n private filterMenuStates: Map<\n string | number,\n {\n // 筛选菜单打开时固定的候选值列表\n stableCandidateValues: Array<{ value: any; count: number; rawValue: any }>;\n // 当前搜索关键词\n currentSearchKeyword: string;\n // 显示值到原始值的映射\n displayToRawMap: Map<any, any>;\n }\n > = new Map();\n\n constructor(table: ListTable | PivotTable, engine: FilterEngine) {\n this.state = {\n filters: new Map()\n };\n this.engine = engine;\n this.table = table;\n }\n\n getFilterState(fieldId?: string | number): FilterConfig {\n return this.state.filters.get(fieldId);\n }\n\n /**\n * 获取所有激活的筛选字段\n */\n getActiveFilterFields(): (string | number)[] {\n const activeFields: (string | number)[] = [];\n this.state.filters.forEach((config, field) => {\n if (config.enable) {\n activeFields.push(field);\n }\n });\n return activeFields;\n }\n\n /**\n * 获取所有筛选状态\n */\n getAllFilterStates(): FilterState {\n return this.state;\n }\n\n /**\n * 公共方法:重新应用当前所有激活的筛选状态\n * 用于在表格配置更新后恢复筛选显示\n */\n reapplyCurrentFilters(): void {\n const activeFields = this.getActiveFilterFields();\n if (activeFields.length > 0) {\n this.applyFilters();\n }\n }\n\n dispatch(action: FilterAction) {\n this.state = this.reduce(this.state, action);\n if (this.shouldApplyFilter(action)) {\n this.applyFilters();\n }\n this.notifyListeners();\n }\n\n subscribe(listener: (state: FilterState) => void): () => void {\n this.listeners.push(listener);\n return () => {\n this.listeners = this.listeners.filter(l => l !== listener);\n };\n }\n\n private notifyListeners(): void {\n this.listeners.forEach(listener => listener(this.state));\n }\n\n private reduce(state: FilterState, action: FilterAction): FilterState {\n const { type, payload } = action;\n const newFilter = new Map(state.filters);\n switch (type) {\n case FilterActionType.ADD_FILTER:\n newFilter.set(payload.field, payload);\n break;\n case FilterActionType.REMOVE_FILTER:\n newFilter.delete(payload.field);\n break;\n case FilterActionType.UPDATE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload });\n break;\n case FilterActionType.ENABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: true });\n break;\n case FilterActionType.DISABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });\n break;\n case FilterActionType.CLEAR_ALL_FILTERS:\n newFilter.clear();\n break;\n case FilterActionType.APPLY_FILTERS:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload, enable: true });\n break;\n }\n\n return { ...state, filters: newFilter };\n }\n\n private applyFilters() {\n this.engine.applyFilter(this.state, this.table);\n }\n\n private shouldApplyFilter(action: FilterAction) {\n const shouldApplyActions = [\n FilterActionType.REMOVE_FILTER,\n FilterActionType.ENABLE_FILTER,\n FilterActionType.DISABLE_FILTER,\n FilterActionType.CLEAR_ALL_FILTERS,\n FilterActionType.APPLY_FILTERS\n ];\n return shouldApplyActions.includes(action.type) || action.payload.enable;\n }\n\n /**\n * 初始化筛选菜单状态(当筛选菜单打开时调用)\n */\n initializeFilterMenuState(\n fieldId: string | number,\n candidateValues: Array<{ value: any; count: number; rawValue: any }>,\n displayToRawMap: Map<any, any>\n ): void {\n this.filterMenuStates.set(fieldId, {\n stableCandidateValues: candidateValues,\n currentSearchKeyword: '',\n displayToRawMap: displayToRawMap\n });\n }\n\n /**\n * 获取筛选菜单的稳定候选值列表\n */\n getStableCandidateValues(fieldId: string | number): Array<{ value: any; count: number; rawValue: any }> {\n return this.filterMenuStates.get(fieldId)?.stableCandidateValues || [];\n }\n\n /**\n * 更新搜索关键词\n */\n updateSearchKeyword(fieldId: string | number, keyword: string): void {\n const menuState = this.filterMenuStates.get(fieldId);\n if (!menuState) {\n return;\n }\n\n menuState.currentSearchKeyword = keyword;\n }\n\n /**\n * 获取当前可见的选中值(根据搜索关键词从筛选状态中筛选)\n */\n getVisibleSelectedValues(fieldId: string | number): Set<any> {\n const menuState = this.filterMenuStates.get(fieldId);\n const filter = this.getFilterState(fieldId);\n if (!menuState || !filter?.values) {\n return new Set();\n }\n\n const allSelectedValues = new Set(filter.values);\n const keyword = menuState.currentSearchKeyword;\n const filterKeywords = keyword\n .toUpperCase()\n .split(' ')\n .filter(s => s);\n\n // 如果没有搜索关键词,返回所有被选中的值\n if (filterKeywords.length === 0) {\n return allSelectedValues;\n }\n\n // 根据搜索关键词筛选出可见的选中值\n const visibleSelected = new Set<any>();\n for (const candidate of menuState.stableCandidateValues) {\n const displayValue = candidate.value;\n const txtValue = String(displayValue).toUpperCase();\n\n // 检查是否匹配搜索关键词\n const match = filterKeywords.some(keyword => txtValue.includes(keyword));\n\n if (match) {\n // 如果可见,检查是否被选中\n const rawValue = menuState.displayToRawMap ? menuState.displayToRawMap.get(displayValue) : displayValue;\n if (allSelectedValues.has(rawValue)) {\n visibleSelected.add(rawValue);\n }\n }\n }\n\n return visibleSelected;\n }\n\n /**\n * 获取当前搜索关键词\n */\n getCurrentSearchKeyword(fieldId: string | number): string {\n return this.filterMenuStates.get(fieldId)?.currentSearchKeyword || '';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/filter/filter-state-manager.ts"],"names":[],"mappings":";;;AAEA,mCAA2C;AAM3C,MAAa,kBAAkB;IAoB7B,YAAY,KAA6B,EAAE,MAAoB;QAjBvD,cAAS,GAA0B,EAAE,CAAC;QAKtC,qBAAgB,GAUpB,IAAI,GAAG,EAAE,CAAC;QAGZ,IAAI,CAAC,KAAK,GAAG;YACX,OAAO,EAAE,IAAI,GAAG,EAAE;SACnB,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,cAAc,CAAC,OAAyB;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAKD,qBAAqB;QACnB,MAAM,YAAY,GAAwB,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAC3C,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC1B;QACH,CAAC,CAAC,CAAC;QACH,OAAO,YAAY,CAAC;IACtB,CAAC;IAKD,kBAAkB;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAMD,qBAAqB;QACnB,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAClD,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3B,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;IACH,CAAC;IAED,QAAQ,CAAC,MAAoB;QAC3B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE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,IAAI,SAAS,CAAC,qBAAqB,EAAE;YACvD,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC;YACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;YAGpD,MAAM,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAEzE,IAAI,KAAK,EAAE;gBAET,MAAM,QAAQ,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;gBACxG,IAAI,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;oBACnC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;iBAC/B;aACF;SACF;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAKD,uBAAuB,CAAC,OAAwB;;QAC9C,OAAO,CAAA,MAAA,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,0CAAE,oBAAoB,KAAI,EAAE,CAAC;IACxE,CAAC;CACF;AAlND,gDAkNC","file":"filter-state-manager.js","sourcesContent":["import type { ListTable, PivotTable } from '@visactor/vtable';\nimport type { FilterState, FilterAction, FilterConfig, FilterListener } from './types';\nimport { FilterActionType } from './types';\nimport type { FilterEngine } from './filter-engine';\n\n/**\n * 筛选状态管理器,用于管理筛选状态\n */\nexport class FilterStateManager {\n private state: FilterState;\n private engine: FilterEngine;\n private listeners: Array<FilterListener> = [];\n\n private table: ListTable | PivotTable;\n\n // 筛选菜单相关的状态\n private filterMenuStates: Map<\n string | number,\n {\n // 筛选菜单打开时固定的候选值列表\n stableCandidateValues: Array<{ value: any; count: number; rawValue: any }>;\n // 当前搜索关键词\n currentSearchKeyword: string;\n // 显示值到原始值的映射\n displayToRawMap: Map<any, any>;\n }\n > = new Map();\n\n constructor(table: ListTable | PivotTable, engine: FilterEngine) {\n this.state = {\n filters: new Map()\n };\n this.engine = engine;\n this.table = table;\n }\n\n getFilterState(fieldId?: string | number): FilterConfig {\n return this.state.filters.get(fieldId);\n }\n\n /**\n * 获取所有激活的筛选字段\n */\n getActiveFilterFields(): (string | number)[] {\n const activeFields: (string | number)[] = [];\n this.state.filters.forEach((config, field) => {\n if (config.enable) {\n activeFields.push(field);\n }\n });\n return activeFields;\n }\n\n /**\n * 获取所有筛选状态\n */\n getAllFilterStates(): FilterState {\n return this.state;\n }\n\n /**\n * 公共方法:重新应用当前所有激活的筛选状态\n * 用于在表格配置更新后恢复筛选显示\n */\n reapplyCurrentFilters(): void {\n const activeFields = this.getActiveFilterFields();\n if (activeFields.length > 0) {\n this.applyFilters();\n }\n }\n\n dispatch(action: FilterAction) {\n this.state = this.reduce(this.state, action);\n if (this.shouldApplyFilter(action)) {\n this.applyFilters();\n }\n this.notifyListeners(action);\n }\n\n subscribe(listener: FilterListener): () => void {\n this.listeners.push(listener);\n return () => {\n this.listeners = this.listeners.filter(l => l !== listener);\n };\n }\n\n private notifyListeners(action: FilterAction): void {\n this.listeners.forEach(listener => listener(this.state, action));\n }\n\n private reduce(state: FilterState, action: FilterAction): FilterState {\n const { type, payload } = action;\n const newFilter = new Map(state.filters);\n switch (type) {\n case FilterActionType.ADD_FILTER:\n newFilter.set(payload.field, payload);\n break;\n case FilterActionType.REMOVE_FILTER:\n newFilter.delete(payload.field);\n break;\n case FilterActionType.UPDATE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload });\n break;\n case FilterActionType.ENABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: true });\n break;\n case FilterActionType.DISABLE_FILTER:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), enable: false });\n break;\n case FilterActionType.CLEAR_ALL_FILTERS:\n newFilter.clear();\n break;\n case FilterActionType.APPLY_FILTERS:\n newFilter.set(payload.field, { ...newFilter.get(payload.field), ...payload, enable: true });\n break;\n }\n\n return { ...state, filters: newFilter };\n }\n\n private applyFilters() {\n this.engine.applyFilter(this.state, this.table);\n }\n\n private shouldApplyFilter(action: FilterAction) {\n const shouldApplyActions = [\n FilterActionType.REMOVE_FILTER,\n FilterActionType.ENABLE_FILTER,\n FilterActionType.DISABLE_FILTER,\n FilterActionType.CLEAR_ALL_FILTERS,\n FilterActionType.APPLY_FILTERS\n ];\n return shouldApplyActions.includes(action.type) || action.payload.enable;\n }\n\n /**\n * 初始化筛选菜单状态(当筛选菜单打开时调用)\n */\n initializeFilterMenuState(\n fieldId: string | number,\n candidateValues: Array<{ value: any; count: number; rawValue: any }>,\n displayToRawMap: Map<any, any>\n ): void {\n this.filterMenuStates.set(fieldId, {\n stableCandidateValues: candidateValues,\n currentSearchKeyword: '',\n displayToRawMap: displayToRawMap\n });\n }\n\n /**\n * 获取筛选菜单的稳定候选值列表\n */\n getStableCandidateValues(fieldId: string | number): Array<{ value: any; count: number; rawValue: any }> {\n return this.filterMenuStates.get(fieldId)?.stableCandidateValues || [];\n }\n\n /**\n * 更新搜索关键词\n */\n updateSearchKeyword(fieldId: string | number, keyword: string): void {\n const menuState = this.filterMenuStates.get(fieldId);\n if (!menuState) {\n return;\n }\n\n menuState.currentSearchKeyword = keyword;\n }\n\n /**\n * 获取当前可见的选中值(根据搜索关键词从筛选状态中筛选)\n */\n getVisibleSelectedValues(fieldId: string | number): Set<any> {\n const menuState = this.filterMenuStates.get(fieldId);\n const filter = this.getFilterState(fieldId);\n if (!menuState || !filter?.values) {\n return new Set();\n }\n\n const allSelectedValues = new Set(filter.values);\n const keyword = menuState.currentSearchKeyword;\n const filterKeywords = keyword\n .toUpperCase()\n .split(' ')\n .filter(s => s);\n\n // 如果没有搜索关键词,返回所有被选中的值\n if (filterKeywords.length === 0) {\n return allSelectedValues;\n }\n\n // 根据搜索关键词筛选出可见的选中值\n const visibleSelected = new Set<any>();\n for (const candidate of menuState.stableCandidateValues) {\n const displayValue = candidate.value;\n const txtValue = String(displayValue).toUpperCase();\n\n // 检查是否匹配搜索关键词\n const match = filterKeywords.some(keyword => txtValue.includes(keyword));\n\n if (match) {\n // 如果可见,检查是否被选中\n const rawValue = menuState.displayToRawMap ? menuState.displayToRawMap.get(displayValue) : displayValue;\n if (allSelectedValues.has(rawValue)) {\n visibleSelected.add(rawValue);\n }\n }\n }\n\n return visibleSelected;\n }\n\n /**\n * 获取当前搜索关键词\n */\n getCurrentSearchKeyword(fieldId: string | number): string {\n return this.filterMenuStates.get(fieldId)?.currentSearchKeyword || '';\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { ListTable, PivotTable } from '@visactor/vtable';
|
|
|
2
2
|
import type { FilterStateManager } from './filter-state-manager';
|
|
3
3
|
import { ValueFilter } from './value-filter';
|
|
4
4
|
import { ConditionFilter } from './condition-filter';
|
|
5
|
-
import type { FilterMode, FilterStyles } from './types';
|
|
5
|
+
import type { FilterMode, FilterOperatorCategoryOption, FilterStyles } from './types';
|
|
6
6
|
export declare class FilterToolbar {
|
|
7
7
|
table: ListTable | PivotTable;
|
|
8
8
|
filterStateManager: FilterStateManager;
|
|
@@ -22,7 +22,7 @@ export declare class FilterToolbar {
|
|
|
22
22
|
private clearFilterOptionLink;
|
|
23
23
|
private cancelFilterButton;
|
|
24
24
|
private applyFilterButton;
|
|
25
|
-
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, styles: FilterStyles);
|
|
25
|
+
constructor(table: ListTable | PivotTable, filterStateManager: FilterStateManager, styles: FilterStyles, conditionCategories: FilterOperatorCategoryOption[]);
|
|
26
26
|
private onTabSwitch;
|
|
27
27
|
private updateSelectedField;
|
|
28
28
|
private applyFilter;
|
|
@@ -7,11 +7,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
const value_filter_1 = require("./value-filter"), condition_filter_1 = require("./condition-filter"), styles_1 = require("./styles");
|
|
8
8
|
|
|
9
9
|
class FilterToolbar {
|
|
10
|
-
constructor(table, filterStateManager, styles) {
|
|
10
|
+
constructor(table, filterStateManager, styles, conditionCategories) {
|
|
11
11
|
this.valueFilter = null, this.conditionFilter = null, this.activeTab = "byValue",
|
|
12
12
|
this.isVisible = !1, this.selectedField = null, this.filterModes = [], this.table = table,
|
|
13
13
|
this.filterStateManager = filterStateManager, this.styles = styles, this.valueFilter = new value_filter_1.ValueFilter(this.table, this.filterStateManager, this.styles),
|
|
14
|
-
this.conditionFilter = new condition_filter_1.ConditionFilter(this.table, this.filterStateManager, this.styles),
|
|
14
|
+
this.conditionFilter = new condition_filter_1.ConditionFilter(this.table, this.filterStateManager, this.styles, conditionCategories),
|
|
15
15
|
this.filterMenuWidth = 300, this.filterStateManager.subscribe((state => {
|
|
16
16
|
this.isVisible && null !== this.selectedField && this.updateClearFilterButtonState(this.selectedField);
|
|
17
17
|
}));
|
|
@@ -92,7 +92,7 @@ class FilterToolbar {
|
|
|
92
92
|
this.filterMenu.style.left = `${left}px`, this.filterMenu.style.top = `${top}px`;
|
|
93
93
|
}
|
|
94
94
|
show(col, row, filterModes) {
|
|
95
|
-
this.filterModes = filterModes, this.filterModes.includes("byValue") ? this.filterModes.includes("byCondition") || (this.filterTabByCondition.style.display = "none",
|
|
95
|
+
this.valueFilter.clearSearchInputValue(), this.filterModes = filterModes, this.filterModes.includes("byValue") ? this.filterModes.includes("byCondition") || (this.filterTabByCondition.style.display = "none",
|
|
96
96
|
this.onTabSwitch("byValue")) : (this.filterTabByValue.style.display = "none", this.onTabSwitch("byCondition")),
|
|
97
97
|
this.adjustMenuPosition(col, row), this.filterMenu.style.display = "block";
|
|
98
98
|
const field = this.table.internalProps.layoutMap.getHeaderField(col, row);
|