@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.
- 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 +1 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var rxjs = require('rxjs');
|
|
6
|
+
|
|
7
|
+
class DataColumn {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
10
|
+
this.title = "";
|
|
11
|
+
this.name = "";
|
|
12
|
+
this.attrName = "";
|
|
13
|
+
this.fullAttrName = "";
|
|
14
|
+
this.default = void 0;
|
|
15
|
+
this._visible = true;
|
|
16
|
+
this.component = void 0;
|
|
17
|
+
this.isExtend = false;
|
|
18
|
+
this.componentTitle = "";
|
|
19
|
+
this.componentProps = void 0;
|
|
20
|
+
this._visibleSubject = null;
|
|
21
|
+
this.title = (_a = options == null ? void 0 : options.title) != null ? _a : this.title;
|
|
22
|
+
this.name = (_b = options == null ? void 0 : options.name) != null ? _b : this.name;
|
|
23
|
+
this.attrName = (_c = options == null ? void 0 : options.attrName) != null ? _c : this.attrName;
|
|
24
|
+
this.default = (_d = options == null ? void 0 : options.default) != null ? _d : this.default;
|
|
25
|
+
this._visible = (_e = options == null ? void 0 : options.visible) != null ? _e : this._visible;
|
|
26
|
+
this.component = (_f = options == null ? void 0 : options.component) != null ? _f : this.component;
|
|
27
|
+
this.componentTitle = (_g = options == null ? void 0 : options.componentTitle) != null ? _g : this.componentTitle;
|
|
28
|
+
this.componentProps = (_h = options == null ? void 0 : options.componentProps) != null ? _h : this.componentProps;
|
|
29
|
+
this.isExtend = (_i = options == null ? void 0 : options.isExtend) != null ? _i : this.isExtend;
|
|
30
|
+
this.fullAttrName = this.isExtend ? options == null ? void 0 : options.fullAttrName : this.attrName;
|
|
31
|
+
this._visibleSubject = new rxjs.BehaviorSubject(this._visible);
|
|
32
|
+
}
|
|
33
|
+
get visible() {
|
|
34
|
+
return this._visible;
|
|
35
|
+
}
|
|
36
|
+
set visible(visible) {
|
|
37
|
+
if (visible) {
|
|
38
|
+
this.show();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.hide();
|
|
42
|
+
}
|
|
43
|
+
getVisibleSubject() {
|
|
44
|
+
return this._visibleSubject;
|
|
45
|
+
}
|
|
46
|
+
show() {
|
|
47
|
+
if (this._visible) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this._visible = true;
|
|
51
|
+
this._visibleSubject.next(this._visible);
|
|
52
|
+
}
|
|
53
|
+
hide() {
|
|
54
|
+
if (!this._visible) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this._visible = false;
|
|
58
|
+
this._visibleSubject.next(this._visible);
|
|
59
|
+
}
|
|
60
|
+
toggleVisible() {
|
|
61
|
+
if (this._visible) {
|
|
62
|
+
this.hide();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.show();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports["default"] = DataColumn;
|
|
@@ -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;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
|
+
var get = require('lodash/get');
|
|
7
|
+
var DataModelAdapter = require('./DataModelAdapter.js');
|
|
8
|
+
require('./DataColumn.js');
|
|
9
|
+
var iocAnnotations = require('@ctzy-web-client/ioc-annotations');
|
|
10
|
+
var support = require('@ctzy-web-client/support');
|
|
11
|
+
var ioc = require('@ctzy-web-client/ioc');
|
|
12
|
+
var lodash = require('lodash');
|
|
13
|
+
var rxjs = require('rxjs');
|
|
14
|
+
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
18
|
+
|
|
19
|
+
var _dec, _dec2, _class, _descriptor, _descriptor2;
|
|
20
|
+
let DataModel = (_dec = iocAnnotations.inject(DataModelAdapter["default"]), _dec2 = iocAnnotations.inject(ioc.InstantiationService), _class = class DataModel2 extends support.EventDispatcher {
|
|
21
|
+
constructor(options) {
|
|
22
|
+
super();
|
|
23
|
+
this.name = "";
|
|
24
|
+
this.title = "";
|
|
25
|
+
this.primaryKey = "id";
|
|
26
|
+
_rollupPluginBabelHelpers.initializerDefineProperty(this, "adapter", _descriptor, this);
|
|
27
|
+
_rollupPluginBabelHelpers.initializerDefineProperty(this, "instantiationService", _descriptor2, this);
|
|
28
|
+
this.defaultParams = {};
|
|
29
|
+
this.model = null;
|
|
30
|
+
this.ready = false;
|
|
31
|
+
this._options = null;
|
|
32
|
+
this.extendField = "";
|
|
33
|
+
this.extendFieldInfos = [];
|
|
34
|
+
this._columns = [];
|
|
35
|
+
this._displayColumns = [];
|
|
36
|
+
this._columnSubscriptionMap = /* @__PURE__ */ new Map();
|
|
37
|
+
this._displayColumnsSubject = new rxjs.BehaviorSubject([]);
|
|
38
|
+
this.setOptions(options);
|
|
39
|
+
}
|
|
40
|
+
setOptions(options) {
|
|
41
|
+
this._options = options;
|
|
42
|
+
this.name = options.name;
|
|
43
|
+
this.title = options.title;
|
|
44
|
+
this.primaryKey = options.primaryKey || this.primaryKey;
|
|
45
|
+
this.extendField = options.extendField;
|
|
46
|
+
this.model = options.model;
|
|
47
|
+
}
|
|
48
|
+
init() {
|
|
49
|
+
var _a;
|
|
50
|
+
if (typeof ((_a = this._options) == null ? void 0 : _a.adapter) === "function") {
|
|
51
|
+
this.adapter = this.instantiationService.createInstance(this._options.adapter);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
_format(data, propName = "name") {
|
|
55
|
+
const columns = this.getColumns();
|
|
56
|
+
const _data = {};
|
|
57
|
+
for (let column of columns.filter((column2) => !column2.isExtend)) {
|
|
58
|
+
const value = data == null ? void 0 : data[column[propName]];
|
|
59
|
+
_data[column.attrName] = value === "" || value == null ? column.default : value;
|
|
60
|
+
}
|
|
61
|
+
if (this.extendField) {
|
|
62
|
+
let extendObject = {};
|
|
63
|
+
for (let column of columns.filter((column2) => column2.isExtend)) {
|
|
64
|
+
const value = get__default["default"](data, column.fullAttrName);
|
|
65
|
+
extendObject[column.attrName] = value === "" || value == null ? column.default : value;
|
|
66
|
+
}
|
|
67
|
+
_data[this.extendField] = extendObject;
|
|
68
|
+
}
|
|
69
|
+
const extendProperties = (source, target, predicate) => {
|
|
70
|
+
let keys = Object.keys(source);
|
|
71
|
+
keys = keys.filter((key) => !columns.filter(predicate).find((column) => column.attrName === key));
|
|
72
|
+
for (const key of keys) {
|
|
73
|
+
target[key] = source[key];
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
extendProperties(data, _data, (column) => !column.isExtend);
|
|
77
|
+
if (this.extendField && data[this.extendField]) {
|
|
78
|
+
extendProperties(data[this.extendField], _data[this.extendField], (column) => column.isExtend);
|
|
79
|
+
}
|
|
80
|
+
return _data;
|
|
81
|
+
}
|
|
82
|
+
getDisplayColumnsSubject() {
|
|
83
|
+
return this._displayColumnsSubject;
|
|
84
|
+
}
|
|
85
|
+
setParam(key, value) {
|
|
86
|
+
this.defaultParams[key] = value;
|
|
87
|
+
}
|
|
88
|
+
getParam(key) {
|
|
89
|
+
return this.defaultParams[key];
|
|
90
|
+
}
|
|
91
|
+
hasParam(key) {
|
|
92
|
+
return Reflect.has(this.defaultParams, key);
|
|
93
|
+
}
|
|
94
|
+
removeParam(key) {
|
|
95
|
+
Reflect.deleteProperty(this.defaultParams, key);
|
|
96
|
+
}
|
|
97
|
+
addParams(params = {}) {
|
|
98
|
+
this.defaultParams = {
|
|
99
|
+
...this.defaultParams,
|
|
100
|
+
...params
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
setParams(params = {}) {
|
|
104
|
+
this.defaultParams = params;
|
|
105
|
+
}
|
|
106
|
+
clearParam() {
|
|
107
|
+
this.defaultParams = {};
|
|
108
|
+
}
|
|
109
|
+
formatData(data) {
|
|
110
|
+
return this._format(data);
|
|
111
|
+
}
|
|
112
|
+
formatExtendFieldInfo(extendFieldInfo) {
|
|
113
|
+
return {
|
|
114
|
+
title: extendFieldInfo.title,
|
|
115
|
+
name: extendFieldInfo.name,
|
|
116
|
+
default: extendFieldInfo.defaultValue,
|
|
117
|
+
attrName: extendFieldInfo.name,
|
|
118
|
+
isExtend: !extendFieldInfo.type,
|
|
119
|
+
required: !!extendFieldInfo.isRequired,
|
|
120
|
+
visible: !!extendFieldInfo.isVisible,
|
|
121
|
+
component: extendFieldInfo.component,
|
|
122
|
+
componentProps: {
|
|
123
|
+
...extendFieldInfo.extendInfo
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
mergeTableColumn(formatedExtendFieldInfo, modelFieldInfo) {
|
|
128
|
+
return {
|
|
129
|
+
...modelFieldInfo,
|
|
130
|
+
...formatedExtendFieldInfo,
|
|
131
|
+
fullAttrName: `${this.extendField}.${formatedExtendFieldInfo.name}`,
|
|
132
|
+
componentProps: {
|
|
133
|
+
...modelFieldInfo == null ? void 0 : modelFieldInfo.componentProps,
|
|
134
|
+
...formatedExtendFieldInfo.extendInfo
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
mergeTableColumns(extendFieldInfos, modelFieldInfos = []) {
|
|
139
|
+
return extendFieldInfos.map((extendFieldInfo) => {
|
|
140
|
+
const modelFieldInfo = modelFieldInfos.find((field) => field.name === extendFieldInfo.name);
|
|
141
|
+
const formatedExtendFieldInfo = this.formatExtendFieldInfo(extendFieldInfo);
|
|
142
|
+
return this.mergeTableColumn(formatedExtendFieldInfo, modelFieldInfo);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
getColumns() {
|
|
146
|
+
return this._columns.slice();
|
|
147
|
+
}
|
|
148
|
+
setColumns(columns) {
|
|
149
|
+
this._columnSubscriptionMap.clear();
|
|
150
|
+
this._columns = [];
|
|
151
|
+
for (let column of columns) {
|
|
152
|
+
this.addColumn(column);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
sortColumns(columns) {
|
|
156
|
+
throw new Error("\u6682\u672A\u5B9E\u73B0\u3002");
|
|
157
|
+
}
|
|
158
|
+
addColumn(column) {
|
|
159
|
+
if (!this.getColumn(column.attrName)) {
|
|
160
|
+
this._columns = this.sortColumns(this.getColumns().concat(column));
|
|
161
|
+
const subscription = column.getVisibleSubject().subscribe({
|
|
162
|
+
next: (visible) => {
|
|
163
|
+
if (visible) {
|
|
164
|
+
this.addDisplayColumn(column);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this.removeDisplayColumn(column);
|
|
168
|
+
},
|
|
169
|
+
error: () => {
|
|
170
|
+
this.removeDisplayColumn(column);
|
|
171
|
+
},
|
|
172
|
+
complete: () => {
|
|
173
|
+
this.removeDisplayColumn(column);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
this._columnSubscriptionMap.set(column.attrName, subscription);
|
|
177
|
+
} else {
|
|
178
|
+
throw new Error("\u65E0\u6CD5\u6DFB\u52A0\u4E24\u4E2A\u5B57\u6BB5\u540D\u79F0\u4E00\u6837\u7684\u5B57\u6BB5:" + column.attrName);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
getColumn(columnName) {
|
|
182
|
+
var _a;
|
|
183
|
+
return (_a = this._columns.find((column) => column.attrName === columnName)) != null ? _a : null;
|
|
184
|
+
}
|
|
185
|
+
getDisplayColumns() {
|
|
186
|
+
return this._displayColumns.slice();
|
|
187
|
+
}
|
|
188
|
+
setDisplayColumns(displayColumns) {
|
|
189
|
+
this._displayColumns = displayColumns;
|
|
190
|
+
this.getDisplayColumnsSubject().next(this.getDisplayColumns());
|
|
191
|
+
}
|
|
192
|
+
hasDisplayColumn(column) {
|
|
193
|
+
return !!this._displayColumns.find((item) => item.attrName === column.attrName);
|
|
194
|
+
}
|
|
195
|
+
addDisplayColumn(column) {
|
|
196
|
+
if (!this.getColumn(column.attrName) || this.hasDisplayColumn(column)) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.setDisplayColumns(this._displayColumns.concat(column));
|
|
200
|
+
}
|
|
201
|
+
removeDisplayColumn(column) {
|
|
202
|
+
if (!this.hasDisplayColumn(column)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
this.setDisplayColumns(this._displayColumns.filter((item) => item.attrName !== column.attrName));
|
|
206
|
+
}
|
|
207
|
+
clone() {
|
|
208
|
+
const cloned = lodash.clone(this);
|
|
209
|
+
cloned.adapter = this.adapter;
|
|
210
|
+
cloned.instantiationService = this.instantiationService;
|
|
211
|
+
cloned.defaultParams = lodash.cloneDeep(this.defaultParams);
|
|
212
|
+
cloned._columns = lodash.cloneDeep(this._columns);
|
|
213
|
+
return cloned;
|
|
214
|
+
}
|
|
215
|
+
}, _descriptor = _rollupPluginBabelHelpers.applyDecoratedDescriptor(_class.prototype, "adapter", [_dec], {
|
|
216
|
+
configurable: true,
|
|
217
|
+
enumerable: true,
|
|
218
|
+
writable: true,
|
|
219
|
+
initializer: function() {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
}), _descriptor2 = _rollupPluginBabelHelpers.applyDecoratedDescriptor(_class.prototype, "instantiationService", [_dec2], {
|
|
223
|
+
configurable: true,
|
|
224
|
+
enumerable: true,
|
|
225
|
+
writable: true,
|
|
226
|
+
initializer: function() {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}), _class);
|
|
230
|
+
|
|
231
|
+
exports["default"] = DataModel;
|
|
@@ -0,0 +1,90 @@
|
|
|
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 support = require('@ctzy-web-client/support');
|
|
8
|
+
|
|
9
|
+
var _dec, _dec2, _class, _descriptor, _descriptor2;
|
|
10
|
+
let DataModelAdapter = (_dec = iocAnnotations.inject(support.HttpRequest), _dec2 = iocAnnotations.value("AppName"), _class = class DataModelAdapter2 {
|
|
11
|
+
constructor() {
|
|
12
|
+
_rollupPluginBabelHelpers.initializerDefineProperty(this, "httpRequest", _descriptor, this);
|
|
13
|
+
_rollupPluginBabelHelpers.initializerDefineProperty(this, "appName", _descriptor2, this);
|
|
14
|
+
this.loadDataListItfMethod = "POST";
|
|
15
|
+
this.deleteItfMethod = "POST";
|
|
16
|
+
this.loadDataByRecIdMethod = "POST";
|
|
17
|
+
this.saveItfMethod = "POST";
|
|
18
|
+
this.updateItfMethod = "POST";
|
|
19
|
+
this.extendFieldItfMethod = "POST";
|
|
20
|
+
this.loadDataListItfUrl = "/${DataModelName}/page";
|
|
21
|
+
this.saveItfUrl = "${DataModelName}/save";
|
|
22
|
+
this.updateItfUrl = "${DataModelName}/update";
|
|
23
|
+
this.loadDataByRecIdItfUrl = "/${DataModelName}/find";
|
|
24
|
+
this.deleteItfUrl = "/${DataModelName}/delete";
|
|
25
|
+
this.extendFieldItfUrl = "/sceneField/default/page";
|
|
26
|
+
this.submitMethod = "POST";
|
|
27
|
+
this.pagerNumParamName = "pageNo";
|
|
28
|
+
this.recCountParamName = "pageSize";
|
|
29
|
+
this.dataNodeName = "data";
|
|
30
|
+
this.totalRecCountNodeName = "totalRecCount";
|
|
31
|
+
}
|
|
32
|
+
formatUrl(url, context) {
|
|
33
|
+
return url.replace(/(\$\{[\S]+?\})/g, (name) => {
|
|
34
|
+
if (name == "${AppName}") {
|
|
35
|
+
return context.appName;
|
|
36
|
+
} else if (name == "${DataModelName}") {
|
|
37
|
+
return context.dataModelName;
|
|
38
|
+
}
|
|
39
|
+
return name;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async sendRequest(url, method, params) {
|
|
43
|
+
return this.httpRequest[method.toLowerCase()](url, params);
|
|
44
|
+
}
|
|
45
|
+
async _sendRequest(context, url, method, params) {
|
|
46
|
+
const _context = {
|
|
47
|
+
appName: this.appName,
|
|
48
|
+
dataModelName: context.name
|
|
49
|
+
};
|
|
50
|
+
url = this.formatUrl(url, _context);
|
|
51
|
+
return this.sendRequest(url, method, params);
|
|
52
|
+
}
|
|
53
|
+
getExtendsFieldHandle(context, params) {
|
|
54
|
+
return this._sendRequest(context, this.extendFieldItfUrl, this.extendFieldItfMethod, params);
|
|
55
|
+
}
|
|
56
|
+
async loadDataListHandle(context, params) {
|
|
57
|
+
return this._sendRequest(context, this.loadDataListItfUrl, this.loadDataListItfMethod, params);
|
|
58
|
+
}
|
|
59
|
+
async deleteHandle(context, params) {
|
|
60
|
+
return this._sendRequest(context, this.deleteItfUrl, this.deleteItfMethod, params);
|
|
61
|
+
}
|
|
62
|
+
async loadDataByRecIdHandle(context, params) {
|
|
63
|
+
return this._sendRequest(context, this.loadDataByRecIdItfUrl, this.loadDataByRecIdMethod, params);
|
|
64
|
+
}
|
|
65
|
+
async saveHandle(context, params) {
|
|
66
|
+
return this._sendRequest(context, this.saveItfUrl, this.saveItfMethod, params);
|
|
67
|
+
}
|
|
68
|
+
async updateHandle(context, params) {
|
|
69
|
+
return this._sendRequest(context, this.updateItfUrl, this.updateItfMethod, params);
|
|
70
|
+
}
|
|
71
|
+
async submitHandle(context, params) {
|
|
72
|
+
return (params == null ? void 0 : params[context.primaryKey]) ? this.updateHandle(context, params) : this.saveHandle(context, params);
|
|
73
|
+
}
|
|
74
|
+
}, _descriptor = _rollupPluginBabelHelpers.applyDecoratedDescriptor(_class.prototype, "httpRequest", [_dec], {
|
|
75
|
+
configurable: true,
|
|
76
|
+
enumerable: true,
|
|
77
|
+
writable: true,
|
|
78
|
+
initializer: function() {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}), _descriptor2 = _rollupPluginBabelHelpers.applyDecoratedDescriptor(_class.prototype, "appName", [_dec2], {
|
|
82
|
+
configurable: true,
|
|
83
|
+
enumerable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
initializer: function() {
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
}), _class);
|
|
89
|
+
|
|
90
|
+
exports["default"] = DataModelAdapter;
|