@ctzy-web-client/data-model 1.0.0 → 1.0.4

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.
Files changed (51) hide show
  1. package/es/SimpleOrm.mjs +85 -0
  2. package/es/_virtual/_rollupPluginBabelHelpers.mjs +2830 -0
  3. package/es/abstract/DataColumn.mjs +65 -0
  4. package/es/abstract/DataForm.mjs +178 -0
  5. package/es/abstract/DataModel.mjs +223 -0
  6. package/es/abstract/DataModelAdapter.mjs +86 -0
  7. package/es/abstract/DataTable.mjs +339 -0
  8. package/es/abstract/FilterColumn.mjs +44 -0
  9. package/es/abstract/FilterPanel.mjs +392 -0
  10. package/es/abstract/FormColumn.mjs +27 -0
  11. package/es/abstract/TableColumn.mjs +34 -0
  12. package/es/abstract/dataForm2.mjs +178 -0
  13. package/es/abstract/where/CombineCondition.mjs +63 -0
  14. package/es/abstract/where/Condition.mjs +4 -0
  15. package/es/abstract/where/SingleCondition.mjs +22 -0
  16. package/es/abstract/where/Where.mjs +21 -0
  17. package/es/decorator/constant.mjs +11 -0
  18. package/es/decorator/dataForm.mjs +18 -0
  19. package/es/decorator/dataTable.mjs +18 -0
  20. package/es/decorator/filterColumn.mjs +21 -0
  21. package/es/decorator/formColumn.mjs +19 -0
  22. package/es/decorator/tableColumn.mjs +20 -0
  23. package/es/factory.mjs +14 -0
  24. package/es/index.mjs +14 -0
  25. package/es/utils/index.mjs +15 -0
  26. package/lib/SimpleOrm.js +89 -0
  27. package/lib/_virtual/_rollupPluginBabelHelpers.js +2948 -0
  28. package/lib/abstract/DataColumn.js +69 -0
  29. package/lib/abstract/DataForm.js +186 -0
  30. package/lib/abstract/DataModel.js +231 -0
  31. package/lib/abstract/DataModelAdapter.js +90 -0
  32. package/lib/abstract/DataTable.js +343 -0
  33. package/lib/abstract/FilterColumn.js +48 -0
  34. package/lib/abstract/FilterPanel.js +396 -0
  35. package/lib/abstract/FormColumn.js +31 -0
  36. package/lib/abstract/TableColumn.js +38 -0
  37. package/lib/abstract/dataForm2.js +186 -0
  38. package/lib/abstract/where/CombineCondition.js +67 -0
  39. package/lib/abstract/where/Condition.js +8 -0
  40. package/lib/abstract/where/SingleCondition.js +26 -0
  41. package/lib/abstract/where/Where.js +25 -0
  42. package/lib/decorator/constant.js +20 -0
  43. package/lib/decorator/dataForm.js +22 -0
  44. package/lib/decorator/dataTable.js +22 -0
  45. package/lib/decorator/filterColumn.js +25 -0
  46. package/lib/decorator/formColumn.js +23 -0
  47. package/lib/decorator/tableColumn.js +24 -0
  48. package/lib/factory.js +19 -0
  49. package/lib/index.js +36 -0
  50. package/lib/utils/index.js +19 -0
  51. package/package.json +33 -33
@@ -0,0 +1,392 @@
1
+ import { cloneDeep, isEqual, set, get, unset } from 'lodash';
2
+ import { EventDispatcher, aesEncrypt } from '@ctzy-web-client/support';
3
+ import FilterColumn from './FilterColumn.mjs';
4
+ import { Where } from './where/Where.mjs';
5
+ import { sortColumn } from '../utils/index.mjs';
6
+
7
+ class FilterPanel extends EventDispatcher {
8
+ get isInited() {
9
+ return this._inited;
10
+ }
11
+ get ready() {
12
+ if (!this._inited) {
13
+ return false;
14
+ }
15
+ return this.existComponent ? this._ready : true;
16
+ }
17
+ set ready(value) {
18
+ if (!this._inited) {
19
+ return;
20
+ }
21
+ if (this.ready || this._ready === value) {
22
+ return;
23
+ }
24
+ this._ready = value;
25
+ this.emit("ready");
26
+ }
27
+ constructor(dataTable) {
28
+ super();
29
+ this._filterColumns = [];
30
+ this._selectedColumnAttrNames = [];
31
+ this._searchValue = "";
32
+ this._searchAttr = "";
33
+ this.fieldSearchValue = "";
34
+ this._filterParams = {};
35
+ this.existComponent = false;
36
+ this._inited = false;
37
+ this._ready = false;
38
+ this._isChange = false;
39
+ this._allowTriggerParamsChange = 0;
40
+ this._searchFields = [];
41
+ this.whereForFilter = false;
42
+ this.whereParamName = "";
43
+ this.encryptCondition = true;
44
+ this.dataTable = dataTable;
45
+ this.originFilterParams = {};
46
+ this.originSearchValue = "";
47
+ }
48
+ _formatFilterColumn(extendFieldInfo) {
49
+ const baseFilterColumnConfig = {
50
+ name: extendFieldInfo.name,
51
+ attrName: extendFieldInfo.name,
52
+ isExtend: true,
53
+ default: extendFieldInfo.defaultValue,
54
+ formComponent: extendFieldInfo.component,
55
+ closable: true,
56
+ title: extendFieldInfo.title,
57
+ fullAttrName: `${this.dataTable.extendField}.${extendFieldInfo.name}`
58
+ };
59
+ if (["BwaSelect"].includes(extendFieldInfo.component)) {
60
+ baseFilterColumnConfig.component = "BwaSingleMenuCondition";
61
+ baseFilterColumnConfig.componentProps = extendFieldInfo.extendInfo;
62
+ }
63
+ if (["BwaMultiSelect"].includes(extendFieldInfo.component)) {
64
+ baseFilterColumnConfig.component = "BwaMultipleMenuCondition";
65
+ baseFilterColumnConfig.componentProps = extendFieldInfo.extendInfo;
66
+ }
67
+ if (["BwaUserSelect"].includes(extendFieldInfo.component)) {
68
+ baseFilterColumnConfig.component = "BwaSingleUserCondition";
69
+ }
70
+ if (["BwaUserMultiSelect"].includes(extendFieldInfo.component)) {
71
+ baseFilterColumnConfig.component = "BwaMultiUserCondition";
72
+ }
73
+ return baseFilterColumnConfig;
74
+ }
75
+ _parseFilterColumns(extendFieldInfos, filterColumnConfigs) {
76
+ const allowComponents = ["BwaSelect", "BwaMultiSelect", "BwaUserSelect", "BwaUserMultiSelect"];
77
+ extendFieldInfos = extendFieldInfos.filter((extendFieldInfo) => extendFieldInfo.type != 1).filter((extendFieldInfo) => allowComponents.includes(extendFieldInfo.component));
78
+ const attrNames = Array.from(new Set(filterColumnConfigs.map((config) => config.attrName)));
79
+ extendFieldInfos = extendFieldInfos.filter((extendFieldInfo) => !attrNames.includes(extendFieldInfo.name));
80
+ const formatedExtendColumnConfigs = extendFieldInfos.map((item) => this._formatFilterColumn(item));
81
+ return [...filterColumnConfigs, ...formatedExtendColumnConfigs];
82
+ }
83
+ init(extendFieldInfos, filterColumnConfigs, filterColumnsOrder) {
84
+ if (this._inited) {
85
+ return;
86
+ }
87
+ this._inited = true;
88
+ filterColumnConfigs = this._parseFilterColumns(extendFieldInfos, filterColumnConfigs);
89
+ const filterColumns = sortColumn((filterColumnConfigs || []).map((filterColumnConfig) => new FilterColumn(this, filterColumnConfig)), filterColumnsOrder);
90
+ this.setColumns(filterColumns);
91
+ this._selectedColumnAttrNames = this.getAppliedColumns().map((column) => column.fullAttrName);
92
+ this._filterParams = {
93
+ ...this._getDefaultParams(),
94
+ ...this._filterParams
95
+ };
96
+ this.changeOriginFilterParams();
97
+ this._inited = true;
98
+ this.emit("initCompleted");
99
+ }
100
+ setSearchFields(searchFields) {
101
+ this._searchFields = searchFields.slice();
102
+ }
103
+ getSearchFields() {
104
+ return this._searchFields.slice();
105
+ }
106
+ changeOriginFilterParams(originFilterParams = this.getFilterParams()) {
107
+ this.originFilterParams = cloneDeep(originFilterParams);
108
+ this._checkChange();
109
+ }
110
+ changeOriginSearchValue(originSearchValue = this.getSearchValue()) {
111
+ this.originSearchValue = originSearchValue;
112
+ this._checkChange();
113
+ }
114
+ isChange() {
115
+ return this._isChange;
116
+ }
117
+ setIsChange(isChange) {
118
+ if (this._isChange === isChange) {
119
+ return;
120
+ }
121
+ this._isChange = isChange;
122
+ }
123
+ _checkChange() {
124
+ this.setIsChange(!isEqual(this.originFilterParams, this.getFilterParams()) || this.originSearchValue !== this.getSearchValue());
125
+ }
126
+ noTriggerParamsChange(callback) {
127
+ this._allowTriggerParamsChange++;
128
+ callback == null ? void 0 : callback();
129
+ this._allowTriggerParamsChange--;
130
+ }
131
+ getSearchValue() {
132
+ return this._searchValue;
133
+ }
134
+ _triggerParamsChange() {
135
+ if (this._allowTriggerParamsChange > 0) {
136
+ return;
137
+ }
138
+ this.emit("params-change");
139
+ }
140
+ setSeachValue(value, isSearch = false) {
141
+ this._searchValue = value;
142
+ this._checkChange();
143
+ if (!isSearch) {
144
+ this._triggerParamsChange();
145
+ }
146
+ }
147
+ setFilterParam(column, value, isSearch = false) {
148
+ if (this.getFilterParam(column) === value) {
149
+ return;
150
+ }
151
+ set(this._filterParams, column.fullAttrName, value);
152
+ this._checkChange();
153
+ if (!isSearch) {
154
+ this._triggerParamsChange();
155
+ }
156
+ this.emit("change-search-value");
157
+ }
158
+ getFilterParam(column) {
159
+ return get(this._filterParams, column.fullAttrName);
160
+ }
161
+ setSearchAttr(searchAttr) {
162
+ this._searchAttr = searchAttr;
163
+ }
164
+ getSearchAttr() {
165
+ return this._searchAttr;
166
+ }
167
+ _setFilterParams(filterParams, ignoreEmit = false) {
168
+ this._filterParams = cloneDeep(filterParams);
169
+ this._checkChange();
170
+ if (!ignoreEmit) {
171
+ this._triggerParamsChange();
172
+ }
173
+ }
174
+ getFilterParams() {
175
+ return this._filterParams;
176
+ }
177
+ appliedColumn(filterColumn) {
178
+ this._setFilterParams({
179
+ ...this._getDefaultParams(),
180
+ ...this.getFilterParams()
181
+ }, true);
182
+ }
183
+ cancelAppliedColumn(filterColumn) {
184
+ const filterParams = {
185
+ ...this._getDefaultParams(),
186
+ ...this.getFilterParams()
187
+ };
188
+ unset(filterParams, filterColumn.fullAttrName);
189
+ this._setFilterParams(filterParams, true);
190
+ }
191
+ _getDefaultParams() {
192
+ const filterParams = {};
193
+ for (const filterColumn of this.getVisibelColumns()) {
194
+ set(filterParams, filterColumn.fullAttrName, typeof filterColumn.default === "function" ? filterColumn.default() : filterColumn.default);
195
+ }
196
+ return filterParams;
197
+ }
198
+ resetFilterParams() {
199
+ this.noTriggerParamsChange(() => {
200
+ this._setFilterParams(this.originFilterParams);
201
+ this.setSeachValue("");
202
+ });
203
+ this._triggerParamsChange();
204
+ }
205
+ addColumn(filterColumn) {
206
+ if (this.getColumn(filterColumn.fullAttrName)) {
207
+ throw new Error("\u65E0\u6CD5\u6DFB\u52A0\u4E24\u4E2A\u5B57\u6BB5\u540D\u79F0\u4E00\u6837\u7684\u5B57\u6BB5:" + filterColumn.fullAttrName);
208
+ }
209
+ this._filterColumns.push(filterColumn);
210
+ }
211
+ removeColumn(filterColumn) {
212
+ this._filterColumns = this._filterColumns.filter((column) => column.attrName !== filterColumn.attrName);
213
+ }
214
+ getColumn(name) {
215
+ var _a;
216
+ return (_a = this.getColumns().find((column) => column.fullAttrName === name)) != null ? _a : null;
217
+ }
218
+ setColumns(fillterColumns) {
219
+ this._filterColumns = [];
220
+ for (let filterColumn of fillterColumns) {
221
+ this.addColumn(filterColumn);
222
+ }
223
+ }
224
+ getColumns() {
225
+ return this._filterColumns.slice();
226
+ }
227
+ getVisibelColumns() {
228
+ return this.getColumns().filter((column) => column.visible);
229
+ }
230
+ getFxiedColumns() {
231
+ return this.getVisibelColumns().filter((column) => !column.closable);
232
+ }
233
+ getClosableColumns() {
234
+ return this.getColumns().filter((column) => column.closable);
235
+ }
236
+ getSearchClosableColumns() {
237
+ const closableColumns = this.getClosableColumns();
238
+ return closableColumns.filter((column) => {
239
+ return column.title.includes(this.fieldSearchValue) || column.fullAttrName.toLocaleLowerCase().includes(this.fieldSearchValue);
240
+ });
241
+ }
242
+ getSelectedColumnAttrNames() {
243
+ return this._selectedColumnAttrNames.slice();
244
+ }
245
+ setSelectedColumnAttrNames(v) {
246
+ this._selectedColumnAttrNames = v;
247
+ for (let column of this.getClosableColumns()) {
248
+ column.visible = this._selectedColumnAttrNames.includes(column.fullAttrName);
249
+ }
250
+ this.emit("selected-column-change");
251
+ }
252
+ closeColumn(column) {
253
+ const selectedColumnAttrNames = this.getSelectedColumnAttrNames().filter((name) => name !== column.fullAttrName);
254
+ this.setSelectedColumnAttrNames(selectedColumnAttrNames);
255
+ }
256
+ getSelectedColumns() {
257
+ return this._selectedColumnAttrNames.map((attrName) => this.getColumn(attrName)).filter(Boolean).filter((column) => column.closable);
258
+ }
259
+ getAppliedColumns() {
260
+ return this.getFxiedColumns().concat(this.getSelectedColumns()).filter((column) => column.visible);
261
+ }
262
+ _parseWhereAttrMapping(where, column, params) {
263
+ var _a, _b;
264
+ const keys = Object.keys(column.attrMapping || {});
265
+ if (!keys.length) {
266
+ return;
267
+ }
268
+ let group = null;
269
+ if (column.twoFieldsDatePicker) {
270
+ const startInfo = (_a = column.attrMapping) == null ? void 0 : _a.start;
271
+ const endInfo = (_b = column.attrMapping) == null ? void 0 : _b.end;
272
+ if (!startInfo || !endInfo) {
273
+ return;
274
+ }
275
+ const startName = startInfo.name.replace("${name}", column.name).replace("${key}", "start");
276
+ const endName = endInfo.name.replace("${name}", column.name).replace("${key}", "end");
277
+ const object = get(params, this._formatFilterParamName(column.fullAttrName));
278
+ const start = get(object || {}, "start");
279
+ const end = get(object || {}, "end");
280
+ if (start && end) {
281
+ const group2 = where.addGroup();
282
+ const startGroup = group2.addOrGroup();
283
+ const endGroup = group2.addOrGroup();
284
+ startGroup.addCondition(startName, ">=", start);
285
+ startGroup.addCondition(startName, "<=", end);
286
+ endGroup.addCondition(endName, ">=", start);
287
+ endGroup.addCondition(endName, "<=", end);
288
+ }
289
+ return;
290
+ }
291
+ for (const key of keys) {
292
+ const info = column.attrMapping[key];
293
+ if (!info || typeof info !== "object") {
294
+ continue;
295
+ }
296
+ const name = info.name.replace("${name}", column.name).replace("${key}", key);
297
+ const object = get(params, this._formatFilterParamName(column.fullAttrName));
298
+ const value = get(object || {}, key);
299
+ if (value) {
300
+ group = group || where.addGroup();
301
+ switch (column.conditionOper) {
302
+ case "OR":
303
+ group.addOrCondition(name, info.op, value);
304
+ break;
305
+ case "AND":
306
+ default:
307
+ group.addCondition(name, info.op, value);
308
+ }
309
+ }
310
+ }
311
+ }
312
+ _getWhere(params) {
313
+ const where = new Where();
314
+ const columns = this.getAppliedColumns();
315
+ for (const column of columns) {
316
+ const key = this._formatFilterParamName(column.fullAttrName);
317
+ const value = get(params, key);
318
+ if (Array.isArray(value)) {
319
+ if (value.length === 0) {
320
+ continue;
321
+ }
322
+ const isMultipleColumn = ["BwaMultiSelect", "BwaUserMultiSelect"].includes(column.formComponent);
323
+ where.addCondition(key, isMultipleColumn ? "json_contains" : "in", value);
324
+ continue;
325
+ }
326
+ if (typeof value === "object") {
327
+ if (!value) {
328
+ continue;
329
+ }
330
+ this._parseWhereAttrMapping(where, column, params);
331
+ continue;
332
+ }
333
+ if (value) {
334
+ where.addCondition(key, "=", value);
335
+ }
336
+ }
337
+ if (this.getSearchFields().length) {
338
+ if (this.getSearchValue()) {
339
+ const group = where.addGroup();
340
+ for (let field of this.getSearchFields()) {
341
+ group.addOrCondition(field, "like", `%${this.getSearchValue()}%`);
342
+ }
343
+ }
344
+ }
345
+ return this.encryptCondition ? aesEncrypt(JSON.stringify(where), "bwa-mkbl") : JSON.stringify(where);
346
+ }
347
+ _formatFilterParamName(paramName) {
348
+ const column = this.getColumn(paramName);
349
+ if (!column) {
350
+ return paramName;
351
+ }
352
+ let segments = column.fullAttrName.split(".");
353
+ segments.pop();
354
+ return [...segments, column.name].join(".");
355
+ }
356
+ _formatFilterParam(params, column, value) {
357
+ const key = this._formatFilterParamName(column.fullAttrName);
358
+ if (value && !Array.isArray(value) && typeof value === "object" && column.attrMapping && typeof column.attrMapping === "object" && Object.values(column.attrMapping).every((value2) => typeof value2 === "string")) {
359
+ for (const key2 of Reflect.ownKeys(column.attrMapping)) {
360
+ set(params, column.attrMapping[key2], value[key2]);
361
+ }
362
+ return;
363
+ }
364
+ set(params, key, value);
365
+ }
366
+ _getAjaxFilterParams() {
367
+ const filterParams = this.getFilterParams();
368
+ const columns = this.getColumns();
369
+ const params = {};
370
+ for (const column of columns) {
371
+ this._formatFilterParam(params, column, get(filterParams, column.fullAttrName));
372
+ }
373
+ return params;
374
+ }
375
+ getAjaxParams() {
376
+ let ajaxFilterParams = this._getAjaxFilterParams();
377
+ if (this.whereForFilter) {
378
+ return {
379
+ [this.whereParamName]: this._getWhere(ajaxFilterParams)
380
+ };
381
+ }
382
+ if (this.getSearchAttr()) {
383
+ ajaxFilterParams = {
384
+ [this.getSearchAttr()]: this.getSearchValue(),
385
+ ...ajaxFilterParams
386
+ };
387
+ }
388
+ return ajaxFilterParams;
389
+ }
390
+ }
391
+
392
+ export { FilterPanel };
@@ -0,0 +1,27 @@
1
+ import DataColumn from './DataColumn.mjs';
2
+
3
+ class FormColumn extends DataColumn {
4
+ constructor(options = {}) {
5
+ var _a, _b, _c, _d, _e, _f;
6
+ super(options);
7
+ this.submitName = "";
8
+ this.rules = [];
9
+ this.required = true;
10
+ this.disabled = false;
11
+ this.submitName = (_a = options == null ? void 0 : options.submitName) != null ? _a : this.submitName;
12
+ this.rules = (_b = options == null ? void 0 : options.rules) != null ? _b : this.rules;
13
+ this.required = (_c = options == null ? void 0 : options.required) != null ? _c : this.required;
14
+ this.disabled = (_f = (_e = options == null ? void 0 : options.disabled) != null ? _e : (_d = this.componentProps) == null ? void 0 : _d.disabled) != null ? _f : false;
15
+ if (this.componentProps && typeof this.componentProps === "object") {
16
+ Reflect.deleteProperty(this.componentProps, "disabled");
17
+ }
18
+ }
19
+ disable() {
20
+ this.disabled = true;
21
+ }
22
+ enable() {
23
+ this.disabled = false;
24
+ }
25
+ }
26
+
27
+ export { FormColumn as default };
@@ -0,0 +1,34 @@
1
+ import DataColumn from './DataColumn.mjs';
2
+
3
+ const DEFAULT_SETTINGS = {
4
+ visible: true,
5
+ disabled: false
6
+ };
7
+ class TableColumn extends DataColumn {
8
+ constructor(options = {}) {
9
+ var _a, _b, _c, _d, _e, _f, _g, _h;
10
+ super(options);
11
+ this.width = "auto";
12
+ this.formComponent = "";
13
+ this.align = "center";
14
+ this.rule = "";
15
+ this.template = "${value}";
16
+ this.type = "string";
17
+ this.settings = null;
18
+ this.sortable = "";
19
+ this.width = (_a = options == null ? void 0 : options.width) != null ? _a : this.width;
20
+ this.formComponent = (_b = options.formComponent) != null ? _b : this.formComponent;
21
+ this.align = (_c = options == null ? void 0 : options.align) != null ? _c : this.align;
22
+ this.rule = (_d = options == null ? void 0 : options.rule) != null ? _d : this.rule;
23
+ this.template = (_e = options == null ? void 0 : options.template) != null ? _e : this.template;
24
+ this.type = (_f = options == null ? void 0 : options.type) != null ? _f : this.type;
25
+ this.default = (_g = options == null ? void 0 : options.default) != null ? _g : "-";
26
+ this.settings = {
27
+ ...DEFAULT_SETTINGS,
28
+ ...options == null ? void 0 : options.settings
29
+ };
30
+ this.sortable = (_h = options == null ? void 0 : options.sortable) != null ? _h : this.sortable;
31
+ }
32
+ }
33
+
34
+ export { TableColumn as default };
@@ -0,0 +1,178 @@
1
+ import get from 'lodash/get';
2
+ import { DATA_FORM, DATA_FORM_COLUMNS } from '../decorator/constant.mjs';
3
+ import { sortColumn } from '../utils/index.mjs';
4
+ import DataModel from './DataModel.mjs';
5
+ import FormColumn from './FormColumn.mjs';
6
+
7
+ class DataForm extends DataModel {
8
+ constructor(option) {
9
+ super(option);
10
+ this.changed = false;
11
+ this.locking = false;
12
+ this.disabled = false;
13
+ this.data = {};
14
+ this.formValivators = [];
15
+ this._loadCallbacks = [];
16
+ this._inited = false;
17
+ }
18
+ setOptions(options) {
19
+ if (!options.model) {
20
+ return;
21
+ }
22
+ super.setOptions({
23
+ ...options.model[DATA_FORM],
24
+ model: options.model
25
+ });
26
+ }
27
+ disable() {
28
+ this.disabled = true;
29
+ }
30
+ enable() {
31
+ this.disabled = false;
32
+ }
33
+ init() {
34
+ super.init();
35
+ const model = this.model;
36
+ if (!model) {
37
+ return;
38
+ }
39
+ if (this.extendField) {
40
+ return;
41
+ } else {
42
+ const columns = (model[DATA_FORM_COLUMNS] || []).map((columnConfig) => new FormColumn(columnConfig));
43
+ for (const column of columns) {
44
+ this.addColumn(column);
45
+ }
46
+ model.formColumns = this.getColumns().map((column) => column.attrName);
47
+ }
48
+ this.setData(null);
49
+ this._inited = true;
50
+ this.emit("init-completed");
51
+ }
52
+ setExtendFieldInfos(extendFieldInfos) {
53
+ if (this._inited) {
54
+ return;
55
+ }
56
+ this.extendFieldInfos = extendFieldInfos;
57
+ const formColumns = extendFieldInfos.map((extendField) => {
58
+ var _a;
59
+ return new FormColumn({
60
+ name: extendField.name,
61
+ title: extendField.title,
62
+ attrName: extendField.name,
63
+ submitName: extendField.name,
64
+ default: extendField.defaultValue || "",
65
+ isExtend: !extendField.type,
66
+ required: !!extendField.isRequired,
67
+ component: extendField.component,
68
+ componentProps: (_a = extendField.extendInfo) != null ? _a : {},
69
+ fullAttrName: `${this.extendField}.${extendField.name}`
70
+ });
71
+ });
72
+ this.setColumns(formColumns);
73
+ this.setData(null);
74
+ this._inited = true;
75
+ for (const callback of this._loadCallbacks) {
76
+ callback();
77
+ }
78
+ this.emit("init-completed");
79
+ }
80
+ setData(data) {
81
+ if (data) {
82
+ this.data = data;
83
+ } else {
84
+ this.reset();
85
+ }
86
+ this.ready = true;
87
+ }
88
+ reset() {
89
+ this.setData(this.formatData({}));
90
+ }
91
+ async loadDataByRecId(params) {
92
+ if (!this._inited) {
93
+ return new Promise((resolve, reject) => {
94
+ this._loadCallbacks.push(() => {
95
+ this.loadDataByRecId(params).then(resolve, reject);
96
+ });
97
+ });
98
+ }
99
+ this.locking = true;
100
+ if (typeof params !== "object") {
101
+ params = {
102
+ [this.primaryKey]: params
103
+ };
104
+ }
105
+ params = {
106
+ ...this.defaultParams,
107
+ ...params
108
+ };
109
+ this.emit("before-load", params);
110
+ return this.adapter.loadDataByRecIdHandle(this, params).then((res) => {
111
+ const data = this.formatData(Array.isArray(res.data) ? res.data[0] : res.data);
112
+ this.setData(data);
113
+ this.emit("load-successfully", res);
114
+ return res;
115
+ }).catch((e) => {
116
+ this.emit("load-failed", e);
117
+ return Promise.reject(e);
118
+ }).finally(() => {
119
+ this.locking = false;
120
+ this.emit("load-complete");
121
+ });
122
+ }
123
+ formatSubmitData(data) {
124
+ return this._format(data, "submitName");
125
+ }
126
+ sortColumns(columns) {
127
+ return sortColumn(columns, this.model.formColumns || []);
128
+ }
129
+ async validate() {
130
+ if (!this.formValivators.length) {
131
+ return Promise.resolve(false);
132
+ }
133
+ const validateResults = await Promise.all(this.formValivators.map((validator) => validator.validate().then(() => true, () => false)));
134
+ return validateResults.reduce((result, item) => result && item, true);
135
+ }
136
+ async submit(data = {}) {
137
+ if (this.disabled) {
138
+ throw new Error("\u7981\u7528\u72B6\u6001\u4E0D\u80FD\u4FDD\u5B58");
139
+ }
140
+ if (this.locking) {
141
+ return;
142
+ }
143
+ if (!await this.validate()) {
144
+ return;
145
+ }
146
+ this.locking = true;
147
+ const submitData = {};
148
+ for (let column of this.getColumns().filter((column2) => !column2.isExtend)) {
149
+ submitData[column.submitName] = this.data[column.attrName];
150
+ }
151
+ if (this.extendField) {
152
+ let extendObject = {};
153
+ for (let column of this.getColumns().filter((column2) => column2.isExtend)) {
154
+ extendObject[column.attrName] = get(this.data, column.fullAttrName);
155
+ }
156
+ submitData[this.extendField] = extendObject;
157
+ }
158
+ Object.assign(submitData, data);
159
+ this.emit("before-submit", data);
160
+ return this.adapter.submitHandle(this, submitData).then((res) => {
161
+ this.emit("submit-successfully", res);
162
+ return res;
163
+ }).catch((e) => {
164
+ this.emit("submit-failed", e);
165
+ return Promise.reject(e);
166
+ }).finally(() => {
167
+ this.emit("submit-complete");
168
+ this.locking = false;
169
+ });
170
+ }
171
+ setDisplayColumns(displayColumns) {
172
+ const displayColumnNames = displayColumns.map((column) => column.fullAttrName);
173
+ this._displayColumns = this.getColumns().filter((column) => displayColumnNames.includes(column.fullAttrName));
174
+ this.getDisplayColumnsSubject().next(this.getDisplayColumns());
175
+ }
176
+ }
177
+
178
+ export { DataForm as default };
@@ -0,0 +1,63 @@
1
+ import { Condition } from './Condition.mjs';
2
+ import { SingleCondition } from './SingleCondition.mjs';
3
+
4
+ class CombineCondition extends Condition {
5
+ constructor(...args) {
6
+ super(...args);
7
+ this.conditions = [];
8
+ }
9
+ addCondition(fieldName, operator, value) {
10
+ const condition = new SingleCondition(fieldName, operator, value);
11
+ if (this.conditions.length) {
12
+ this.conditions.push("AND");
13
+ }
14
+ this.conditions.push(condition);
15
+ return condition;
16
+ }
17
+ addOrCondition(fieldName, operator, value) {
18
+ const condition = new SingleCondition(fieldName, operator, value);
19
+ if (this.conditions.length) {
20
+ this.conditions.push("OR");
21
+ }
22
+ this.conditions.push(condition);
23
+ return condition;
24
+ }
25
+ addGroup(group) {
26
+ const _group = group || new CombineCondition();
27
+ if (this.conditions.length) {
28
+ this.conditions.push("AND");
29
+ }
30
+ this.conditions.push(_group);
31
+ return _group;
32
+ }
33
+ addOrGroup(group) {
34
+ const _group = group || new CombineCondition();
35
+ if (this.conditions.length) {
36
+ this.conditions.push("OR");
37
+ }
38
+ this.conditions.push(_group);
39
+ return _group;
40
+ }
41
+ removeCondition(fieldName) {
42
+ let index = this.conditions.findIndex((condition) => condition instanceof SingleCondition && condition.f === fieldName);
43
+ if (index === 0) {
44
+ this.conditions.splice(index, 1);
45
+ return;
46
+ }
47
+ this.conditions.splice(index - 1, 2);
48
+ const combineConditions = this.conditions.filter((condition) => condition instanceof CombineCondition);
49
+ for (let i = combineConditions.length - 1; i >= 0; i--) {
50
+ const combineCondition = combineConditions[i];
51
+ combineCondition.removeCondition(fieldName);
52
+ if (!combineCondition.conditions.length) {
53
+ const index2 = this.conditions.indexOf(combineCondition);
54
+ this.conditions.splice(index2, 1);
55
+ }
56
+ }
57
+ }
58
+ toJSON() {
59
+ return this.conditions.map((condition) => condition instanceof Condition ? condition.toJSON() : condition);
60
+ }
61
+ }
62
+
63
+ export { CombineCondition };
@@ -0,0 +1,4 @@
1
+ class Condition {
2
+ }
3
+
4
+ export { Condition };