@ctzy-web-client/data-model 1.0.4 → 1.0.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.
Files changed (51) hide show
  1. package/package.json +33 -33
  2. package/es/SimpleOrm.mjs +0 -85
  3. package/es/_virtual/_rollupPluginBabelHelpers.mjs +0 -2830
  4. package/es/abstract/DataColumn.mjs +0 -65
  5. package/es/abstract/DataForm.mjs +0 -178
  6. package/es/abstract/DataModel.mjs +0 -223
  7. package/es/abstract/DataModelAdapter.mjs +0 -86
  8. package/es/abstract/DataTable.mjs +0 -339
  9. package/es/abstract/FilterColumn.mjs +0 -44
  10. package/es/abstract/FilterPanel.mjs +0 -392
  11. package/es/abstract/FormColumn.mjs +0 -27
  12. package/es/abstract/TableColumn.mjs +0 -34
  13. package/es/abstract/dataForm2.mjs +0 -178
  14. package/es/abstract/where/CombineCondition.mjs +0 -63
  15. package/es/abstract/where/Condition.mjs +0 -4
  16. package/es/abstract/where/SingleCondition.mjs +0 -22
  17. package/es/abstract/where/Where.mjs +0 -21
  18. package/es/decorator/constant.mjs +0 -11
  19. package/es/decorator/dataForm.mjs +0 -18
  20. package/es/decorator/dataTable.mjs +0 -18
  21. package/es/decorator/filterColumn.mjs +0 -21
  22. package/es/decorator/formColumn.mjs +0 -19
  23. package/es/decorator/tableColumn.mjs +0 -20
  24. package/es/factory.mjs +0 -14
  25. package/es/index.mjs +0 -14
  26. package/es/utils/index.mjs +0 -15
  27. package/lib/SimpleOrm.js +0 -89
  28. package/lib/_virtual/_rollupPluginBabelHelpers.js +0 -2948
  29. package/lib/abstract/DataColumn.js +0 -69
  30. package/lib/abstract/DataForm.js +0 -186
  31. package/lib/abstract/DataModel.js +0 -231
  32. package/lib/abstract/DataModelAdapter.js +0 -90
  33. package/lib/abstract/DataTable.js +0 -343
  34. package/lib/abstract/FilterColumn.js +0 -48
  35. package/lib/abstract/FilterPanel.js +0 -396
  36. package/lib/abstract/FormColumn.js +0 -31
  37. package/lib/abstract/TableColumn.js +0 -38
  38. package/lib/abstract/dataForm2.js +0 -186
  39. package/lib/abstract/where/CombineCondition.js +0 -67
  40. package/lib/abstract/where/Condition.js +0 -8
  41. package/lib/abstract/where/SingleCondition.js +0 -26
  42. package/lib/abstract/where/Where.js +0 -25
  43. package/lib/decorator/constant.js +0 -20
  44. package/lib/decorator/dataForm.js +0 -22
  45. package/lib/decorator/dataTable.js +0 -22
  46. package/lib/decorator/filterColumn.js +0 -25
  47. package/lib/decorator/formColumn.js +0 -23
  48. package/lib/decorator/tableColumn.js +0 -24
  49. package/lib/factory.js +0 -19
  50. package/lib/index.js +0 -36
  51. package/lib/utils/index.js +0 -19
@@ -1,343 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var lodash = require('lodash');
6
- var constant = require('../decorator/constant.js');
7
- var index = require('../utils/index.js');
8
- var DataModel = require('./DataModel.js');
9
- require('./FilterColumn.js');
10
- var TableColumn = require('./TableColumn.js');
11
- var FilterPanel = require('./FilterPanel.js');
12
-
13
- class DataTable extends DataModel["default"] {
14
- get filterColumns() {
15
- return this.filterPanel.getColumns();
16
- }
17
- get locking() {
18
- return this._loadingCount > 0;
19
- }
20
- get searchParams() {
21
- return this.filterPanel._filterParams;
22
- }
23
- set whereForFilter(v) {
24
- this._options.whereForFilter = v;
25
- if (this.filterPanel) {
26
- this.filterPanel.whereForFilter = v;
27
- }
28
- }
29
- get whereForFilter() {
30
- return this._options.whereForFilter;
31
- }
32
- set whereParamName(v) {
33
- this.filterPanel.whereParamName = v;
34
- }
35
- get whereParamName() {
36
- return this.filterPanel.whereParamName;
37
- }
38
- set encryptCondition(v) {
39
- this.filterPanel.encryptCondition = v;
40
- }
41
- get encryptCondition() {
42
- return this.filterPanel.encryptCondition;
43
- }
44
- constructor(option) {
45
- super(option);
46
- this._userService = null;
47
- this._loadingCount = 0;
48
- this.totalRecCount = 0;
49
- this.pageNum = 1;
50
- this.pageSize = 20;
51
- this.selection = [];
52
- this.data = [];
53
- this._defaultColumnSort = [];
54
- this.inited = false;
55
- this.filterPanel = new FilterPanel.FilterPanel(this);
56
- this.whereForFilter = this.whereForFilter;
57
- this._loadCallbacks = [];
58
- this.filterPanel.on("ready", () => {
59
- for (let callback of this._loadCallbacks) {
60
- callback();
61
- }
62
- });
63
- }
64
- getTotalPage() {
65
- const totalPage = Math.ceil(this.totalRecCount / this.pageSize);
66
- return Number.isNaN(totalPage) ? 0 : totalPage;
67
- }
68
- setOptions(options) {
69
- var _a;
70
- if (!options.model) {
71
- return;
72
- }
73
- super.setOptions({
74
- ...options.model[constant.DATA_TABLE],
75
- model: options.model
76
- });
77
- this.whereForFilter = (_a = options.model[constant.DATA_TABLE].whereForFilter) != null ? _a : false;
78
- }
79
- setSelection(selection) {
80
- const oldSelection = this.selection;
81
- this.selection = selection;
82
- this.emit("select-change", selection, oldSelection);
83
- }
84
- getSelection() {
85
- return this.selection;
86
- }
87
- clearSelection() {
88
- this.setSelection([]);
89
- }
90
- setWhereParamName(whereParamName) {
91
- this.whereParamName = whereParamName;
92
- }
93
- init() {
94
- if (this.inited) {
95
- return;
96
- }
97
- super.init();
98
- const model = this.model;
99
- if (!model) {
100
- return;
101
- }
102
- if (this.extendField) {
103
- this._loadingCount++;
104
- return;
105
- } else {
106
- let tableColumnConfigs = model.tableColumns || [];
107
- const tableColumns = (model[constant.DATA_TABLE_COLUMNS] || []).map((columnConfig) => new TableColumn["default"]({
108
- type: columnConfig.formComponent === "BwaRichText" ? "html" : "",
109
- ...columnConfig
110
- }));
111
- tableColumnConfigs = tableColumnConfigs.concat(tableColumns.filter((column) => !tableColumnConfigs.includes(column.name)).map((column) => column.attrName));
112
- index.sortColumn(tableColumns, tableColumnConfigs).forEach((tableColumn) => {
113
- this.addColumn(tableColumn);
114
- });
115
- }
116
- this._defaultColumnSort = this.getColumns().map((column) => ({
117
- name: column.attrName,
118
- visible: column.visible
119
- }));
120
- this.filterPanel.init([], model[constant.DATA_TABLE_FILTER_COLUMN] || [], model.filterColumns || []);
121
- this.inited = true;
122
- this.emit("init-completed");
123
- }
124
- setData(data, append = false) {
125
- if (!append) {
126
- this.data.length = 0;
127
- }
128
- this.data.push(...data);
129
- this.ready = true;
130
- }
131
- async setDataBeforeMount(data = []) {
132
- if (this.extendFieldInfos.every((a) => a.type !== 0)) {
133
- return data;
134
- }
135
- const colMap = {};
136
- let userListResult = {};
137
- if (this.extendFieldInfos.some((a) => ["BwaUserSelect", "BwaUserMultiSelect"].includes(a.component))) {
138
- if (this._userService) {
139
- userListResult = await this._userService({
140
- name: ""
141
- });
142
- }
143
- }
144
- this.extendFieldInfos.forEach((e) => {
145
- var _a;
146
- if (e.type === 0) {
147
- if (["BwaSelect", "BwaMultiSelect"].includes(e.component)) {
148
- colMap[e.name] = (_a = e.extendInfo) == null ? void 0 : _a.options;
149
- }
150
- if (["BwaUserSelect", "BwaUserMultiSelect"].includes(e.component)) {
151
- colMap[e.name] = (userListResult == null ? void 0 : userListResult.data) || [];
152
- }
153
- }
154
- });
155
- const getValueByString = (key, value) => {
156
- let arr = colMap[key] || [];
157
- let find = arr.find((item) => item.value == value);
158
- return find ? find.label : value || "-";
159
- };
160
- const getValueByArray = (key, valueList) => {
161
- let list = [];
162
- valueList.forEach((v) => {
163
- list.push(getValueByString(key, v));
164
- });
165
- return list;
166
- };
167
- data.forEach((e) => {
168
- let obj = e.columnJson || e.json || {};
169
- Object.keys(obj).forEach((key) => {
170
- if (["string", "number"].includes(typeof obj[key]))
171
- obj[key] = getValueByString(key, obj[key]);
172
- if (Array.isArray(obj[key]))
173
- obj[key] = getValueByArray(key, obj[key]);
174
- });
175
- });
176
- return data;
177
- }
178
- async load(params) {
179
- if (!this.filterPanel.ready) {
180
- return new Promise((resolve, reject) => {
181
- this._loadCallbacks.push(() => {
182
- this.load(params).then(resolve, reject);
183
- });
184
- });
185
- }
186
- this.ready = false;
187
- this._loadingCount++;
188
- const loadParams = {
189
- [this.adapter.pagerNumParamName]: this.pageNum,
190
- [this.adapter.recCountParamName]: this.pageSize,
191
- ...this.defaultParams,
192
- ...this.filterPanel.getAjaxParams(),
193
- ...params
194
- };
195
- this.emit("before-load", loadParams);
196
- return this.adapter.loadDataListHandle(this, loadParams).then((res) => {
197
- this.totalRecCount = res[this.adapter.totalRecCountNodeName] ? res[this.adapter.totalRecCountNodeName] * 1 : 0;
198
- const data = (res[this.adapter.dataNodeName] || []).map(this.formatData.bind(this));
199
- this.setDataBeforeMount(data).then((arr) => {
200
- this.setData(arr);
201
- });
202
- this.emit("load-successfully", res);
203
- return res;
204
- }).catch((e) => {
205
- this.emit("load-failed", e);
206
- return Promise.reject(e);
207
- }).finally(() => {
208
- this.emit("load-complete");
209
- this._loadingCount--;
210
- });
211
- }
212
- refresh() {
213
- return this.load();
214
- }
215
- pageTo(pageNum) {
216
- this.pageNum = pageNum || 1;
217
- this.emit("current-page-change", this.pageNum);
218
- return this.refresh();
219
- }
220
- setPageSize(pageSize) {
221
- this.pageSize = pageSize;
222
- this.emit("page-size-change", this.pageSize);
223
- return this.refresh();
224
- }
225
- async delete(params) {
226
- if (this.locking) {
227
- return;
228
- }
229
- this._loadingCount++;
230
- if (typeof params !== "object") {
231
- params = {
232
- [this.primaryKey]: params
233
- };
234
- }
235
- return this.adapter.deleteHandle(this, params).then((res) => {
236
- this.emit("delete-successfully", res);
237
- return res;
238
- }).catch((e) => {
239
- this.emit("delete-failed", e);
240
- throw e;
241
- }).finally(() => {
242
- this._loadingCount--;
243
- this.emit("delete-complete");
244
- });
245
- }
246
- formatExtendFieldInfo(extendFieldInfo) {
247
- return {
248
- ...super.formatExtendFieldInfo(extendFieldInfo),
249
- component: "",
250
- formComponent: extendFieldInfo.component,
251
- visible: !!extendFieldInfo.enablePageShow
252
- };
253
- }
254
- mergeTableColumn(formatedExtendFieldInfo, modelFieldInfo) {
255
- var _a;
256
- return {
257
- ...super.mergeTableColumn(formatedExtendFieldInfo, modelFieldInfo),
258
- visible: (_a = modelFieldInfo == null ? void 0 : modelFieldInfo.visible) != null ? _a : true
259
- };
260
- }
261
- setExtendFieldInfos(extendFieldInfos) {
262
- this.extendFieldInfos = extendFieldInfos;
263
- const mergedColumnInfos = this.mergeTableColumns(extendFieldInfos, this.model[constant.DATA_TABLE_COLUMNS]);
264
- const tableColumns = mergedColumnInfos.map((columnInfo) => new TableColumn["default"]({
265
- type: columnInfo.formComponent === "BwaRichText" ? "html" : "",
266
- ...columnInfo
267
- }));
268
- this.setColumns(tableColumns);
269
- this._defaultColumnSort = this.getColumns().map((column) => ({
270
- name: column.attrName,
271
- visible: column.visible
272
- }));
273
- this.filterPanel.init(extendFieldInfos, this.model[constant.DATA_TABLE_FILTER_COLUMN] || [], this.model.filterColumns || []);
274
- this._loadingCount--;
275
- this.inited = true;
276
- this.emit("init-completed");
277
- }
278
- async refreshAfterDelete(params) {
279
- const deleteResult = await this.delete(params);
280
- this.refresh();
281
- return deleteResult;
282
- }
283
- sortColumns(columns) {
284
- return index.sortColumn(columns, this.model.tableColumns || []);
285
- }
286
- resetColumnSort() {
287
- if (this.isDefaultColumnSort()) {
288
- return;
289
- }
290
- this._defaultColumnSort.forEach((item) => {
291
- const column = this.getColumn(item.name);
292
- if (column) {
293
- column.visible = item.visible;
294
- }
295
- });
296
- const displayColumns = this._defaultColumnSort.filter((item) => item.visible).map((item) => {
297
- return this.getColumn(item.name);
298
- });
299
- this.setDisplayColumns(displayColumns);
300
- }
301
- isDefaultColumnSort() {
302
- const displayColumns = this.getDisplayColumns();
303
- const defaultVisibleColumnInfos = this._defaultColumnSort.filter((item) => item.visible);
304
- if (displayColumns.length !== defaultVisibleColumnInfos.length) {
305
- return false;
306
- }
307
- for (let i = 0; i < displayColumns.length; i++) {
308
- if (displayColumns[i].attrName !== defaultVisibleColumnInfos[i].name || displayColumns[i].visible !== defaultVisibleColumnInfos[i].visible) {
309
- return false;
310
- }
311
- }
312
- return true;
313
- }
314
- addFilterColumn(column) {
315
- this.filterPanel.addColumn(column);
316
- }
317
- removeFilterColumn(column) {
318
- this.filterPanel.removeColumn(column);
319
- }
320
- setFilterColumns(columns) {
321
- this.filterPanel.setColumns(columns);
322
- }
323
- getFilterColumns() {
324
- return this.filterPanel.getColumns();
325
- }
326
- getFilterColumn(columnName) {
327
- return this.filterPanel.getColumn(columnName);
328
- }
329
- resetSearchParams() {
330
- this.filterPanel.resetFilterParams();
331
- }
332
- clone() {
333
- const cloned = super.clone();
334
- cloned.data = lodash.cloneDeep(this.data);
335
- cloned.filterPanel = lodash.cloneDeep(this.filterPanel);
336
- cloned.selection = this.selection.map((select) => {
337
- return cloned.data.find((item) => item[this.primaryKey] === select[this.primaryKey]);
338
- }).filter(Boolean);
339
- return cloned;
340
- }
341
- }
342
-
343
- exports["default"] = DataTable;
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var DataColumn = require('./DataColumn.js');
6
-
7
- class FilterColumn extends DataColumn["default"] {
8
- constructor(filterPanel, options) {
9
- var _a, _b, _c, _d;
10
- super(options);
11
- this.closable = true;
12
- this.attrMapping = {
13
- start: {
14
- name: "${name}",
15
- op: ">="
16
- },
17
- end: {
18
- name: "${name}",
19
- op: "<="
20
- }
21
- };
22
- this.conditionOper = "AND";
23
- this.formComponent = "";
24
- this.twoFieldsDatePicker = false;
25
- this.closable = (_a = options.closable) != null ? _a : this.closable;
26
- this.attrMapping = (_c = (_b = options.attrMapping) != null ? _b : options.whereAttrMapping) != null ? _c : this.attrMapping;
27
- this.filterPanel = filterPanel;
28
- this.conditionOper = options.conditionOper;
29
- this.formComponent = (_d = options.formComponent) != null ? _d : this.formComponent;
30
- this.twoFieldsDatePicker = options.twoFieldsDatePicker;
31
- }
32
- show() {
33
- const visible = this.visible;
34
- super.show();
35
- if (visible !== this.visible) {
36
- this.filterPanel.appliedColumn(this);
37
- }
38
- }
39
- hide() {
40
- const visible = this.visible;
41
- super.hide();
42
- if (visible !== this.visible) {
43
- this.filterPanel.cancelAppliedColumn(this);
44
- }
45
- }
46
- }
47
-
48
- exports["default"] = FilterColumn;