@zhubangyun/lowcode-core 5.7.301 → 5.8.110
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/components/page-loading/index.less +12 -10
- package/es/index.js +6 -2
- package/es/utils/api/form-api.d.ts +1 -0
- package/es/utils/api/form-api.js +37 -108
- package/es/utils/api/form-api.utils.d.ts +7 -0
- package/es/utils/api/form-api.utils.js +128 -0
- package/es/utils/api/rest-api.d.ts +3 -0
- package/es/utils/api/rest-api.js +107 -43
- package/es/utils/data/index.d.ts +1 -0
- package/es/utils/data/index.js +20 -0
- package/es/utils/page/page-layout.js +1 -1
- package/lib/components/page-loading/index.less +12 -10
- package/lib/index.js +5 -2
- package/lib/utils/api/form-api.d.ts +1 -0
- package/lib/utils/api/form-api.js +42 -113
- package/lib/utils/api/form-api.utils.d.ts +7 -0
- package/lib/utils/api/form-api.utils.js +136 -0
- package/lib/utils/api/rest-api.d.ts +3 -0
- package/lib/utils/api/rest-api.js +107 -43
- package/lib/utils/data/index.d.ts +1 -0
- package/lib/utils/data/index.js +24 -0
- package/lib/utils/page/page-layout.js +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
height: 100vh;
|
|
5
|
-
top: 0;
|
|
6
|
-
left: 0;
|
|
1
|
+
.page-loading {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: 100%;
|
|
7
4
|
z-index: 10;
|
|
8
5
|
background: rgba(255, 255, 255, 0.5);
|
|
9
6
|
display: flex;
|
|
@@ -12,10 +9,14 @@
|
|
|
12
9
|
overflow: hidden;
|
|
13
10
|
}
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
|
|
13
|
+
#fullscreen-loading {
|
|
14
|
+
position: fixed;
|
|
15
|
+
width: 100vw;
|
|
16
|
+
height: 100vh;
|
|
17
|
+
top: 0;
|
|
18
|
+
left: 0;
|
|
19
|
+
z-index: 100000;
|
|
19
20
|
background: rgba(255, 255, 255, 0.5);
|
|
20
21
|
display: flex;
|
|
21
22
|
justify-content: center;
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
overflow: hidden;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
|
|
26
28
|
.atom-spinner, .atom-spinner * {
|
|
27
29
|
box-sizing: border-box;
|
|
28
30
|
}
|
package/lib/index.js
CHANGED
|
@@ -23,11 +23,14 @@ exports.Layout = _layout.Layout;
|
|
|
23
23
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
24
24
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
25
25
|
// @ts-ignore
|
|
26
|
-
window.utils = _utils["default"];
|
|
27
|
-
// @ts-ignore
|
|
28
26
|
window.__ReactRender = _reactRender.ReactRender;
|
|
29
27
|
// @ts-ignore
|
|
30
28
|
if (window._) {
|
|
31
29
|
// @ts-ignore
|
|
32
30
|
window.lodash = window._;
|
|
31
|
+
}
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
if (!window.utils) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
window.utils = _utils["default"];
|
|
33
36
|
}
|
|
@@ -14,4 +14,5 @@ export declare class RestFormApi<DataType> extends RestApi<DataType> {
|
|
|
14
14
|
save(data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
|
|
15
15
|
create(data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
|
|
16
16
|
update(id: string, data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
|
|
17
|
+
serviceUpdate(data: DataType, options?: BaseRequestOptions<DataType>): Promise<import("axios").AxiosResponse<any, any>>;
|
|
17
18
|
}
|
|
@@ -8,9 +8,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
8
8
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
9
9
|
var _restApi = require("./rest-api");
|
|
10
10
|
var _index = require("./index");
|
|
11
|
-
|
|
12
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
var _formApi = require("./form-api.utils");
|
|
14
12
|
var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
15
13
|
function RestFormApi(formId, fieldId, mock) {
|
|
16
14
|
var _this;
|
|
@@ -30,7 +28,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
30
28
|
_proto.initialize = /*#__PURE__*/function () {
|
|
31
29
|
var _initialize = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
32
30
|
var _this2 = this;
|
|
33
|
-
var res;
|
|
31
|
+
var _this$schema$props, res;
|
|
34
32
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
35
33
|
while (1) switch (_context.prev = _context.next) {
|
|
36
34
|
case 0:
|
|
@@ -47,7 +45,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
47
45
|
res = _context.sent;
|
|
48
46
|
this.schema = res.data;
|
|
49
47
|
this.initialized = !!this.schema;
|
|
50
|
-
this.title = this.schema.label;
|
|
48
|
+
this.title = (_this$schema$props = this.schema.props) === null || _this$schema$props === void 0 ? void 0 : _this$schema$props.label;
|
|
51
49
|
if (this.fieldId) {
|
|
52
50
|
JSON.stringify(this.schema, function (key, value) {
|
|
53
51
|
var _value$props;
|
|
@@ -116,26 +114,35 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
116
114
|
}();
|
|
117
115
|
_proto.search = /*#__PURE__*/function () {
|
|
118
116
|
var _search = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(params) {
|
|
119
|
-
var
|
|
117
|
+
var _params, _params2;
|
|
118
|
+
var config, res;
|
|
120
119
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
121
120
|
while (1) switch (_context3.prev = _context3.next) {
|
|
122
121
|
case 0:
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
case 2:
|
|
126
|
-
_context3.next = 4;
|
|
127
|
-
return this.request.post("search", params, {
|
|
122
|
+
params = params || {};
|
|
123
|
+
config = {
|
|
128
124
|
params: {
|
|
129
125
|
description: this.title + "\u67E5\u8BE2",
|
|
130
126
|
formId: this.formId,
|
|
131
127
|
fieldId: this.fieldId
|
|
132
128
|
}
|
|
133
|
-
}
|
|
129
|
+
};
|
|
130
|
+
_context3.next = 4;
|
|
131
|
+
return this.handleRequestConfig(config);
|
|
134
132
|
case 4:
|
|
133
|
+
params.filterRules = (0, _formApi.handleFilterRules)(((_params = params) === null || _params === void 0 ? void 0 : _params.filterRules) || [], {
|
|
134
|
+
filterNullValue: false
|
|
135
|
+
});
|
|
136
|
+
params.searchFields = (0, _formApi.handleFilterRules)(((_params2 = params) === null || _params2 === void 0 ? void 0 : _params2.searchFields) || [], {
|
|
137
|
+
filterNullValue: true
|
|
138
|
+
});
|
|
139
|
+
_context3.next = 8;
|
|
140
|
+
return this.request.post("search", params, config);
|
|
141
|
+
case 8:
|
|
135
142
|
res = _context3.sent;
|
|
136
|
-
assembleAssociationField(res.data, res.refs);
|
|
143
|
+
(0, _formApi.assembleAssociationField)(res.data, res.refs);
|
|
137
144
|
return _context3.abrupt("return", res);
|
|
138
|
-
case
|
|
145
|
+
case 11:
|
|
139
146
|
case "end":
|
|
140
147
|
return _context3.stop();
|
|
141
148
|
}
|
|
@@ -156,7 +163,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
156
163
|
return _RestApi.prototype.getById.call(this, id, options);
|
|
157
164
|
case 2:
|
|
158
165
|
res = _context4.sent;
|
|
159
|
-
assembleAssociationField(res.data, res.refs);
|
|
166
|
+
(0, _formApi.assembleAssociationField)(res.data, res.refs);
|
|
160
167
|
console.debug("formApi.getById", res);
|
|
161
168
|
return _context4.abrupt("return", res);
|
|
162
169
|
case 6:
|
|
@@ -175,7 +182,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
175
182
|
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
176
183
|
while (1) switch (_context5.prev = _context5.next) {
|
|
177
184
|
case 0:
|
|
178
|
-
return _context5.abrupt("return", _RestApi.prototype.save.call(this, convertSaveData(data), options));
|
|
185
|
+
return _context5.abrupt("return", _RestApi.prototype.save.call(this, (0, _formApi.convertSaveData)(data), options));
|
|
179
186
|
case 1:
|
|
180
187
|
case "end":
|
|
181
188
|
return _context5.stop();
|
|
@@ -192,7 +199,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
192
199
|
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
193
200
|
while (1) switch (_context6.prev = _context6.next) {
|
|
194
201
|
case 0:
|
|
195
|
-
return _context6.abrupt("return", _RestApi.prototype.create.call(this, convertSaveData(data), options));
|
|
202
|
+
return _context6.abrupt("return", _RestApi.prototype.create.call(this, (0, _formApi.convertSaveData)(data), options));
|
|
196
203
|
case 1:
|
|
197
204
|
case "end":
|
|
198
205
|
return _context6.stop();
|
|
@@ -209,7 +216,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
209
216
|
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
210
217
|
while (1) switch (_context7.prev = _context7.next) {
|
|
211
218
|
case 0:
|
|
212
|
-
return _context7.abrupt("return", _RestApi.prototype.update.call(this, id, convertSaveData(data), options));
|
|
219
|
+
return _context7.abrupt("return", _RestApi.prototype.update.call(this, id, (0, _formApi.convertSaveData)(data), options));
|
|
213
220
|
case 1:
|
|
214
221
|
case "end":
|
|
215
222
|
return _context7.stop();
|
|
@@ -221,100 +228,22 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
221
228
|
}
|
|
222
229
|
return update;
|
|
223
230
|
}();
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
function
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}));
|
|
234
|
-
}
|
|
235
|
-
function assembleAssociationField(data, refs) {
|
|
236
|
-
if (!data || !refs) return;
|
|
237
|
-
var fieldIdDataMap = new Map();
|
|
238
|
-
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
239
|
-
var ref = _step.value;
|
|
240
|
-
var dataMap = new Map();
|
|
241
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(ref.data), _step4; !(_step4 = _iterator4()).done;) {
|
|
242
|
-
var datum = _step4.value;
|
|
243
|
-
dataMap.set(datum.id, datum);
|
|
244
|
-
}
|
|
245
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(ref.fieldIds), _step5; !(_step5 = _iterator5()).done;) {
|
|
246
|
-
var fieldId = _step5.value;
|
|
247
|
-
fieldIdDataMap.set(fieldId + "Id", dataMap);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
//组装refs的关联属性
|
|
251
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(refs), _step2; !(_step2 = _iterator2()).done;) {
|
|
252
|
-
var _ref = _step2.value;
|
|
253
|
-
var key = _ref.form.id;
|
|
254
|
-
if (_ref.form.fieldId) {
|
|
255
|
-
key += "." + _ref.form.fieldId;
|
|
256
|
-
}
|
|
257
|
-
assembleAssociationFieldValue(_ref.data, fieldIdDataMap, key);
|
|
258
|
-
}
|
|
259
|
-
function loopAssembleAssociation(values) {
|
|
260
|
-
if (!Array.isArray(values)) {
|
|
261
|
-
if (values !== null && values !== void 0 && values.id) {
|
|
262
|
-
loopAssembleAssociation([values]);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (Array.isArray(values)) {
|
|
266
|
-
var _values$;
|
|
267
|
-
if ((_values$ = values[0]) !== null && _values$ !== void 0 && _values$.id) {
|
|
268
|
-
assembleAssociationFieldValue(values, fieldIdDataMap);
|
|
269
|
-
//处理子表
|
|
270
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(values), _step3; !(_step3 = _iterator3()).done;) {
|
|
271
|
-
var value = _step3.value;
|
|
272
|
-
for (var _i = 0, _Object$values = Object.values(value); _i < _Object$values.length; _i++) {
|
|
273
|
-
var subValues = _Object$values[_i];
|
|
274
|
-
if (Array.isArray(subValues)) {
|
|
275
|
-
loopAssembleAssociation(subValues);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
loopAssembleAssociation(data);
|
|
283
|
-
}
|
|
284
|
-
function assembleAssociationFieldValue(data, fieldIdDataMap, prefixKey) {
|
|
285
|
-
var arrayData = [];
|
|
286
|
-
if (Array.isArray(data)) {
|
|
287
|
-
arrayData = data;
|
|
288
|
-
} else if (typeof data == "object") {
|
|
289
|
-
arrayData = [data];
|
|
290
|
-
}
|
|
291
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(arrayData), _step6; !(_step6 = _iterator6()).done;) {
|
|
292
|
-
var item = _step6.value;
|
|
293
|
-
var _loop = function _loop() {
|
|
294
|
-
var fieldIdName = _Object$keys[_i2];
|
|
295
|
-
var fieldIdKey = fieldIdName;
|
|
296
|
-
if (prefixKey) {
|
|
297
|
-
fieldIdKey = prefixKey + "." + fieldIdName;
|
|
298
|
-
}
|
|
299
|
-
var dataMap = fieldIdDataMap.get(fieldIdKey);
|
|
300
|
-
if (dataMap) {
|
|
301
|
-
var fieldIdValue = item[fieldIdName];
|
|
302
|
-
var fieldValue = null;
|
|
303
|
-
if (Array.isArray(fieldIdValue)) {
|
|
304
|
-
// @ts-ignore
|
|
305
|
-
fieldValue = fieldIdValue.map(function (id) {
|
|
306
|
-
return dataMap.get(id);
|
|
307
|
-
}).filter(function (v) {
|
|
308
|
-
return !!v;
|
|
309
|
-
});
|
|
310
|
-
} else if (typeof fieldIdValue == "string") {
|
|
311
|
-
fieldValue = dataMap.get(fieldIdValue);
|
|
231
|
+
_proto.serviceUpdate = /*#__PURE__*/function () {
|
|
232
|
+
var _serviceUpdate = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(data, options) {
|
|
233
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
|
234
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
235
|
+
case 0:
|
|
236
|
+
return _context8.abrupt("return", this.request.post("serviceUpdate", data));
|
|
237
|
+
case 1:
|
|
238
|
+
case "end":
|
|
239
|
+
return _context8.stop();
|
|
312
240
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
_loop();
|
|
241
|
+
}, _callee8, this);
|
|
242
|
+
}));
|
|
243
|
+
function serviceUpdate(_x12, _x13) {
|
|
244
|
+
return _serviceUpdate.apply(this, arguments);
|
|
318
245
|
}
|
|
319
|
-
|
|
320
|
-
}
|
|
246
|
+
return serviceUpdate;
|
|
247
|
+
}();
|
|
248
|
+
return RestFormApi;
|
|
249
|
+
}(_restApi.RestApi);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseType, FilterRule, Refs } from "./rest-api";
|
|
2
|
+
export declare function convertSaveData(data: any): any;
|
|
3
|
+
export declare function assembleAssociationField(data: BaseType | BaseType[], refs?: Refs): void;
|
|
4
|
+
export declare function assembleAssociationFieldValue(data: BaseType | BaseType[], fieldIdDataMap: Map<string, Map<string, BaseType>>, prefixKey?: string): void;
|
|
5
|
+
export declare function handleFilterRules(filters: FilterRule[], options: {
|
|
6
|
+
filterNullValue: boolean;
|
|
7
|
+
}): any;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.assembleAssociationField = assembleAssociationField;
|
|
6
|
+
exports.assembleAssociationFieldValue = assembleAssociationFieldValue;
|
|
7
|
+
exports.convertSaveData = convertSaveData;
|
|
8
|
+
exports.handleFilterRules = handleFilterRules;
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _data = require("../data");
|
|
11
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
function convertSaveData(data) {
|
|
15
|
+
if (!data) return data;
|
|
16
|
+
return JSON.parse(JSON.stringify(data, function (key, value) {
|
|
17
|
+
if (key == "parent") {
|
|
18
|
+
return value === null || value === void 0 ? void 0 : value.id;
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
function assembleAssociationField(data, refs) {
|
|
24
|
+
if (!data || !refs) return;
|
|
25
|
+
var fieldIdDataMap = new Map();
|
|
26
|
+
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
27
|
+
var ref = _step.value;
|
|
28
|
+
var dataMap = new Map();
|
|
29
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(ref.data), _step4; !(_step4 = _iterator4()).done;) {
|
|
30
|
+
var datum = _step4.value;
|
|
31
|
+
dataMap.set(datum.id, datum);
|
|
32
|
+
}
|
|
33
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(ref.fieldIds), _step5; !(_step5 = _iterator5()).done;) {
|
|
34
|
+
var fieldId = _step5.value;
|
|
35
|
+
fieldIdDataMap.set(fieldId + "Id", dataMap);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//组装refs的关联属性
|
|
39
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(refs), _step2; !(_step2 = _iterator2()).done;) {
|
|
40
|
+
var _ref = _step2.value;
|
|
41
|
+
var key = _ref.form.id;
|
|
42
|
+
if (_ref.form.fieldId) {
|
|
43
|
+
key += "." + _ref.form.fieldId;
|
|
44
|
+
}
|
|
45
|
+
assembleAssociationFieldValue(_ref.data, fieldIdDataMap, key);
|
|
46
|
+
}
|
|
47
|
+
function loopAssembleAssociation(values) {
|
|
48
|
+
if (!Array.isArray(values)) {
|
|
49
|
+
if (values !== null && values !== void 0 && values.id) {
|
|
50
|
+
loopAssembleAssociation([values]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(values)) {
|
|
54
|
+
var _values$;
|
|
55
|
+
if ((_values$ = values[0]) !== null && _values$ !== void 0 && _values$.id) {
|
|
56
|
+
assembleAssociationFieldValue(values, fieldIdDataMap);
|
|
57
|
+
//处理子表
|
|
58
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(values), _step3; !(_step3 = _iterator3()).done;) {
|
|
59
|
+
var value = _step3.value;
|
|
60
|
+
for (var _i = 0, _Object$values = Object.values(value); _i < _Object$values.length; _i++) {
|
|
61
|
+
var subValues = _Object$values[_i];
|
|
62
|
+
if (Array.isArray(subValues)) {
|
|
63
|
+
loopAssembleAssociation(subValues);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
loopAssembleAssociation(data);
|
|
71
|
+
}
|
|
72
|
+
function assembleAssociationFieldValue(data, fieldIdDataMap, prefixKey) {
|
|
73
|
+
var arrayData = [];
|
|
74
|
+
if (Array.isArray(data)) {
|
|
75
|
+
arrayData = data;
|
|
76
|
+
} else if (typeof data == "object") {
|
|
77
|
+
arrayData = [data];
|
|
78
|
+
}
|
|
79
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(arrayData), _step6; !(_step6 = _iterator6()).done;) {
|
|
80
|
+
var item = _step6.value;
|
|
81
|
+
var _loop = function _loop() {
|
|
82
|
+
var fieldIdName = _Object$keys[_i2];
|
|
83
|
+
var fieldIdKey = fieldIdName;
|
|
84
|
+
if (prefixKey) {
|
|
85
|
+
fieldIdKey = prefixKey + "." + fieldIdName;
|
|
86
|
+
}
|
|
87
|
+
var dataMap = fieldIdDataMap.get(fieldIdKey);
|
|
88
|
+
if (dataMap) {
|
|
89
|
+
var fieldIdValue = item[fieldIdName];
|
|
90
|
+
var fieldValue = null;
|
|
91
|
+
if (Array.isArray(fieldIdValue)) {
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
fieldValue = fieldIdValue.map(function (id) {
|
|
94
|
+
return dataMap.get(id);
|
|
95
|
+
}).filter(function (v) {
|
|
96
|
+
return !!v;
|
|
97
|
+
});
|
|
98
|
+
} else if (typeof fieldIdValue == "string") {
|
|
99
|
+
fieldValue = dataMap.get(fieldIdValue);
|
|
100
|
+
}
|
|
101
|
+
item[fieldIdName.slice(0, -2)] = fieldValue;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
for (var _i2 = 0, _Object$keys = Object.keys(item); _i2 < _Object$keys.length; _i2++) {
|
|
105
|
+
_loop();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function handleFilterRules(filters, options) {
|
|
110
|
+
var filterNullValue = options.filterNullValue;
|
|
111
|
+
if (Array.isArray(filters)) {
|
|
112
|
+
var cloneRules = filters.filter(function (rule) {
|
|
113
|
+
return !!rule;
|
|
114
|
+
}).map(function (rule) {
|
|
115
|
+
return (0, _extends2["default"])({}, rule, {
|
|
116
|
+
value: (0, _data.transformerId)(rule.value),
|
|
117
|
+
rules: handleFilterRules(rule.rules || [], options)
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
if (filterNullValue) {
|
|
121
|
+
cloneRules = cloneRules.filter(function (rule) {
|
|
122
|
+
if (rule.value == null) {
|
|
123
|
+
if (rule.operator != "isNull" && rule.operator != "isNotNull") {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (cloneRules.length == 0) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -22,6 +22,8 @@ export interface RestSearchParams {
|
|
|
22
22
|
page?: number;
|
|
23
23
|
pageSize?: number;
|
|
24
24
|
filterRules?: FilterRule[];
|
|
25
|
+
searchFields?: FilterRule[];
|
|
26
|
+
orderRules?: any[];
|
|
25
27
|
}
|
|
26
28
|
export declare abstract class BaseRestApi<DataType> {
|
|
27
29
|
uri: string;
|
|
@@ -49,6 +51,7 @@ export declare abstract class BaseRestApi<DataType> {
|
|
|
49
51
|
* 通过id删除
|
|
50
52
|
*/
|
|
51
53
|
deleteById(id: string, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
|
|
54
|
+
delete(data: any | any[], options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
|
|
52
55
|
private showError;
|
|
53
56
|
}
|
|
54
57
|
export declare class RestApi<DataType> extends BaseRestApi<DataType> {
|
|
@@ -11,6 +11,7 @@ var _message2 = _interopRequireDefault(require("antd/lib/message"));
|
|
|
11
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
12
|
var _axios = _interopRequireDefault(require("axios"));
|
|
13
13
|
var _index = require("./index");
|
|
14
|
+
var _data = require("../data");
|
|
14
15
|
var BaseRestApi = exports.BaseRestApi = /*#__PURE__*/function () {
|
|
15
16
|
function BaseRestApi(uri, options) {
|
|
16
17
|
this.uri = void 0;
|
|
@@ -121,7 +122,7 @@ var BaseRestApi = exports.BaseRestApi = /*#__PURE__*/function () {
|
|
|
121
122
|
return (_this$handleRequestCo3 = this.handleRequestConfig) === null || _this$handleRequestCo3 === void 0 ? void 0 : _this$handleRequestCo3.call(this, config);
|
|
122
123
|
case 3:
|
|
123
124
|
_context3.next = 5;
|
|
124
|
-
return this.request.post("", data, config);
|
|
125
|
+
return this.request.post("save", data, config);
|
|
125
126
|
case 5:
|
|
126
127
|
res = _context3.sent;
|
|
127
128
|
if (res.success) {
|
|
@@ -291,67 +292,130 @@ var BaseRestApi = exports.BaseRestApi = /*#__PURE__*/function () {
|
|
|
291
292
|
}
|
|
292
293
|
return deleteById;
|
|
293
294
|
}();
|
|
294
|
-
_proto
|
|
295
|
-
var
|
|
296
|
-
var
|
|
295
|
+
_proto["delete"] = /*#__PURE__*/function () {
|
|
296
|
+
var _delete2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(data, options) {
|
|
297
|
+
var _this$handleRequestCo7;
|
|
298
|
+
var config, arrayData, idValue, res, _options$onError6, _options$onSuccess6;
|
|
297
299
|
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
298
300
|
while (1) switch (_context7.prev = _context7.next) {
|
|
299
301
|
case 0:
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (!(
|
|
307
|
-
|
|
308
|
-
|
|
302
|
+
config = {};
|
|
303
|
+
_context7.next = 3;
|
|
304
|
+
return (_this$handleRequestCo7 = this.handleRequestConfig) === null || _this$handleRequestCo7 === void 0 ? void 0 : _this$handleRequestCo7.call(this, config);
|
|
305
|
+
case 3:
|
|
306
|
+
arrayData = [];
|
|
307
|
+
idValue = (0, _data.transformerId)(data);
|
|
308
|
+
if (!Array.isArray(idValue)) {
|
|
309
|
+
arrayData.push(idValue);
|
|
310
|
+
} else {
|
|
311
|
+
arrayData = idValue;
|
|
309
312
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
content: message
|
|
313
|
+
arrayData = arrayData.filter(function (item) {
|
|
314
|
+
return !!item;
|
|
313
315
|
});
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (!(_type == "modal")) {
|
|
317
|
-
_context7.next = 13;
|
|
316
|
+
if (!(arrayData.length == 0)) {
|
|
317
|
+
_context7.next = 9;
|
|
318
318
|
break;
|
|
319
319
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
return
|
|
324
|
-
case
|
|
325
|
-
|
|
326
|
-
|
|
320
|
+
throw new Error("删除对象不可为空!");
|
|
321
|
+
case 9:
|
|
322
|
+
_context7.next = 11;
|
|
323
|
+
return this.request.post("remove", arrayData, config);
|
|
324
|
+
case 11:
|
|
325
|
+
res = _context7.sent;
|
|
326
|
+
if (res.success) {
|
|
327
|
+
_context7.next = 18;
|
|
327
328
|
break;
|
|
328
329
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return _context7.abrupt("return");
|
|
330
|
+
this.showError("\u5220\u9664\u5931\u8D25!", res.message).then();
|
|
331
|
+
_context7.next = 16;
|
|
332
|
+
return options === null || options === void 0 ? void 0 : (_options$onError6 = options.onError) === null || _options$onError6 === void 0 ? void 0 : _options$onError6.call(options, res);
|
|
333
333
|
case 16:
|
|
334
334
|
_context7.next = 20;
|
|
335
335
|
break;
|
|
336
336
|
case 18:
|
|
337
|
-
_context7.
|
|
338
|
-
|
|
337
|
+
_context7.next = 20;
|
|
338
|
+
return options === null || options === void 0 ? void 0 : (_options$onSuccess6 = options.onSuccess) === null || _options$onSuccess6 === void 0 ? void 0 : _options$onSuccess6.call(options, res);
|
|
339
339
|
case 20:
|
|
340
|
+
return _context7.abrupt("return", res);
|
|
341
|
+
case 21:
|
|
342
|
+
case "end":
|
|
343
|
+
return _context7.stop();
|
|
344
|
+
}
|
|
345
|
+
}, _callee7, this);
|
|
346
|
+
}));
|
|
347
|
+
function _delete(_x13, _x14) {
|
|
348
|
+
return _delete2.apply(this, arguments);
|
|
349
|
+
}
|
|
350
|
+
return _delete;
|
|
351
|
+
}();
|
|
352
|
+
_proto.showError = /*#__PURE__*/function () {
|
|
353
|
+
var _showError = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(type, msg) {
|
|
354
|
+
var props;
|
|
355
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
|
356
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
357
|
+
case 0:
|
|
358
|
+
_context8.prev = 0;
|
|
359
|
+
if (!msg) {
|
|
360
|
+
_context8.next = 18;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
props = JSON.parse(msg);
|
|
364
|
+
props.content = props.message;
|
|
365
|
+
if (props.title) {
|
|
366
|
+
props.title = "" + this.title + type;
|
|
367
|
+
}
|
|
368
|
+
if (!(props.type == "message")) {
|
|
369
|
+
_context8.next = 10;
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
_message2["default"].error(props);
|
|
373
|
+
return _context8.abrupt("return");
|
|
374
|
+
case 10:
|
|
375
|
+
if (!(props.type == "modal")) {
|
|
376
|
+
_context8.next = 15;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
_modal["default"].error(props);
|
|
380
|
+
return _context8.abrupt("return");
|
|
381
|
+
case 15:
|
|
382
|
+
if (!(props.type == "notification")) {
|
|
383
|
+
_context8.next = 18;
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
_notification2["default"].error(props);
|
|
387
|
+
return _context8.abrupt("return");
|
|
388
|
+
case 18:
|
|
389
|
+
_context8.next = 23;
|
|
390
|
+
break;
|
|
391
|
+
case 20:
|
|
392
|
+
_context8.prev = 20;
|
|
393
|
+
_context8.t0 = _context8["catch"](0);
|
|
394
|
+
console.log("`showError`解析异常:", _context8.t0);
|
|
395
|
+
case 23:
|
|
340
396
|
console.error("{" + this.title + "}" + type + (msg || ""));
|
|
341
397
|
_message2["default"] === null || _message2["default"] === void 0 ? void 0 : _message2["default"].error("{" + this.title + "}" + type + (msg || "")).then();
|
|
342
|
-
case
|
|
398
|
+
case 25:
|
|
343
399
|
case "end":
|
|
344
|
-
return
|
|
400
|
+
return _context8.stop();
|
|
345
401
|
}
|
|
346
|
-
},
|
|
402
|
+
}, _callee8, this, [[0, 20]]);
|
|
347
403
|
}));
|
|
348
|
-
function showError(
|
|
404
|
+
function showError(_x15, _x16) {
|
|
349
405
|
return _showError.apply(this, arguments);
|
|
350
406
|
}
|
|
351
407
|
return showError;
|
|
352
408
|
}();
|
|
353
409
|
return BaseRestApi;
|
|
354
410
|
}();
|
|
411
|
+
function getStringId(item) {
|
|
412
|
+
if (typeof (item === null || item === void 0 ? void 0 : item.id) === "string") {
|
|
413
|
+
return item.id;
|
|
414
|
+
} else if (typeof item === "string") {
|
|
415
|
+
return item;
|
|
416
|
+
}
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
355
419
|
var RestApi = exports.RestApi = /*#__PURE__*/function (_BaseRestApi2) {
|
|
356
420
|
function RestApi(uri, options) {
|
|
357
421
|
return _BaseRestApi2.call(this, uri, options) || this;
|
|
@@ -359,16 +423,16 @@ var RestApi = exports.RestApi = /*#__PURE__*/function (_BaseRestApi2) {
|
|
|
359
423
|
(0, _inheritsLoose2["default"])(RestApi, _BaseRestApi2);
|
|
360
424
|
var _proto2 = RestApi.prototype;
|
|
361
425
|
_proto2.handleRequestConfig = /*#__PURE__*/function () {
|
|
362
|
-
var _handleRequestConfig = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
363
|
-
return _regenerator["default"].wrap(function
|
|
364
|
-
while (1) switch (
|
|
426
|
+
var _handleRequestConfig = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(config) {
|
|
427
|
+
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
428
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
365
429
|
case 0:
|
|
366
430
|
case "end":
|
|
367
|
-
return
|
|
431
|
+
return _context9.stop();
|
|
368
432
|
}
|
|
369
|
-
},
|
|
433
|
+
}, _callee9);
|
|
370
434
|
}));
|
|
371
|
-
function handleRequestConfig(
|
|
435
|
+
function handleRequestConfig(_x17) {
|
|
372
436
|
return _handleRequestConfig.apply(this, arguments);
|
|
373
437
|
}
|
|
374
438
|
return handleRequestConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function transformerId(value: any): any;
|