plain-design 1.0.0-beta.159 → 1.0.0-beta.160
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/dist/plain-design.commonjs.min.js +1 -1
- package/dist/plain-design.min.js +1 -1
- package/dist/report.html +2 -2
- package/package.json +1 -1
- package/src/packages/components/AutoTable/filter/useTableOption.filter.state.ts +4 -1
- package/src/packages/components/AutoTable/setting/useTableOption.setting.senior.filter.tsx +388 -385
- package/src/packages/components/AutoTable/setting/useTableOption.setting.tsx +109 -109
- package/src/packages/components/Checkbox/index.tsx +4 -6
|
@@ -1,385 +1,388 @@
|
|
|
1
|
-
import {eAutoTableFilterMode} from "../filter/useTableOption.filter.state";
|
|
2
|
-
import {computed, Fragment, iMouseEvent, reactive, RenderNode, useRefList} from "@peryl/react-compose";
|
|
3
|
-
import {FilterFormSingle, iFilterFormSingleData} from "../../FilterFormSingle";
|
|
4
|
-
import {eTableOptionSettingView} from "./useTableOption.setting.utils";
|
|
5
|
-
import {Button} from "../../Button";
|
|
6
|
-
import {Checkbox} from "../../Checkbox";
|
|
7
|
-
import {Input} from "../../Input";
|
|
8
|
-
import {Empty} from "../../Empty";
|
|
9
|
-
import {iFilterQueryMeta} from "../../FilterService/utils/filter.service.utils";
|
|
10
|
-
import {$message} from "../../$message";
|
|
11
|
-
import {delay} from "@peryl/utils/delay";
|
|
12
|
-
import {Icon} from "../../Icon";
|
|
13
|
-
import {doNothing} from "@peryl/utils/doNothing";
|
|
14
|
-
import {deepcopy} from "@peryl/utils/deepcopy";
|
|
15
|
-
import {TableOptionSpace} from "../utils/TableOption.space";
|
|
16
|
-
import '../utils/TableOption.space';
|
|
17
|
-
import {TableOptionUtils} from "../utils/TableOption.utils";
|
|
18
|
-
import i18n from "../../i18n";
|
|
19
|
-
import {AutoModule} from "../utils/AutoModule";
|
|
20
|
-
|
|
21
|
-
declare module '../utils/TableOption.space' {
|
|
22
|
-
namespace TableOptionSpace {
|
|
23
|
-
interface iTableOption {
|
|
24
|
-
settingSeniorFilter: ReturnType<typeof useTableOptionSettingSeniorFilter>;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const useTableOptionSettingSeniorFilter = AutoModule.createRegistration((
|
|
30
|
-
{
|
|
31
|
-
cache,
|
|
32
|
-
setting,
|
|
33
|
-
hooks,
|
|
34
|
-
methods,
|
|
35
|
-
filterState,
|
|
36
|
-
}
|
|
37
|
-
) => {
|
|
38
|
-
|
|
39
|
-
const { refList, onRefList } = useRefList(FilterFormSingle);
|
|
40
|
-
|
|
41
|
-
const filterOptions = filterState.createComputedFilterOptions(eAutoTableFilterMode.filterSenior);
|
|
42
|
-
|
|
43
|
-
const utils = {
|
|
44
|
-
/*按照F_1, F_2, F_3...的规则生成ID*/
|
|
45
|
-
nextId: (() => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (!
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
edit
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
{
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
</div>
|
|
233
|
-
<
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
1
|
+
import {eAutoTableFilterMode} from "../filter/useTableOption.filter.state";
|
|
2
|
+
import {computed, Fragment, iMouseEvent, reactive, RenderNode, useRefList} from "@peryl/react-compose";
|
|
3
|
+
import {FilterFormSingle, iFilterFormSingleData} from "../../FilterFormSingle";
|
|
4
|
+
import {eTableOptionSettingView} from "./useTableOption.setting.utils";
|
|
5
|
+
import {Button} from "../../Button";
|
|
6
|
+
import {Checkbox} from "../../Checkbox";
|
|
7
|
+
import {Input} from "../../Input";
|
|
8
|
+
import {Empty} from "../../Empty";
|
|
9
|
+
import {iFilterQueryMeta} from "../../FilterService/utils/filter.service.utils";
|
|
10
|
+
import {$message} from "../../$message";
|
|
11
|
+
import {delay} from "@peryl/utils/delay";
|
|
12
|
+
import {Icon} from "../../Icon";
|
|
13
|
+
import {doNothing} from "@peryl/utils/doNothing";
|
|
14
|
+
import {deepcopy} from "@peryl/utils/deepcopy";
|
|
15
|
+
import {TableOptionSpace} from "../utils/TableOption.space";
|
|
16
|
+
import '../utils/TableOption.space';
|
|
17
|
+
import {TableOptionUtils} from "../utils/TableOption.utils";
|
|
18
|
+
import i18n from "../../i18n";
|
|
19
|
+
import {AutoModule} from "../utils/AutoModule";
|
|
20
|
+
|
|
21
|
+
declare module '../utils/TableOption.space' {
|
|
22
|
+
namespace TableOptionSpace {
|
|
23
|
+
interface iTableOption {
|
|
24
|
+
settingSeniorFilter: ReturnType<typeof useTableOptionSettingSeniorFilter>;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const useTableOptionSettingSeniorFilter = AutoModule.createRegistration((
|
|
30
|
+
{
|
|
31
|
+
cache,
|
|
32
|
+
setting,
|
|
33
|
+
hooks,
|
|
34
|
+
methods,
|
|
35
|
+
filterState,
|
|
36
|
+
}
|
|
37
|
+
) => {
|
|
38
|
+
|
|
39
|
+
const { refList, onRefList } = useRefList(FilterFormSingle);
|
|
40
|
+
|
|
41
|
+
const filterOptions = filterState.createComputedFilterOptions(eAutoTableFilterMode.filterSenior);
|
|
42
|
+
|
|
43
|
+
const utils = {
|
|
44
|
+
/*按照F_1, F_2, F_3...的规则生成ID*/
|
|
45
|
+
nextId: (() => {
|
|
46
|
+
/*这里maxCount使用computed,导致出现异常*/
|
|
47
|
+
/*第二次打开高级筛选配置页面的时候,点击添加触发这里会导致内容渲染异常,这里把computed去掉*/
|
|
48
|
+
const maxCount = () => {
|
|
49
|
+
const max = edit.state.metas.reduce((prev, item) => {
|
|
50
|
+
let [_, val] = item.id.split('_');
|
|
51
|
+
const v = Number(val);
|
|
52
|
+
return !isNaN(v) && v > prev ? v : prev;
|
|
53
|
+
}, 0);
|
|
54
|
+
return Math.max(max, edit.state.metas.length);
|
|
55
|
+
};
|
|
56
|
+
return () => `F_${maxCount() + 1}`;
|
|
57
|
+
})(),
|
|
58
|
+
/*重置查询表达式*/
|
|
59
|
+
resetOperator: () => {
|
|
60
|
+
edit.state.expression = edit.getDefaultExpression();
|
|
61
|
+
},
|
|
62
|
+
/*创建初始状态变量*/
|
|
63
|
+
createState: () => {
|
|
64
|
+
const state: iTableOptionSeniorData = ({
|
|
65
|
+
/*iTableOptionSeniorFilterMeta*/
|
|
66
|
+
metas: [],
|
|
67
|
+
/*查询表达式*/
|
|
68
|
+
expression: null,
|
|
69
|
+
/*当前是否开启自定义表达式*/
|
|
70
|
+
isCustomExpression: true,
|
|
71
|
+
});
|
|
72
|
+
/*默认的查询表达式*/
|
|
73
|
+
const getDefaultExpression = (): string => state.metas.map(i => i.id).join(` ${DEFAULT_EXPRESSION_JOIN} `);
|
|
74
|
+
return {
|
|
75
|
+
state, getDefaultExpression,
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 查询的时候的数据
|
|
82
|
+
* @author 韦胜健
|
|
83
|
+
* @date 2021/7/22 21:05
|
|
84
|
+
*/
|
|
85
|
+
const query = (() => {
|
|
86
|
+
const { state: _state, getDefaultExpression } = utils.createState();
|
|
87
|
+
const state = reactive(_state);
|
|
88
|
+
|
|
89
|
+
const apply = async (autoReload: boolean) => {
|
|
90
|
+
await delay();
|
|
91
|
+
const dataList = refList.length === 0 ? [] : await Promise.all(refList.map(i => i.getData()));
|
|
92
|
+
const metas = !isSettingSeniorOpen() ? edit.state.metas : dataList.map((data, index) => ({ data, id: edit.state.metas[index].id }));
|
|
93
|
+
/*检查每一个条件是否输入正确*/
|
|
94
|
+
const invalidIndex = metas.findIndex(i => !i.data || !i.data.filterQueryParam || !i.data.filterQueryParam.queries?.length);
|
|
95
|
+
if (invalidIndex > -1) {
|
|
96
|
+
$message.error(i18n.$it('table.pleaseEnterCompleteParamsForCondition', { invalidIndex: invalidIndex + 1 }).d(`第${invalidIndex + 1}个条件请输入完整参数!`));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
state.metas = metas;
|
|
100
|
+
state.expression = edit.state.expression;
|
|
101
|
+
state.isCustomExpression = edit.state.isCustomExpression;
|
|
102
|
+
|
|
103
|
+
if (autoReload) {await methods.pageMethods.reload();}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
state,
|
|
108
|
+
getDefaultExpression,
|
|
109
|
+
apply,
|
|
110
|
+
};
|
|
111
|
+
})();
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 编辑的时候的数据
|
|
115
|
+
* @author 韦胜健
|
|
116
|
+
* @date 2021/7/22 21:05
|
|
117
|
+
*/
|
|
118
|
+
const edit = (() => {
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 状态需要与query同步初始化,因为应用的时候可能filter form single没有初始化,此时应该用edit的状态
|
|
122
|
+
* 因为 edit.remove 删除的是edit内部的状态
|
|
123
|
+
* @author 韦胜健
|
|
124
|
+
* @date 2023.1.15 22:11
|
|
125
|
+
*/
|
|
126
|
+
const { state: _state, getDefaultExpression } = utils.createState();
|
|
127
|
+
const state = reactive(_state);
|
|
128
|
+
|
|
129
|
+
const add = () => {
|
|
130
|
+
const id = utils.nextId();
|
|
131
|
+
if (state.metas.length === 0) {
|
|
132
|
+
state.expression = id;
|
|
133
|
+
} else {
|
|
134
|
+
state.expression += ` ${DEFAULT_EXPRESSION_JOIN} ${id}`;
|
|
135
|
+
}
|
|
136
|
+
state.metas.push({ id, data: undefined });
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const remove = (index: number) => {
|
|
140
|
+
const isMatchDefaultOperator = !!state.expression && state.expression.trim() === getDefaultExpression();
|
|
141
|
+
state.metas.splice(index, 1);
|
|
142
|
+
if (isMatchDefaultOperator) {state.expression = getDefaultExpression();}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const clear = async (autoReload: boolean) => {
|
|
146
|
+
Object.assign(state, utils.createState().state);
|
|
147
|
+
await query.apply(autoReload);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
state,
|
|
152
|
+
getDefaultExpression,
|
|
153
|
+
|
|
154
|
+
add,
|
|
155
|
+
remove,
|
|
156
|
+
clear,
|
|
157
|
+
};
|
|
158
|
+
})();
|
|
159
|
+
|
|
160
|
+
cache.registry<iTableOptionSeniorData>({
|
|
161
|
+
cacheKey: 'filter-state-senior',
|
|
162
|
+
applyCache: ({ plcList, cacheData }) => {
|
|
163
|
+
query.state.isCustomExpression = !cacheData ? false : cacheData.isCustomExpression;
|
|
164
|
+
query.state.expression = !cacheData ? null : cacheData.expression;
|
|
165
|
+
query.state.metas = !cacheData ? [] : cacheData.metas.map(item => {
|
|
166
|
+
/*有些字段可能从代码中去掉了,这里将无效的字段对应的缓存筛选条件去除*/
|
|
167
|
+
if (!item.data?.field) {return null;}
|
|
168
|
+
const { field } = item.data || {};
|
|
169
|
+
const plc = plcList.find(i => i.props.searchField === field || i.props.field === field);
|
|
170
|
+
if (!plc) {return null;}
|
|
171
|
+
return item;
|
|
172
|
+
}).filter(Boolean) as iTableOptionSeniorFilterMeta[];
|
|
173
|
+
/*同步edit与query的状态*/
|
|
174
|
+
edit.state.metas = deepcopy(query.state.metas);
|
|
175
|
+
edit.state.expression = query.state.expression;
|
|
176
|
+
edit.state.isCustomExpression = query.state.isCustomExpression;
|
|
177
|
+
},
|
|
178
|
+
getCache: () => {
|
|
179
|
+
return {
|
|
180
|
+
expression: query.state.expression,
|
|
181
|
+
metas: query.state.metas,
|
|
182
|
+
isCustomExpression: query.state.isCustomExpression,
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const { isOpen: isSettingSeniorOpen } = setting.useTableOptionSettingInner({
|
|
188
|
+
key: eTableOptionSettingView.seniorFilter,
|
|
189
|
+
title: i18n.$it('table.seniorFilter').d('高级筛选'),
|
|
190
|
+
seq: 1,
|
|
191
|
+
beforeOpen: () => {
|
|
192
|
+
edit.state.metas = deepcopy(query.state.metas);
|
|
193
|
+
edit.state.expression = query.state.expression;
|
|
194
|
+
edit.state.isCustomExpression = query.state.isCustomExpression;
|
|
195
|
+
},
|
|
196
|
+
render: () => {
|
|
197
|
+
refList.splice(0, refList.length);
|
|
198
|
+
|
|
199
|
+
const apply = () => query.apply(true);
|
|
200
|
+
const clear = () => edit.clear(true);
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<div className="auto-table-setting-senior-filter">
|
|
204
|
+
<div className="auto-table-setting-senior-filter-button">
|
|
205
|
+
<div>
|
|
206
|
+
<Button label={i18n.$it('base.edit.apply').d('应用')} onClick={apply} mode="fill" icon="pi-find-replace"/>
|
|
207
|
+
<Button label={i18n.$it('base.edit.add').d('添加')} onClick={edit.add} icon="pi-plus"/>
|
|
208
|
+
</div>
|
|
209
|
+
<Button label={i18n.$it('base.clear').d('清空')} icon="pi-delete" status="error" onClick={clear}/>
|
|
210
|
+
</div>
|
|
211
|
+
<div className="auto-table-setting-senior-filter-list">
|
|
212
|
+
{edit.state.metas.length === 0 ? (
|
|
213
|
+
<Empty noData label={i18n.$it('table.pleaseAddFilterCondition').d('请添加筛选条件')}/>
|
|
214
|
+
) : (
|
|
215
|
+
edit.state.metas.map((meta, index) => (
|
|
216
|
+
<div key={meta.id} className="auto-table-setting-senior-filter-list-item">
|
|
217
|
+
<FilterFormSingle
|
|
218
|
+
ref={onRefList(index)}
|
|
219
|
+
filterOptions={filterOptions.value}
|
|
220
|
+
initialState={meta.data}
|
|
221
|
+
onSearch={apply}
|
|
222
|
+
width="calc(100% - 40px)"
|
|
223
|
+
hideSearchButton
|
|
224
|
+
v-slots={{
|
|
225
|
+
prepend: () => (<Input readonly modelValue={meta.id} width={60}/>)
|
|
226
|
+
}}
|
|
227
|
+
/>
|
|
228
|
+
<Button icon="pi-delete" onClick={() => edit.remove(index)}/>
|
|
229
|
+
</div>
|
|
230
|
+
))
|
|
231
|
+
)}
|
|
232
|
+
</div>
|
|
233
|
+
<div className="auto-table-setting-senior-filter-expression-header">
|
|
234
|
+
<div className="auto-table-setting-senior-filter-expression-title">{i18n.$it('table.expression').d('表达式')}</div>
|
|
235
|
+
</div>
|
|
236
|
+
<Input textarea v-model={edit.state.expression} disabled={!edit.state.isCustomExpression}/>
|
|
237
|
+
<Checkbox label={i18n.$it('base.custom').d('自定义')} v-model={edit.state.isCustomExpression} onChange={utils.resetOperator}/>
|
|
238
|
+
</div>
|
|
239
|
+
);
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 获取查询参数时返回当前绑定的参数
|
|
245
|
+
* @author 韦胜健
|
|
246
|
+
* @date 2023.1.8 19:09
|
|
247
|
+
*/
|
|
248
|
+
hooks.onQueryParam.use(async () => {
|
|
249
|
+
let expression = !query.state.isCustomExpression || !query.state.expression ? query.getDefaultExpression() : query.state.expression;
|
|
250
|
+
/*处理空格*/
|
|
251
|
+
expression = expression.replace(/\s*(\|\||&&|或者|并且|or|and)\s*/gi, ' $1 ').replace(/\s+/, ' ');
|
|
252
|
+
/*目标queries数组*/
|
|
253
|
+
const resultQueries: iFilterQueryMeta[] = [];
|
|
254
|
+
|
|
255
|
+
/*id映射senior meta查询参数*/
|
|
256
|
+
const idToSeniorMeta: Record<string, iTableOptionSeniorFilterMeta & { index: number }> = query.state.metas.reduce((prev, item) => {
|
|
257
|
+
prev[item.id] = item;
|
|
258
|
+
return prev;
|
|
259
|
+
}, {} as any);
|
|
260
|
+
|
|
261
|
+
expression = expression.replace(/\w+/g, (input) => {
|
|
262
|
+
if (ExpressionJoins.indexOf(input) > -1) {return input;}
|
|
263
|
+
const senior = idToSeniorMeta[input];
|
|
264
|
+
if (!senior || !senior.data) {return input;}
|
|
265
|
+
const { queries } = senior.data.filterQueryParam;
|
|
266
|
+
if (!queries || queries.length === 0) {return input;}
|
|
267
|
+
if (queries.length === 1) {
|
|
268
|
+
queries[0].id = input;
|
|
269
|
+
resultQueries.push(...queries);
|
|
270
|
+
return input;
|
|
271
|
+
}
|
|
272
|
+
const itemQueryIds: string[] = [];
|
|
273
|
+
queries.forEach((i, idx) => {
|
|
274
|
+
const itemId = `${input}-${idx + 1}`;
|
|
275
|
+
itemQueryIds.push(itemId);
|
|
276
|
+
resultQueries.push({
|
|
277
|
+
...i,
|
|
278
|
+
id: itemId,
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
return `(${itemQueryIds.join(' 并且 ')})`;
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// console.log(resultQueries.length === 0 ? null : { queries: resultQueries, expression: expression });
|
|
285
|
+
|
|
286
|
+
return resultQueries.length === 0 ? null : { queries: resultQueries, expression: expression };
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
/*只显示激活的筛选条件*/
|
|
290
|
+
filterState.useState<any>({
|
|
291
|
+
seq: Infinity,
|
|
292
|
+
key: 'senior-filter',
|
|
293
|
+
title: i18n.$it('table.seniorQuery').d('高级查询'),
|
|
294
|
+
applyCache: () => null,
|
|
295
|
+
getCache: () => null,
|
|
296
|
+
getDisplay: () => () => (
|
|
297
|
+
<Button onClick={() => setting.openSetting(eTableOptionSettingView.seniorFilter)}>
|
|
298
|
+
<span>{i18n.$it('table.configSeniorFilter').d('配置高级筛选')}</span>
|
|
299
|
+
<Icon icon="pi-arrow-right"/>
|
|
300
|
+
</Button>
|
|
301
|
+
),
|
|
302
|
+
clear: () => edit.clear(false),
|
|
303
|
+
getActiveFilterCount: () => query.state.metas.length
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
const tips = computed((): TableOptionSpace.iTableOptionTipMeta[] => {
|
|
307
|
+
const list: TableOptionSpace.iTableOptionTipMeta[] = [];
|
|
308
|
+
const { metas } = query.state;
|
|
309
|
+
if (!metas.length || !filterOptions.value) {return list;}
|
|
310
|
+
if (metas.every(i => !i.data?.filterQueryParam.queries?.length)) {return list;}
|
|
311
|
+
|
|
312
|
+
let expression = !query.state.isCustomExpression || !query.state.expression ? query.getDefaultExpression() : query.state.expression;
|
|
313
|
+
/*处理空格*/
|
|
314
|
+
expression = expression.replace(/\s*(\|\||&&|或者|并且|or|and)\s*/gi, ' $1 ').replace(/\s+/, ' ');
|
|
315
|
+
|
|
316
|
+
if (!expression || !filterOptions.value.length) {return list;}
|
|
317
|
+
/*id映射senior meta查询参数*/
|
|
318
|
+
const idToSeniorMeta: Record<string, iTableOptionSeniorFilterMeta & { index: number }> = query.state.metas.reduce((prev, item) => {
|
|
319
|
+
prev[item.id] = item;
|
|
320
|
+
return prev;
|
|
321
|
+
}, {} as any);
|
|
322
|
+
const renderList: (() => RenderNode)[] = [];
|
|
323
|
+
expression.split(' ').forEach(work => {
|
|
324
|
+
if (!work.trim().length) {return; }
|
|
325
|
+
if (ExpressionJoins.indexOf(work) > -1) {
|
|
326
|
+
renderList.push(() => ` ${work} `);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const senior = idToSeniorMeta[work];
|
|
330
|
+
if (!senior || !senior.data) {
|
|
331
|
+
renderList.push(() => work);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const { filterHandler, field, formData } = senior.data;
|
|
335
|
+
let filterOption = filterOptions.value!.find(i => i.field === field);
|
|
336
|
+
if (!filterOption) {
|
|
337
|
+
renderList.push(() => work);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
filterOption = { ...filterOption, filterHandler };
|
|
341
|
+
const tip = TableOptionUtils.createTableOptionTipMeta({
|
|
342
|
+
filterOption,
|
|
343
|
+
formData,
|
|
344
|
+
onClick: doNothing,
|
|
345
|
+
onClear: doNothing,
|
|
346
|
+
});
|
|
347
|
+
if (!tip) {
|
|
348
|
+
renderList.push(() => work);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
renderList.push(tip.display);
|
|
352
|
+
});
|
|
353
|
+
list.push({
|
|
354
|
+
display: () => renderList.map((i, index) => <Fragment key={index}>{i()}</Fragment>),
|
|
355
|
+
onClear: async (e: iMouseEvent) => {
|
|
356
|
+
e.stopPropagation();
|
|
357
|
+
await edit.clear(true);
|
|
358
|
+
},
|
|
359
|
+
onClick: () => {setting.openSetting(eTableOptionSettingView.seniorFilter);},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return list;
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
hooks.onTips.use(list => {
|
|
366
|
+
!!tips.value.length && list.push(...tips.value);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
return {
|
|
370
|
+
query,
|
|
371
|
+
edit,
|
|
372
|
+
};
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
export type iTableOptionSeniorFilterMeta = {
|
|
376
|
+
id: string,
|
|
377
|
+
data: undefined | iFilterFormSingleData,
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface iTableOptionSeniorData {
|
|
381
|
+
metas: iTableOptionSeniorFilterMeta[],
|
|
382
|
+
expression: null | string,
|
|
383
|
+
isCustomExpression: boolean,
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const ExpressionJoins = ['&&', '||', 'and', 'or', '并且', '或者'];
|
|
387
|
+
|
|
388
|
+
const DEFAULT_EXPRESSION_JOIN = '或者';
|