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