@ctzy-web-client/data-model 1.0.6 → 1.0.7

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 +1 -1
@@ -0,0 +1,22 @@
1
+ import { Condition } from './Condition.mjs';
2
+
3
+ class SingleCondition extends Condition {
4
+ constructor(f, o, v) {
5
+ super();
6
+ this.f = "";
7
+ this.o = "=";
8
+ this.v = "";
9
+ this.f = f;
10
+ this.v = v;
11
+ this.o = o;
12
+ }
13
+ toJSON() {
14
+ return {
15
+ f: this.f,
16
+ o: this.o,
17
+ v: this.v
18
+ };
19
+ }
20
+ }
21
+
22
+ export { SingleCondition };
@@ -0,0 +1,21 @@
1
+ import { CombineCondition } from './CombineCondition.mjs';
2
+ import { SingleCondition } from './SingleCondition.mjs';
3
+
4
+ class Where extends CombineCondition {
5
+ getCondition(fieldName) {
6
+ let conditions = this.conditions.slice();
7
+ for (let i = 0; i < conditions.length; i++) {
8
+ const condition = conditions[i];
9
+ if (condition instanceof CombineCondition) {
10
+ conditions = conditions.concat(condition.conditions);
11
+ } else if (condition instanceof SingleCondition) {
12
+ if (condition.f === fieldName) {
13
+ return condition;
14
+ }
15
+ }
16
+ }
17
+ return null;
18
+ }
19
+ }
20
+
21
+ export { Where };
@@ -0,0 +1,11 @@
1
+ const DATA_MODEL_DEFINE = {
2
+ table: Symbol("DATA TABLE DEFINE"),
3
+ form: Symbol("DATA FORM DEFINE")
4
+ };
5
+ const DATA_TABLE = "DATA_TABLE";
6
+ const DATA_FORM = "DATA_FORM";
7
+ const DATA_TABLE_COLUMNS = "DATA_TABLE_COLUMNS";
8
+ const DATA_TABLE_FILTER_COLUMN = "DATA_TABLE_FILTER_COLUMN";
9
+ const DATA_FORM_COLUMNS = "DATA_FORM_COLUMNS";
10
+
11
+ export { DATA_FORM, DATA_FORM_COLUMNS, DATA_MODEL_DEFINE, DATA_TABLE, DATA_TABLE_COLUMNS, DATA_TABLE_FILTER_COLUMN };
@@ -0,0 +1,18 @@
1
+ import { DATA_FORM } from './constant.mjs';
2
+ import '../abstract/DataForm.mjs';
3
+
4
+ function dataForm(option) {
5
+ return function decorator(classType) {
6
+ if (classType.constructor !== Function) {
7
+ throw new Error(`@dataForm \u53EA\u80FD\u7528\u4E8E\u7C7B\u7684\u6CE8\u89E3`);
8
+ }
9
+ let dataForm2 = classType[DATA_FORM];
10
+ if (dataForm2) {
11
+ return;
12
+ }
13
+ dataForm2 = classType[DATA_FORM] = option;
14
+ return classType;
15
+ };
16
+ }
17
+
18
+ export { dataForm as default };
@@ -0,0 +1,18 @@
1
+ import { DATA_MODEL_DEFINE, DATA_TABLE } from './constant.mjs';
2
+ import '../abstract/DataTable.mjs';
3
+
4
+ function dataTable(option) {
5
+ return function decorator(classType) {
6
+ if (classType.constructor !== Function) {
7
+ throw new Error(`@dataTable \u53EA\u80FD\u7528\u4E8E\u7C7B\u7684\u6CE8\u89E3`);
8
+ }
9
+ let dataTable2 = classType[DATA_MODEL_DEFINE.table];
10
+ if (dataTable2) {
11
+ return;
12
+ }
13
+ classType[DATA_TABLE] = option;
14
+ return classType;
15
+ };
16
+ }
17
+
18
+ export { dataTable as default };
@@ -0,0 +1,21 @@
1
+ import { DATA_TABLE_FILTER_COLUMN } from './constant.mjs';
2
+
3
+ function filterColumn(options) {
4
+ return function(target, key, description) {
5
+ if (arguments.length !== 3 || target.constructor === Function || typeof description.value === "function") {
6
+ throw new Error(`@formColumn \u53EA\u80FD\u4F7F\u7528\u5728\u7C7B\u7684\u6210\u5458\u53D8\u91CF\u4E2D`);
7
+ }
8
+ target.constructor[DATA_TABLE_FILTER_COLUMN] = target.constructor[DATA_TABLE_FILTER_COLUMN] || [];
9
+ const columns = target.constructor[DATA_TABLE_FILTER_COLUMN];
10
+ options = {
11
+ name: key,
12
+ attrName: key,
13
+ closable: false,
14
+ ...options
15
+ };
16
+ options.visible = !options.closable;
17
+ columns.push(options);
18
+ };
19
+ }
20
+
21
+ export { filterColumn as default };
@@ -0,0 +1,19 @@
1
+ import { DATA_FORM_COLUMNS } from './constant.mjs';
2
+
3
+ function formColumn(option) {
4
+ return function(target, key, description) {
5
+ if (arguments.length !== 3 || target.constructor === Function || typeof description.value === "function") {
6
+ throw new Error(`@formColumn \u53EA\u80FD\u4F7F\u7528\u5728\u7C7B\u7684\u6210\u5458\u53D8\u91CF\u4E2D`);
7
+ }
8
+ target.constructor[DATA_FORM_COLUMNS] = target.constructor[DATA_FORM_COLUMNS] || [];
9
+ const columns = target.constructor[DATA_FORM_COLUMNS];
10
+ columns.push({
11
+ name: key,
12
+ submitName: option.name || key,
13
+ ...option,
14
+ attrName: key
15
+ });
16
+ };
17
+ }
18
+
19
+ export { formColumn as default };
@@ -0,0 +1,20 @@
1
+ import { DATA_TABLE_COLUMNS } from './constant.mjs';
2
+ import '../abstract/DataTable.mjs';
3
+ import '../abstract/TableColumn.mjs';
4
+
5
+ function tableColumn(option) {
6
+ return function(target, key, description) {
7
+ if (arguments.length !== 3 || target.constructor === Function || typeof description.value === "function") {
8
+ throw new Error(`@tableColumn \u53EA\u80FD\u4F7F\u7528\u5728\u7C7B\u7684\u6210\u5458\u53D8\u91CF\u4E2D`);
9
+ }
10
+ target.constructor[DATA_TABLE_COLUMNS] = target.constructor[DATA_TABLE_COLUMNS] || [];
11
+ const columns = target.constructor[DATA_TABLE_COLUMNS];
12
+ columns.push({
13
+ name: key,
14
+ attrName: key,
15
+ ...option
16
+ });
17
+ };
18
+ }
19
+
20
+ export { tableColumn as default };
package/es/factory.mjs ADDED
@@ -0,0 +1,14 @@
1
+ import { DATA_MODEL_DEFINE } from './decorator/constant.mjs';
2
+ import DataTable from './abstract/DataTable.mjs';
3
+ import './abstract/dataForm2.mjs';
4
+
5
+ const createDataTable = function(classType) {
6
+ const baseDataTable = classType[DATA_MODEL_DEFINE.table];
7
+ return baseDataTable ? baseDataTable.clone() : new DataTable();
8
+ };
9
+ const createDataForm = function(classType) {
10
+ const baseDataForm = classType[DATA_MODEL_DEFINE.form];
11
+ return baseDataForm ? baseDataForm.clone() : new dataForm();
12
+ };
13
+
14
+ export { createDataForm, createDataTable };
package/es/index.mjs ADDED
@@ -0,0 +1,14 @@
1
+ export { default as DataTable } from './abstract/DataTable.mjs';
2
+ export { default as DataForm } from './abstract/DataForm.mjs';
3
+ export { FilterPanel } from './abstract/FilterPanel.mjs';
4
+ export { default as DataModelAdapter } from './abstract/DataModelAdapter.mjs';
5
+ export { default as dataTable } from './decorator/dataTable.mjs';
6
+ export { default as dataForm } from './decorator/dataForm.mjs';
7
+ export { default as tableColumn } from './decorator/tableColumn.mjs';
8
+ export { default as formColumn } from './decorator/formColumn.mjs';
9
+ export { default as SimpleOrm } from './SimpleOrm.mjs';
10
+ export { default as filterColumn } from './decorator/filterColumn.mjs';
11
+ export { CombineCondition } from './abstract/where/CombineCondition.mjs';
12
+ export { SingleCondition } from './abstract/where/SingleCondition.mjs';
13
+ export { Where } from './abstract/where/Where.mjs';
14
+ export { createDataForm, createDataTable } from './factory.mjs';
@@ -0,0 +1,15 @@
1
+ const sortColumn = (columns, order) => {
2
+ return [...columns].sort((a, b) => {
3
+ const aIndex = order.indexOf(a.attrName);
4
+ const bIndex = order.indexOf(b.attrName);
5
+ if (aIndex === -1 && bIndex === -1) {
6
+ return 0;
7
+ }
8
+ if (aIndex !== -1 && bIndex !== -1) {
9
+ return aIndex - bIndex;
10
+ }
11
+ return aIndex === -1 ? 1 : -1;
12
+ });
13
+ };
14
+
15
+ export { sortColumn };
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
6
+ var iocAnnotations = require('@ctzy-web-client/ioc-annotations');
7
+ var ioc = require('@ctzy-web-client/ioc');
8
+ var DataModelAdapter = require('./abstract/DataModelAdapter.js');
9
+ var DataTable = require('./abstract/DataTable.js');
10
+ var dataForm = require('./abstract/dataForm2.js');
11
+
12
+ var _dec, _dec2, _class, _descriptor, _descriptor2;
13
+ let SimpleOrm = (_dec = iocAnnotations.inject(DataModelAdapter["default"]), _dec2 = iocAnnotations.inject(ioc.InstantiationService), _class = class SimpleOrm2 {
14
+ constructor() {
15
+ _rollupPluginBabelHelpers.initializerDefineProperty(this, "adapter", _descriptor, this);
16
+ _rollupPluginBabelHelpers.initializerDefineProperty(this, "instantiationService", _descriptor2, this);
17
+ }
18
+ createDataTable(model, options = {}) {
19
+ return this.instantiationService.createInstance(DataTable["default"], {
20
+ args: [{
21
+ model
22
+ }]
23
+ });
24
+ }
25
+ createDataForm(model, options = {}) {
26
+ return this.instantiationService.createInstance(dataForm["default"], {
27
+ args: [{
28
+ model
29
+ }]
30
+ });
31
+ }
32
+ async fill(classType, params2, maxRecCount = 1e4) {
33
+ const dataTable = this.createDataForm(classType);
34
+ return dataTable.adapter.loadDataListHandle(dataTable, Object.assign({
35
+ [dataTable.adapter.pagerNumParamName]: 1,
36
+ [dataTable.adapter.recCountParamName]: maxRecCount
37
+ }, params2)).then((res) => {
38
+ return res.data.map((dataItem) => {
39
+ let modelInstance = new classType();
40
+ dataTable.getColumns().forEach((column) => {
41
+ modelInstance[column.attrName] = dataItem[column.name];
42
+ });
43
+ return modelInstance;
44
+ });
45
+ });
46
+ }
47
+ async first(classType, params2) {
48
+ return this.fill(classType, params2, 1).then((data) => {
49
+ return data[0] || null;
50
+ });
51
+ }
52
+ async firstByRecId(classType, recId) {
53
+ const dataTable = this.createDataTable(classType);
54
+ return this.adapter.loadDataByRecIdHandle(dataTable, Object.assign({
55
+ [this.primaryKey]: recId
56
+ }, params)).then((data) => {
57
+ const result = Array.isArray(data.data) ? data.data[0] : data.data;
58
+ if (result) {
59
+ let modelInstance = new classType();
60
+ dataTable.getColumns().forEach((column) => {
61
+ modelInstance[column.attrName] = result[column.name];
62
+ });
63
+ return modelInstance;
64
+ }
65
+ return result;
66
+ });
67
+ }
68
+ submit(classType, data) {
69
+ const dataForm = this.createDataForm(classType);
70
+ dataForm.adapter = this.adapter;
71
+ return dataForm.submit(data);
72
+ }
73
+ }, _descriptor = _rollupPluginBabelHelpers.applyDecoratedDescriptor(_class.prototype, "adapter", [_dec], {
74
+ configurable: true,
75
+ enumerable: true,
76
+ writable: true,
77
+ initializer: function() {
78
+ return null;
79
+ }
80
+ }), _descriptor2 = _rollupPluginBabelHelpers.applyDecoratedDescriptor(_class.prototype, "instantiationService", [_dec2], {
81
+ configurable: true,
82
+ enumerable: true,
83
+ writable: true,
84
+ initializer: function() {
85
+ return null;
86
+ }
87
+ }), _class);
88
+
89
+ exports["default"] = SimpleOrm;