@ibiz-template/runtime 0.1.35 → 0.1.36
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/index.esm.js +363 -70
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/out/constant/index.d.ts +1 -0
- package/out/constant/index.d.ts.map +1 -1
- package/out/constant/index.js +1 -0
- package/out/constant/value-op.d.ts +82 -0
- package/out/constant/value-op.d.ts.map +1 -0
- package/out/constant/value-op.js +83 -0
- package/out/controller/control/form/search-form/search-form.controller.d.ts +2 -2
- package/out/controller/control/form/search-form/search-form.controller.d.ts.map +1 -1
- package/out/controller/control/form/search-form/search-form.controller.js +11 -3
- package/out/controller/control/md-ctrl/md-ctrl.controller.d.ts +38 -3
- package/out/controller/control/md-ctrl/md-ctrl.controller.d.ts.map +1 -1
- package/out/controller/control/md-ctrl/md-ctrl.controller.js +110 -3
- package/out/controller/control/search-bar/search-bar-filter.controller.d.ts +65 -0
- package/out/controller/control/search-bar/search-bar-filter.controller.d.ts.map +1 -0
- package/out/controller/control/search-bar/search-bar-filter.controller.js +48 -0
- package/out/controller/control/search-bar/search-bar.controller.d.ts +63 -4
- package/out/controller/control/search-bar/search-bar.controller.d.ts.map +1 -1
- package/out/controller/control/search-bar/search-bar.controller.js +143 -9
- package/out/engine/md-view.engine.d.ts.map +1 -1
- package/out/engine/md-view.engine.js +2 -23
- package/out/interface/controller/controller/control/i-search-bar.controller.d.ts +8 -0
- package/out/interface/controller/controller/control/i-search-bar.controller.d.ts.map +1 -1
- package/out/interface/controller/controller/control/i-search-form.controller.d.ts +2 -2
- package/out/interface/controller/controller/control/i-search-form.controller.d.ts.map +1 -1
- package/out/interface/controller/state/control/i-search-bar.state.d.ts +75 -0
- package/out/interface/controller/state/control/i-search-bar.state.d.ts.map +1 -1
- package/out/service/service/entity/method/method.js +2 -2
- package/package.json +3 -3
- package/src/constant/index.ts +1 -0
- package/src/constant/value-op.ts +82 -0
- package/src/controller/control/form/search-form/search-form.controller.ts +11 -3
- package/src/controller/control/md-ctrl/md-ctrl.controller.ts +136 -3
- package/src/controller/control/search-bar/search-bar-filter.controller.ts +112 -0
- package/src/controller/control/search-bar/search-bar.controller.ts +165 -9
- package/src/engine/md-view.engine.ts +2 -27
- package/src/interface/controller/controller/control/i-search-bar.controller.ts +10 -1
- package/src/interface/controller/controller/control/i-search-form.controller.ts +2 -2
- package/src/interface/controller/state/control/i-search-bar.state.ts +86 -0
- package/src/service/service/entity/method/method.ts +2 -2
|
@@ -3,12 +3,16 @@ import {
|
|
|
3
3
|
IUIActionGroup,
|
|
4
4
|
IUIActionGroupDetail,
|
|
5
5
|
} from '@ibiz/model-core';
|
|
6
|
+
import { RuntimeModelError } from '@ibiz-template/core';
|
|
7
|
+
import { isNil } from 'ramda';
|
|
6
8
|
import {
|
|
7
9
|
IMobMDCtrlEvent,
|
|
8
10
|
IMobMDCtrlController,
|
|
9
11
|
IMobMdCtrlState,
|
|
10
12
|
IMobMDCtrlRowState,
|
|
11
13
|
MDCtrlLoadParams,
|
|
14
|
+
IMDControlGroupState,
|
|
15
|
+
CodeListItem,
|
|
12
16
|
} from '../../../interface';
|
|
13
17
|
import { MDCtrlService } from './md-ctrl.service';
|
|
14
18
|
import { MobMDCtrlRowState } from './md-ctrl-row.state';
|
|
@@ -31,6 +35,16 @@ export class MDCtrlController
|
|
|
31
35
|
this.state.mdctrlActiveMode = 1;
|
|
32
36
|
}
|
|
33
37
|
|
|
38
|
+
/**
|
|
39
|
+
* 分组代码表项集合
|
|
40
|
+
*
|
|
41
|
+
* @author zk
|
|
42
|
+
* @date 2023-10-11 04:10:06
|
|
43
|
+
* @type {readonly}
|
|
44
|
+
* @memberof MDCtrlController
|
|
45
|
+
*/
|
|
46
|
+
groupCodeListItems?: readonly CodeListItem[];
|
|
47
|
+
|
|
34
48
|
protected async onCreated(): Promise<void> {
|
|
35
49
|
await super.onCreated();
|
|
36
50
|
this.service = new MDCtrlService(this.model);
|
|
@@ -86,7 +100,10 @@ export class MDCtrlController
|
|
|
86
100
|
await this.load({ isInitialLoad: true });
|
|
87
101
|
}
|
|
88
102
|
|
|
89
|
-
afterLoad(
|
|
103
|
+
async afterLoad(
|
|
104
|
+
args: MDCtrlLoadParams,
|
|
105
|
+
items: ControlVO[],
|
|
106
|
+
): Promise<IData[]> {
|
|
90
107
|
if (args.isInitialLoad) {
|
|
91
108
|
this.state.rows = [];
|
|
92
109
|
}
|
|
@@ -99,6 +116,8 @@ export class MDCtrlController
|
|
|
99
116
|
}),
|
|
100
117
|
);
|
|
101
118
|
}
|
|
119
|
+
await this.initGroupCodeListItems();
|
|
120
|
+
await this.handleDataGroup();
|
|
102
121
|
return super.afterLoad(args, items);
|
|
103
122
|
}
|
|
104
123
|
|
|
@@ -108,7 +127,7 @@ export class MDCtrlController
|
|
|
108
127
|
* @author zk
|
|
109
128
|
* @date 2023-05-26 02:05:46
|
|
110
129
|
* @param {IData[]} items
|
|
111
|
-
* @memberof
|
|
130
|
+
* @memberof MDCtrlController
|
|
112
131
|
*/
|
|
113
132
|
setData(items: IData[]): void {
|
|
114
133
|
const rows = items.map(item => {
|
|
@@ -124,7 +143,7 @@ export class MDCtrlController
|
|
|
124
143
|
* @author zk
|
|
125
144
|
* @date 2023-05-26 02:05:35
|
|
126
145
|
* @return {*} {IData[]}
|
|
127
|
-
* @memberof
|
|
146
|
+
* @memberof MDCtrlController
|
|
128
147
|
*/
|
|
129
148
|
getAllData(): IData[] {
|
|
130
149
|
return this.state.rows.map(row => row.data);
|
|
@@ -196,4 +215,118 @@ export class MDCtrlController
|
|
|
196
215
|
containerState.update(row.data.getOrigin());
|
|
197
216
|
row.uaColStates[group.id!] = containerState;
|
|
198
217
|
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 处理数据分组
|
|
221
|
+
*
|
|
222
|
+
* @memberof MDCtrlController
|
|
223
|
+
*/
|
|
224
|
+
protected async handleDataGroup(): Promise<void> {
|
|
225
|
+
const { enableGroup, groupMode, groupAppDEFieldId } = this.model;
|
|
226
|
+
if (enableGroup && groupMode) {
|
|
227
|
+
if (!groupAppDEFieldId) {
|
|
228
|
+
throw new RuntimeModelError(this.model, '分组属性没有配置');
|
|
229
|
+
}
|
|
230
|
+
if (groupMode === 'AUTO') {
|
|
231
|
+
this.handleAutoGroup();
|
|
232
|
+
} else if (groupMode === 'CODELIST') {
|
|
233
|
+
await this.handleCodeListGroup();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 处理自动分组
|
|
240
|
+
*
|
|
241
|
+
* @memberof MDCtrlController
|
|
242
|
+
*/
|
|
243
|
+
protected handleAutoGroup(): void {
|
|
244
|
+
const { groupAppDEFieldId } = this.model;
|
|
245
|
+
if (groupAppDEFieldId) {
|
|
246
|
+
const { items } = this.state;
|
|
247
|
+
const groupMap: Map<string, MobMDCtrlRowState[]> = new Map();
|
|
248
|
+
items.forEach((item: IData) => {
|
|
249
|
+
const groupVal = item[groupAppDEFieldId];
|
|
250
|
+
if (isNil(groupVal)) {
|
|
251
|
+
// 分组无值的不显示
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!groupMap.has(groupVal)) {
|
|
256
|
+
groupMap.set(groupVal, []);
|
|
257
|
+
}
|
|
258
|
+
groupMap
|
|
259
|
+
.get(groupVal)!
|
|
260
|
+
.push(new MobMDCtrlRowState(item as ControlVO, this));
|
|
261
|
+
});
|
|
262
|
+
const groups: IMDControlGroupState[] = [];
|
|
263
|
+
groupMap.forEach((value: IData[], key: string) => {
|
|
264
|
+
groups.push({
|
|
265
|
+
caption: key,
|
|
266
|
+
key,
|
|
267
|
+
children: [...value],
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
this.state.groups = groups;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* 加载并初始化分组代码表项集合
|
|
276
|
+
* @author lxm
|
|
277
|
+
* @date 2023-08-29 05:11:39
|
|
278
|
+
* @protected
|
|
279
|
+
* @return {*} {Promise<void>}
|
|
280
|
+
*/
|
|
281
|
+
protected async initGroupCodeListItems(): Promise<void> {
|
|
282
|
+
const { groupCodeListId } = this.model;
|
|
283
|
+
if (!groupCodeListId) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const app = ibiz.hub.getApp(this.context.srfappid);
|
|
287
|
+
this.groupCodeListItems = await app.codeList.get(
|
|
288
|
+
groupCodeListId,
|
|
289
|
+
this.context,
|
|
290
|
+
this.params,
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 处理代码表分组
|
|
296
|
+
*
|
|
297
|
+
* @memberof MDCtrlController
|
|
298
|
+
*/
|
|
299
|
+
protected async handleCodeListGroup(): Promise<void> {
|
|
300
|
+
const { groupAppDEFieldId, groupCodeListId } = this.model;
|
|
301
|
+
if (!groupCodeListId) {
|
|
302
|
+
throw new RuntimeModelError(this.model, '分组代码表没有配置');
|
|
303
|
+
}
|
|
304
|
+
const { items } = this.state;
|
|
305
|
+
const groupMap: Map<string | number, MobMDCtrlRowState[]> = new Map();
|
|
306
|
+
this.groupCodeListItems!.forEach(item => {
|
|
307
|
+
groupMap.set(item.value, []);
|
|
308
|
+
});
|
|
309
|
+
items.forEach((item: IData) => {
|
|
310
|
+
const groupVal = item[groupAppDEFieldId!];
|
|
311
|
+
const groupArr = groupMap.get(groupVal);
|
|
312
|
+
if (groupArr) {
|
|
313
|
+
groupArr.push(new MobMDCtrlRowState(item as ControlVO, this));
|
|
314
|
+
}
|
|
315
|
+
// 不在代码表里数据忽略
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const groups: IMDControlGroupState[] = [];
|
|
319
|
+
groupMap.forEach((arr, key) => {
|
|
320
|
+
// 标题
|
|
321
|
+
const codeListItem = this.groupCodeListItems!.find(
|
|
322
|
+
item => item.value === key,
|
|
323
|
+
)!;
|
|
324
|
+
groups.push({
|
|
325
|
+
caption: codeListItem.text,
|
|
326
|
+
key: codeListItem.value,
|
|
327
|
+
children: arr,
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
this.state.groups = groups;
|
|
331
|
+
}
|
|
199
332
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { RuntimeModelError } from '@ibiz-template/core';
|
|
2
|
+
import { IAppDEField, ISearchBarFilter } from '@ibiz/model-core';
|
|
3
|
+
import {
|
|
4
|
+
IEditorContainerController,
|
|
5
|
+
IEditorController,
|
|
6
|
+
IEditorProvider,
|
|
7
|
+
} from '../../../interface';
|
|
8
|
+
import { findFieldById } from '../../../model';
|
|
9
|
+
import { getEditorProvider } from '../../../register';
|
|
10
|
+
import { SearchBarController } from './search-bar.controller';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 搜索栏过滤项控制器
|
|
14
|
+
* @author lxm
|
|
15
|
+
* @date 2023-10-12 05:49:19
|
|
16
|
+
* @export
|
|
17
|
+
* @class SearchBarFilterController
|
|
18
|
+
* @implements {IEditorContainerController}
|
|
19
|
+
*/
|
|
20
|
+
export class SearchBarFilterController implements IEditorContainerController {
|
|
21
|
+
unitName: string | undefined;
|
|
22
|
+
|
|
23
|
+
valueFormat: string | undefined;
|
|
24
|
+
|
|
25
|
+
get context(): IContext {
|
|
26
|
+
return this.searchBar.context;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get params(): IParams {
|
|
30
|
+
return this.searchBar.params;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dataType: number | undefined;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 编辑器控制器
|
|
37
|
+
*
|
|
38
|
+
* @author lxm
|
|
39
|
+
* @date 2022-08-24 20:08:42
|
|
40
|
+
* @type {IEditorController}
|
|
41
|
+
*/
|
|
42
|
+
editor?: IEditorController;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 编辑器适配器
|
|
46
|
+
*
|
|
47
|
+
* @author lxm
|
|
48
|
+
* @date 2022-08-24 20:08:42
|
|
49
|
+
*/
|
|
50
|
+
editorProvider?: IEditorProvider;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 过滤的属性名称(有实体属性的是属性codeName小写,没有就是项名称)
|
|
54
|
+
* @author lxm
|
|
55
|
+
* @date 2023-10-13 02:51:39
|
|
56
|
+
* @type {string}
|
|
57
|
+
*/
|
|
58
|
+
fieldName: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 属性显示的标题
|
|
62
|
+
* @author lxm
|
|
63
|
+
* @date 2023-10-13 03:02:42
|
|
64
|
+
* @type {string}
|
|
65
|
+
*/
|
|
66
|
+
label: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 配置的属性搜索模式对应的值操作
|
|
70
|
+
* @author lxm
|
|
71
|
+
* @date 2023-10-13 03:22:10
|
|
72
|
+
* @type {string}
|
|
73
|
+
*/
|
|
74
|
+
valueOP?: string;
|
|
75
|
+
|
|
76
|
+
constructor(
|
|
77
|
+
public model: ISearchBarFilter,
|
|
78
|
+
public searchBar: SearchBarController,
|
|
79
|
+
) {
|
|
80
|
+
// 实体属性
|
|
81
|
+
let field: IAppDEField | undefined;
|
|
82
|
+
if (model.appDEFieldId) {
|
|
83
|
+
field = findFieldById(searchBar.appDataEntity, model.appDEFieldId)!;
|
|
84
|
+
}
|
|
85
|
+
this.fieldName = field ? field.codeName!.toLowerCase() : model.id!;
|
|
86
|
+
|
|
87
|
+
// 属性标题
|
|
88
|
+
this.label = model.caption || field?.logicName || model.id!;
|
|
89
|
+
|
|
90
|
+
this.valueOP = model.defsearchMode?.valueOP;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 初始化
|
|
95
|
+
* @author lxm
|
|
96
|
+
* @date 2023-10-12 05:47:19
|
|
97
|
+
* @return {*} {Promise<void>}
|
|
98
|
+
*/
|
|
99
|
+
async init(): Promise<void> {
|
|
100
|
+
if (!this.model.editor) {
|
|
101
|
+
throw new RuntimeModelError(this.model, '缺少编辑器模型');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
this.editorProvider = await getEditorProvider(this.model.editor);
|
|
105
|
+
if (this.editorProvider) {
|
|
106
|
+
this.editor = await this.editorProvider.createController(
|
|
107
|
+
this.model.editor,
|
|
108
|
+
this,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { recursiveIterate } from '@ibiz-template/core';
|
|
2
|
+
import { IAppDataEntity, ISearchBar } from '@ibiz/model-core';
|
|
3
|
+
import { isNil } from 'ramda';
|
|
2
4
|
import {
|
|
3
5
|
ISearchBarState,
|
|
4
6
|
ISearchBarEvent,
|
|
5
7
|
ISearchBarController,
|
|
8
|
+
IFilterNode,
|
|
6
9
|
} from '../../../interface';
|
|
7
10
|
import { ControlController } from '../../common';
|
|
11
|
+
import { SearchBarFilterController } from './search-bar-filter.controller';
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* 搜索栏控制器
|
|
@@ -20,13 +24,29 @@ export class SearchBarController
|
|
|
20
24
|
implements ISearchBarController
|
|
21
25
|
{
|
|
22
26
|
/**
|
|
23
|
-
*
|
|
27
|
+
* 快速搜索占位符
|
|
24
28
|
* @return {*}
|
|
25
29
|
* @author: zhujiamin
|
|
26
30
|
* @Date: 2023-08-11 14:13:10
|
|
27
31
|
*/
|
|
28
32
|
placeHolder = '';
|
|
29
33
|
|
|
34
|
+
/**
|
|
35
|
+
* 过滤项控制器集合
|
|
36
|
+
* @author lxm
|
|
37
|
+
* @date 2023-10-13 03:31:26
|
|
38
|
+
* @type {SearchBarFilterController[]}
|
|
39
|
+
*/
|
|
40
|
+
filterControllers: SearchBarFilterController[] = [];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 实体模型
|
|
44
|
+
* @author lxm
|
|
45
|
+
* @date 2023-10-13 02:49:59
|
|
46
|
+
* @type {IAppDataEntity}
|
|
47
|
+
*/
|
|
48
|
+
appDataEntity!: IAppDataEntity;
|
|
49
|
+
|
|
30
50
|
protected initState(): void {
|
|
31
51
|
super.initState();
|
|
32
52
|
this.state.query = '';
|
|
@@ -36,6 +56,9 @@ export class SearchBarController
|
|
|
36
56
|
this.model.enableGroup ||
|
|
37
57
|
this.model.enableFilter
|
|
38
58
|
);
|
|
59
|
+
if (this.model.enableFilter) {
|
|
60
|
+
this.resetFilter();
|
|
61
|
+
}
|
|
39
62
|
}
|
|
40
63
|
|
|
41
64
|
protected async onCreated(): Promise<void> {
|
|
@@ -45,19 +68,38 @@ export class SearchBarController
|
|
|
45
68
|
this.context.srfappid,
|
|
46
69
|
)!;
|
|
47
70
|
if (appDataEntity) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
71
|
+
this.appDataEntity = appDataEntity;
|
|
72
|
+
this.calcQuickSearchPlaceholder();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
await this.initSearchBarFilters();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 计算快速搜索的占位
|
|
80
|
+
* @author lxm
|
|
81
|
+
* @date 2023-10-16 03:49:47
|
|
82
|
+
* @protected
|
|
83
|
+
* @return {*} {void}
|
|
84
|
+
*/
|
|
85
|
+
protected calcQuickSearchPlaceholder(): void {
|
|
86
|
+
if (!this.appDataEntity) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const searchFields = this.appDataEntity.appDEFields!.filter(field => {
|
|
90
|
+
return field.enableQuickSearch;
|
|
91
|
+
});
|
|
92
|
+
if (searchFields.length) {
|
|
51
93
|
const placeHolders: string[] = [];
|
|
52
|
-
searchFields
|
|
53
|
-
if (searchField
|
|
94
|
+
searchFields.forEach(searchField => {
|
|
95
|
+
if (searchField.lnlanguageRes && searchField.lnlanguageRes.lanResTag) {
|
|
54
96
|
placeHolders.push(
|
|
55
97
|
ibiz.i18n.t(
|
|
56
98
|
searchField.lnlanguageRes.lanResTag,
|
|
57
99
|
searchField.logicName,
|
|
58
100
|
),
|
|
59
101
|
);
|
|
60
|
-
} else if (searchField
|
|
102
|
+
} else if (searchField.logicName) {
|
|
61
103
|
placeHolders.push(searchField.logicName);
|
|
62
104
|
}
|
|
63
105
|
});
|
|
@@ -84,7 +126,121 @@ export class SearchBarController
|
|
|
84
126
|
* @author: zhujiamin
|
|
85
127
|
* @Date: 2023-06-01 18:08:18
|
|
86
128
|
*/
|
|
87
|
-
|
|
129
|
+
onSearch(): void {
|
|
88
130
|
this.evt.emit('onSearch', undefined);
|
|
89
131
|
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 获取搜索栏的过滤参数(包括快速搜索,快速分组和过滤器的参数)
|
|
135
|
+
* @author lxm
|
|
136
|
+
* @date 2023-10-16 03:54:07
|
|
137
|
+
* @return {*} {IParams}
|
|
138
|
+
*/
|
|
139
|
+
getFilterParams(): IParams {
|
|
140
|
+
const params: IParams = {};
|
|
141
|
+
// 快速搜索
|
|
142
|
+
if (this.state.query) {
|
|
143
|
+
params.query = this.state.query;
|
|
144
|
+
}
|
|
145
|
+
// 快速分组
|
|
146
|
+
if (this.state.selectedGroupItem?.data) {
|
|
147
|
+
// eslint-disable-next-line no-new-func
|
|
148
|
+
const func = new Function(
|
|
149
|
+
`return (${this.state.selectedGroupItem.data});`,
|
|
150
|
+
);
|
|
151
|
+
const addParams = func() as IData;
|
|
152
|
+
Object.assign(params, addParams);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 搜索过滤器
|
|
156
|
+
const filters = this.calcFilters();
|
|
157
|
+
if (filters) {
|
|
158
|
+
params.filters = filters;
|
|
159
|
+
}
|
|
160
|
+
return params;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 重置过滤器
|
|
165
|
+
* @author lxm
|
|
166
|
+
* @date 2023-10-16 03:52:44
|
|
167
|
+
*/
|
|
168
|
+
resetFilter(): void {
|
|
169
|
+
this.state.filterNodes = [
|
|
170
|
+
{
|
|
171
|
+
leaf: false,
|
|
172
|
+
logicType: 'AND',
|
|
173
|
+
children: [{ leaf: true, field: null, valueOP: null, value: null }],
|
|
174
|
+
},
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 初始化过滤项控制器
|
|
180
|
+
* @author lxm
|
|
181
|
+
* @date 2023-10-13 03:33:17
|
|
182
|
+
* @protected
|
|
183
|
+
* @return {*} {Promise<void>}
|
|
184
|
+
*/
|
|
185
|
+
protected async initSearchBarFilters(): Promise<void> {
|
|
186
|
+
if (this.model.searchBarFilters?.length) {
|
|
187
|
+
this.model.searchBarFilters.forEach(item => {
|
|
188
|
+
const filterController = new SearchBarFilterController(item, this);
|
|
189
|
+
this.filterControllers.push(filterController);
|
|
190
|
+
});
|
|
191
|
+
await Promise.all(
|
|
192
|
+
this.filterControllers.map(controller => controller.init()),
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 计算过滤项参数
|
|
199
|
+
* @author lxm
|
|
200
|
+
* @date 2023-10-13 05:53:35
|
|
201
|
+
* @return {*} {IData}
|
|
202
|
+
*/
|
|
203
|
+
calcFilters(): IData | undefined {
|
|
204
|
+
if (!this.model.enableFilter) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
let hasFilter = false; // 是否有过滤项
|
|
208
|
+
let hasError = false; // 是否有过滤项格式不正确
|
|
209
|
+
recursiveIterate(this.state.filterNodes[0], (node: IFilterNode) => {
|
|
210
|
+
if (node.leaf) {
|
|
211
|
+
if (node.field && node.valueOP && !isNil(node.value)) {
|
|
212
|
+
hasFilter = true;
|
|
213
|
+
} else {
|
|
214
|
+
// 如果过滤项不给
|
|
215
|
+
hasError = true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
if (hasFilter && !hasError) {
|
|
220
|
+
const filter = this.formatFilters(this.state.filterNodes[0]);
|
|
221
|
+
return filter;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 格式化过滤项
|
|
227
|
+
* @author lxm
|
|
228
|
+
* @date 2023-10-16 03:45:41
|
|
229
|
+
* @param {IFilterNode} node
|
|
230
|
+
* @return {*} {IData}
|
|
231
|
+
*/
|
|
232
|
+
formatFilters(node: IFilterNode): IData {
|
|
233
|
+
if (!node.leaf) {
|
|
234
|
+
return {
|
|
235
|
+
[`$${node.logicType.toLowerCase()}`]: node.children.map(item =>
|
|
236
|
+
this.formatFilters(item),
|
|
237
|
+
),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
[`${node.field}`]: {
|
|
242
|
+
[`$${node.valueOP!.toLowerCase()}`]: node.value,
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
90
246
|
}
|
|
@@ -334,36 +334,11 @@ export class MDViewEngine extends ViewEngineBase {
|
|
|
334
334
|
const params: IParams = {};
|
|
335
335
|
// 有搜索表单的整合相关参数
|
|
336
336
|
if (this.searchForm) {
|
|
337
|
-
|
|
338
|
-
const filteredParams = Object.entries(addParams).reduce(
|
|
339
|
-
(result: IData, [key, value]) => {
|
|
340
|
-
if (value !== null && value !== undefined && value !== '') {
|
|
341
|
-
result[key] = value;
|
|
342
|
-
}
|
|
343
|
-
return result;
|
|
344
|
-
},
|
|
345
|
-
{},
|
|
346
|
-
);
|
|
347
|
-
Object.assign(params, filteredParams);
|
|
337
|
+
Object.assign(params, this.searchForm.getFilterParams());
|
|
348
338
|
}
|
|
349
339
|
// 有搜索栏的整合相关参数
|
|
350
340
|
if (this.searchBar) {
|
|
351
|
-
|
|
352
|
-
if (this.searchBar.state.query) {
|
|
353
|
-
const addParams = {
|
|
354
|
-
query: this.searchBar.state.query,
|
|
355
|
-
};
|
|
356
|
-
Object.assign(params, addParams);
|
|
357
|
-
}
|
|
358
|
-
// 快速分组
|
|
359
|
-
if (this.searchBar.state.selectedGroupItem?.data) {
|
|
360
|
-
// eslint-disable-next-line no-new-func
|
|
361
|
-
const func = new Function(
|
|
362
|
-
`return (${this.searchBar.state.selectedGroupItem.data});`,
|
|
363
|
-
);
|
|
364
|
-
const addParams = func() as IData;
|
|
365
|
-
Object.assign(params, addParams);
|
|
366
|
-
}
|
|
341
|
+
Object.assign(params, this.searchBar.getFilterParams());
|
|
367
342
|
}
|
|
368
343
|
return params;
|
|
369
344
|
}
|
|
@@ -12,4 +12,13 @@ import { IControlController } from './i-control.controller';
|
|
|
12
12
|
* @extends {IControlController}
|
|
13
13
|
*/
|
|
14
14
|
export interface ISearchBarController
|
|
15
|
-
extends IControlController<ISearchBar, ISearchBarState, ISearchBarEvent> {
|
|
15
|
+
extends IControlController<ISearchBar, ISearchBarState, ISearchBarEvent> {
|
|
16
|
+
/**
|
|
17
|
+
* 获取搜索栏的过滤参数
|
|
18
|
+
*
|
|
19
|
+
* @author lxm
|
|
20
|
+
* @date 2022-09-22 17:09:21
|
|
21
|
+
* @returns {*} {IParams}
|
|
22
|
+
*/
|
|
23
|
+
getFilterParams(): IParams;
|
|
24
|
+
}
|
|
@@ -22,13 +22,13 @@ export interface ISearchFormController
|
|
|
22
22
|
load(): Promise<IData>;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* 获取搜索表单的过滤参数
|
|
26
26
|
*
|
|
27
27
|
* @author lxm
|
|
28
28
|
* @date 2022-09-22 17:09:21
|
|
29
29
|
* @returns {*} {IParams}
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
getFilterParams(): IParams;
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* 执行搜索行为
|
|
@@ -1,6 +1,84 @@
|
|
|
1
1
|
import { ISearchBarGroup } from '@ibiz/model-core';
|
|
2
2
|
import { IControlState } from './i-control.state';
|
|
3
3
|
|
|
4
|
+
export interface IFilterBranchNode {
|
|
5
|
+
/**
|
|
6
|
+
* 是否是叶子节点
|
|
7
|
+
* @author lxm
|
|
8
|
+
* @date 2023-10-12 05:14:28
|
|
9
|
+
* @type {boolean}
|
|
10
|
+
*/
|
|
11
|
+
leaf: false;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 父节点的逻辑类型
|
|
15
|
+
* @author lxm
|
|
16
|
+
* @date 2023-10-12 05:21:18
|
|
17
|
+
* @type {('AND' | 'OR')}
|
|
18
|
+
*/
|
|
19
|
+
logicType: 'AND' | 'OR';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 过滤项值
|
|
23
|
+
* @author lxm
|
|
24
|
+
* @date 2023-10-12 05:16:52
|
|
25
|
+
* @type {unknown}
|
|
26
|
+
*/
|
|
27
|
+
value?: unknown;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 值操作类型
|
|
31
|
+
* @author lxm
|
|
32
|
+
* @date 2023-10-12 05:27:07
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
valueOP?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 子节点数据集合
|
|
39
|
+
* @author lxm
|
|
40
|
+
* @date 2023-10-12 05:18:19
|
|
41
|
+
* @type {IFilterTreeNode[]}
|
|
42
|
+
*/
|
|
43
|
+
children: IFilterNode[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface IFilterLeafNode {
|
|
47
|
+
/**
|
|
48
|
+
* 是否是叶子节点
|
|
49
|
+
* @author lxm
|
|
50
|
+
* @date 2023-10-12 05:14:28
|
|
51
|
+
* @type {boolean}
|
|
52
|
+
*/
|
|
53
|
+
leaf: true;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 实体属性名称
|
|
57
|
+
* @author lxm
|
|
58
|
+
* @date 2023-10-13 02:35:42
|
|
59
|
+
* @type {string}
|
|
60
|
+
*/
|
|
61
|
+
field: string | null;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 过滤项值
|
|
65
|
+
* @author lxm
|
|
66
|
+
* @date 2023-10-12 05:16:52
|
|
67
|
+
* @type {unknown}
|
|
68
|
+
*/
|
|
69
|
+
value: unknown | null;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 值操作类型
|
|
73
|
+
* @author lxm
|
|
74
|
+
* @date 2023-10-12 05:27:07
|
|
75
|
+
* @type {string}
|
|
76
|
+
*/
|
|
77
|
+
valueOP: string | null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type IFilterNode = IFilterBranchNode | IFilterLeafNode;
|
|
81
|
+
|
|
4
82
|
export interface ISearchBarState extends IControlState {
|
|
5
83
|
/**
|
|
6
84
|
* 快速搜索字符串
|
|
@@ -25,4 +103,12 @@ export interface ISearchBarState extends IControlState {
|
|
|
25
103
|
* @type {boolean}
|
|
26
104
|
*/
|
|
27
105
|
selectedGroupItem: ISearchBarGroup | null;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 过滤项树节点数据集合
|
|
109
|
+
* @author lxm
|
|
110
|
+
* @date 2023-10-12 05:16:12
|
|
111
|
+
* @type {IFilterNode[]}
|
|
112
|
+
*/
|
|
113
|
+
filterNodes: IFilterNode[];
|
|
28
114
|
}
|
|
@@ -111,7 +111,7 @@ export abstract class Method {
|
|
|
111
111
|
case 'POST':
|
|
112
112
|
res = await this.app.net.post(
|
|
113
113
|
this.mergeRequestPath(path, methodName),
|
|
114
|
-
notNilEmpty(data) ? data! : params
|
|
114
|
+
notNilEmpty(data) ? data! : params || {},
|
|
115
115
|
);
|
|
116
116
|
break;
|
|
117
117
|
case 'GET':
|
|
@@ -123,7 +123,7 @@ export abstract class Method {
|
|
|
123
123
|
case 'PUT': {
|
|
124
124
|
res = await this.app.net.put(
|
|
125
125
|
this.mergeRequestPath(path, methodName),
|
|
126
|
-
notNilEmpty(data) ? data! : params
|
|
126
|
+
notNilEmpty(data) ? data! : params || {},
|
|
127
127
|
);
|
|
128
128
|
break;
|
|
129
129
|
}
|