@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/es/index.js
CHANGED
|
@@ -7,8 +7,7 @@ export { PageLoading } from "./components/page-loading";
|
|
|
7
7
|
export { RestApi, RestFormApi, apiRequest } from "./utils/api";
|
|
8
8
|
export { Layout } from "./components/layout";
|
|
9
9
|
export { ReactRender } from "./components/react-render";
|
|
10
|
-
|
|
11
|
-
window.utils = utils;
|
|
10
|
+
|
|
12
11
|
// @ts-ignore
|
|
13
12
|
window.__ReactRender = ReactRender;
|
|
14
13
|
// @ts-ignore
|
|
@@ -16,4 +15,9 @@ if (window._) {
|
|
|
16
15
|
// @ts-ignore
|
|
17
16
|
window.lodash = window._;
|
|
18
17
|
}
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
if (!window.utils) {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
window.utils = utils;
|
|
22
|
+
}
|
|
19
23
|
export { utils, lodash };
|
|
@@ -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
|
}
|
package/es/utils/api/form-api.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
3
|
-
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."); }
|
|
4
|
-
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); }
|
|
5
|
-
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; }
|
|
6
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
4
|
import { RestApi } from "./rest-api";
|
|
8
5
|
import { getSchema } from "./index";
|
|
6
|
+
import { assembleAssociationField, convertSaveData, handleFilterRules } from "./form-api.utils";
|
|
9
7
|
export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
10
8
|
function RestFormApi(formId, fieldId, mock) {
|
|
11
9
|
var _this;
|
|
@@ -25,7 +23,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
25
23
|
_proto.initialize = /*#__PURE__*/function () {
|
|
26
24
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
27
25
|
var _this2 = this;
|
|
28
|
-
var res;
|
|
26
|
+
var _this$schema$props, res;
|
|
29
27
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
30
28
|
while (1) switch (_context.prev = _context.next) {
|
|
31
29
|
case 0:
|
|
@@ -42,7 +40,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
42
40
|
res = _context.sent;
|
|
43
41
|
this.schema = res.data;
|
|
44
42
|
this.initialized = !!this.schema;
|
|
45
|
-
this.title = this.schema.label;
|
|
43
|
+
this.title = (_this$schema$props = this.schema.props) === null || _this$schema$props === void 0 ? void 0 : _this$schema$props.label;
|
|
46
44
|
if (this.fieldId) {
|
|
47
45
|
JSON.stringify(this.schema, function (key, value) {
|
|
48
46
|
var _value$props;
|
|
@@ -111,26 +109,35 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
111
109
|
}();
|
|
112
110
|
_proto.search = /*#__PURE__*/function () {
|
|
113
111
|
var _search = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
|
|
114
|
-
var
|
|
112
|
+
var _params, _params2;
|
|
113
|
+
var config, res;
|
|
115
114
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
116
115
|
while (1) switch (_context3.prev = _context3.next) {
|
|
117
116
|
case 0:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
case 2:
|
|
121
|
-
_context3.next = 4;
|
|
122
|
-
return this.request.post("search", params, {
|
|
117
|
+
params = params || {};
|
|
118
|
+
config = {
|
|
123
119
|
params: {
|
|
124
120
|
description: this.title + "\u67E5\u8BE2",
|
|
125
121
|
formId: this.formId,
|
|
126
122
|
fieldId: this.fieldId
|
|
127
123
|
}
|
|
128
|
-
}
|
|
124
|
+
};
|
|
125
|
+
_context3.next = 4;
|
|
126
|
+
return this.handleRequestConfig(config);
|
|
129
127
|
case 4:
|
|
128
|
+
params.filterRules = handleFilterRules(((_params = params) === null || _params === void 0 ? void 0 : _params.filterRules) || [], {
|
|
129
|
+
filterNullValue: false
|
|
130
|
+
});
|
|
131
|
+
params.searchFields = handleFilterRules(((_params2 = params) === null || _params2 === void 0 ? void 0 : _params2.searchFields) || [], {
|
|
132
|
+
filterNullValue: true
|
|
133
|
+
});
|
|
134
|
+
_context3.next = 8;
|
|
135
|
+
return this.request.post("search", params, config);
|
|
136
|
+
case 8:
|
|
130
137
|
res = _context3.sent;
|
|
131
138
|
assembleAssociationField(res.data, res.refs);
|
|
132
139
|
return _context3.abrupt("return", res);
|
|
133
|
-
case
|
|
140
|
+
case 11:
|
|
134
141
|
case "end":
|
|
135
142
|
return _context3.stop();
|
|
136
143
|
}
|
|
@@ -216,100 +223,22 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
216
223
|
}
|
|
217
224
|
return update;
|
|
218
225
|
}();
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
function
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}));
|
|
229
|
-
}
|
|
230
|
-
function assembleAssociationField(data, refs) {
|
|
231
|
-
if (!data || !refs) return;
|
|
232
|
-
var fieldIdDataMap = new Map();
|
|
233
|
-
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
234
|
-
var ref = _step.value;
|
|
235
|
-
var dataMap = new Map();
|
|
236
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose(ref.data), _step4; !(_step4 = _iterator4()).done;) {
|
|
237
|
-
var datum = _step4.value;
|
|
238
|
-
dataMap.set(datum.id, datum);
|
|
239
|
-
}
|
|
240
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose(ref.fieldIds), _step5; !(_step5 = _iterator5()).done;) {
|
|
241
|
-
var fieldId = _step5.value;
|
|
242
|
-
fieldIdDataMap.set(fieldId + "Id", dataMap);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
//组装refs的关联属性
|
|
246
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(refs), _step2; !(_step2 = _iterator2()).done;) {
|
|
247
|
-
var _ref = _step2.value;
|
|
248
|
-
var key = _ref.form.id;
|
|
249
|
-
if (_ref.form.fieldId) {
|
|
250
|
-
key += "." + _ref.form.fieldId;
|
|
251
|
-
}
|
|
252
|
-
assembleAssociationFieldValue(_ref.data, fieldIdDataMap, key);
|
|
253
|
-
}
|
|
254
|
-
function loopAssembleAssociation(values) {
|
|
255
|
-
if (!Array.isArray(values)) {
|
|
256
|
-
if (values !== null && values !== void 0 && values.id) {
|
|
257
|
-
loopAssembleAssociation([values]);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
if (Array.isArray(values)) {
|
|
261
|
-
var _values$;
|
|
262
|
-
if ((_values$ = values[0]) !== null && _values$ !== void 0 && _values$.id) {
|
|
263
|
-
assembleAssociationFieldValue(values, fieldIdDataMap);
|
|
264
|
-
//处理子表
|
|
265
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(values), _step3; !(_step3 = _iterator3()).done;) {
|
|
266
|
-
var value = _step3.value;
|
|
267
|
-
for (var _i = 0, _Object$values = Object.values(value); _i < _Object$values.length; _i++) {
|
|
268
|
-
var subValues = _Object$values[_i];
|
|
269
|
-
if (Array.isArray(subValues)) {
|
|
270
|
-
loopAssembleAssociation(subValues);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
loopAssembleAssociation(data);
|
|
278
|
-
}
|
|
279
|
-
function assembleAssociationFieldValue(data, fieldIdDataMap, prefixKey) {
|
|
280
|
-
var arrayData = [];
|
|
281
|
-
if (Array.isArray(data)) {
|
|
282
|
-
arrayData = data;
|
|
283
|
-
} else if (typeof data == "object") {
|
|
284
|
-
arrayData = [data];
|
|
285
|
-
}
|
|
286
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose(arrayData), _step6; !(_step6 = _iterator6()).done;) {
|
|
287
|
-
var item = _step6.value;
|
|
288
|
-
var _loop = function _loop() {
|
|
289
|
-
var fieldIdName = _Object$keys[_i2];
|
|
290
|
-
var fieldIdKey = fieldIdName;
|
|
291
|
-
if (prefixKey) {
|
|
292
|
-
fieldIdKey = prefixKey + "." + fieldIdName;
|
|
293
|
-
}
|
|
294
|
-
var dataMap = fieldIdDataMap.get(fieldIdKey);
|
|
295
|
-
if (dataMap) {
|
|
296
|
-
var fieldIdValue = item[fieldIdName];
|
|
297
|
-
var fieldValue = null;
|
|
298
|
-
if (Array.isArray(fieldIdValue)) {
|
|
299
|
-
// @ts-ignore
|
|
300
|
-
fieldValue = fieldIdValue.map(function (id) {
|
|
301
|
-
return dataMap.get(id);
|
|
302
|
-
}).filter(function (v) {
|
|
303
|
-
return !!v;
|
|
304
|
-
});
|
|
305
|
-
} else if (typeof fieldIdValue == "string") {
|
|
306
|
-
fieldValue = dataMap.get(fieldIdValue);
|
|
226
|
+
_proto.serviceUpdate = /*#__PURE__*/function () {
|
|
227
|
+
var _serviceUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(data, options) {
|
|
228
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
229
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
230
|
+
case 0:
|
|
231
|
+
return _context8.abrupt("return", this.request.post("serviceUpdate", data));
|
|
232
|
+
case 1:
|
|
233
|
+
case "end":
|
|
234
|
+
return _context8.stop();
|
|
307
235
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
_loop();
|
|
236
|
+
}, _callee8, this);
|
|
237
|
+
}));
|
|
238
|
+
function serviceUpdate(_x12, _x13) {
|
|
239
|
+
return _serviceUpdate.apply(this, arguments);
|
|
313
240
|
}
|
|
314
|
-
|
|
315
|
-
}
|
|
241
|
+
return serviceUpdate;
|
|
242
|
+
}();
|
|
243
|
+
return RestFormApi;
|
|
244
|
+
}(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,128 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
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."); }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
import { transformerId } from "../data";
|
|
6
|
+
export function convertSaveData(data) {
|
|
7
|
+
if (!data) return data;
|
|
8
|
+
return JSON.parse(JSON.stringify(data, function (key, value) {
|
|
9
|
+
if (key == "parent") {
|
|
10
|
+
return value === null || value === void 0 ? void 0 : value.id;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
export function assembleAssociationField(data, refs) {
|
|
16
|
+
if (!data || !refs) return;
|
|
17
|
+
var fieldIdDataMap = new Map();
|
|
18
|
+
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
19
|
+
var ref = _step.value;
|
|
20
|
+
var dataMap = new Map();
|
|
21
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(ref.data), _step4; !(_step4 = _iterator4()).done;) {
|
|
22
|
+
var datum = _step4.value;
|
|
23
|
+
dataMap.set(datum.id, datum);
|
|
24
|
+
}
|
|
25
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(ref.fieldIds), _step5; !(_step5 = _iterator5()).done;) {
|
|
26
|
+
var fieldId = _step5.value;
|
|
27
|
+
fieldIdDataMap.set(fieldId + "Id", dataMap);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//组装refs的关联属性
|
|
31
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(refs), _step2; !(_step2 = _iterator2()).done;) {
|
|
32
|
+
var _ref = _step2.value;
|
|
33
|
+
var key = _ref.form.id;
|
|
34
|
+
if (_ref.form.fieldId) {
|
|
35
|
+
key += "." + _ref.form.fieldId;
|
|
36
|
+
}
|
|
37
|
+
assembleAssociationFieldValue(_ref.data, fieldIdDataMap, key);
|
|
38
|
+
}
|
|
39
|
+
function loopAssembleAssociation(values) {
|
|
40
|
+
if (!Array.isArray(values)) {
|
|
41
|
+
if (values !== null && values !== void 0 && values.id) {
|
|
42
|
+
loopAssembleAssociation([values]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(values)) {
|
|
46
|
+
var _values$;
|
|
47
|
+
if ((_values$ = values[0]) !== null && _values$ !== void 0 && _values$.id) {
|
|
48
|
+
assembleAssociationFieldValue(values, fieldIdDataMap);
|
|
49
|
+
//处理子表
|
|
50
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(values), _step3; !(_step3 = _iterator3()).done;) {
|
|
51
|
+
var value = _step3.value;
|
|
52
|
+
for (var _i = 0, _Object$values = Object.values(value); _i < _Object$values.length; _i++) {
|
|
53
|
+
var subValues = _Object$values[_i];
|
|
54
|
+
if (Array.isArray(subValues)) {
|
|
55
|
+
loopAssembleAssociation(subValues);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
loopAssembleAssociation(data);
|
|
63
|
+
}
|
|
64
|
+
export function assembleAssociationFieldValue(data, fieldIdDataMap, prefixKey) {
|
|
65
|
+
var arrayData = [];
|
|
66
|
+
if (Array.isArray(data)) {
|
|
67
|
+
arrayData = data;
|
|
68
|
+
} else if (typeof data == "object") {
|
|
69
|
+
arrayData = [data];
|
|
70
|
+
}
|
|
71
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose(arrayData), _step6; !(_step6 = _iterator6()).done;) {
|
|
72
|
+
var item = _step6.value;
|
|
73
|
+
var _loop = function _loop() {
|
|
74
|
+
var fieldIdName = _Object$keys[_i2];
|
|
75
|
+
var fieldIdKey = fieldIdName;
|
|
76
|
+
if (prefixKey) {
|
|
77
|
+
fieldIdKey = prefixKey + "." + fieldIdName;
|
|
78
|
+
}
|
|
79
|
+
var dataMap = fieldIdDataMap.get(fieldIdKey);
|
|
80
|
+
if (dataMap) {
|
|
81
|
+
var fieldIdValue = item[fieldIdName];
|
|
82
|
+
var fieldValue = null;
|
|
83
|
+
if (Array.isArray(fieldIdValue)) {
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
fieldValue = fieldIdValue.map(function (id) {
|
|
86
|
+
return dataMap.get(id);
|
|
87
|
+
}).filter(function (v) {
|
|
88
|
+
return !!v;
|
|
89
|
+
});
|
|
90
|
+
} else if (typeof fieldIdValue == "string") {
|
|
91
|
+
fieldValue = dataMap.get(fieldIdValue);
|
|
92
|
+
}
|
|
93
|
+
item[fieldIdName.slice(0, -2)] = fieldValue;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
for (var _i2 = 0, _Object$keys = Object.keys(item); _i2 < _Object$keys.length; _i2++) {
|
|
97
|
+
_loop();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function handleFilterRules(filters, options) {
|
|
102
|
+
var filterNullValue = options.filterNullValue;
|
|
103
|
+
if (Array.isArray(filters)) {
|
|
104
|
+
var cloneRules = filters.filter(function (rule) {
|
|
105
|
+
return !!rule;
|
|
106
|
+
}).map(function (rule) {
|
|
107
|
+
return _extends({}, rule, {
|
|
108
|
+
value: transformerId(rule.value),
|
|
109
|
+
rules: handleFilterRules(rule.rules || [], options)
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
if (filterNullValue) {
|
|
113
|
+
cloneRules = cloneRules.filter(function (rule) {
|
|
114
|
+
if (rule.value == null) {
|
|
115
|
+
if (rule.operator != "isNull" && rule.operator != "isNotNull") {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (cloneRules.length == 0) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -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> {
|
package/es/utils/api/rest-api.js
CHANGED
|
@@ -6,6 +6,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
6
6
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
7
|
import axios from "axios";
|
|
8
8
|
import { onFulfilled, onRejected } from "./index";
|
|
9
|
+
import { transformerId } from "../data";
|
|
9
10
|
export var BaseRestApi = /*#__PURE__*/function () {
|
|
10
11
|
function BaseRestApi(uri, options) {
|
|
11
12
|
this.uri = void 0;
|
|
@@ -116,7 +117,7 @@ export var BaseRestApi = /*#__PURE__*/function () {
|
|
|
116
117
|
return (_this$handleRequestCo3 = this.handleRequestConfig) === null || _this$handleRequestCo3 === void 0 ? void 0 : _this$handleRequestCo3.call(this, config);
|
|
117
118
|
case 3:
|
|
118
119
|
_context3.next = 5;
|
|
119
|
-
return this.request.post("", data, config);
|
|
120
|
+
return this.request.post("save", data, config);
|
|
120
121
|
case 5:
|
|
121
122
|
res = _context3.sent;
|
|
122
123
|
if (res.success) {
|
|
@@ -286,67 +287,130 @@ export var BaseRestApi = /*#__PURE__*/function () {
|
|
|
286
287
|
}
|
|
287
288
|
return deleteById;
|
|
288
289
|
}();
|
|
289
|
-
_proto
|
|
290
|
-
var
|
|
291
|
-
var
|
|
290
|
+
_proto["delete"] = /*#__PURE__*/function () {
|
|
291
|
+
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(data, options) {
|
|
292
|
+
var _this$handleRequestCo7;
|
|
293
|
+
var config, arrayData, idValue, res, _options$onError6, _options$onSuccess6;
|
|
292
294
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
293
295
|
while (1) switch (_context7.prev = _context7.next) {
|
|
294
296
|
case 0:
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
if (!(
|
|
302
|
-
|
|
303
|
-
|
|
297
|
+
config = {};
|
|
298
|
+
_context7.next = 3;
|
|
299
|
+
return (_this$handleRequestCo7 = this.handleRequestConfig) === null || _this$handleRequestCo7 === void 0 ? void 0 : _this$handleRequestCo7.call(this, config);
|
|
300
|
+
case 3:
|
|
301
|
+
arrayData = [];
|
|
302
|
+
idValue = transformerId(data);
|
|
303
|
+
if (!Array.isArray(idValue)) {
|
|
304
|
+
arrayData.push(idValue);
|
|
305
|
+
} else {
|
|
306
|
+
arrayData = idValue;
|
|
304
307
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
content: message
|
|
308
|
+
arrayData = arrayData.filter(function (item) {
|
|
309
|
+
return !!item;
|
|
308
310
|
});
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (!(_type == "modal")) {
|
|
312
|
-
_context7.next = 13;
|
|
311
|
+
if (!(arrayData.length == 0)) {
|
|
312
|
+
_context7.next = 9;
|
|
313
313
|
break;
|
|
314
314
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
return
|
|
319
|
-
case
|
|
320
|
-
|
|
321
|
-
|
|
315
|
+
throw new Error("删除对象不可为空!");
|
|
316
|
+
case 9:
|
|
317
|
+
_context7.next = 11;
|
|
318
|
+
return this.request.post("remove", arrayData, config);
|
|
319
|
+
case 11:
|
|
320
|
+
res = _context7.sent;
|
|
321
|
+
if (res.success) {
|
|
322
|
+
_context7.next = 18;
|
|
322
323
|
break;
|
|
323
324
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return _context7.abrupt("return");
|
|
325
|
+
this.showError("\u5220\u9664\u5931\u8D25!", res.message).then();
|
|
326
|
+
_context7.next = 16;
|
|
327
|
+
return options === null || options === void 0 ? void 0 : (_options$onError6 = options.onError) === null || _options$onError6 === void 0 ? void 0 : _options$onError6.call(options, res);
|
|
328
328
|
case 16:
|
|
329
329
|
_context7.next = 20;
|
|
330
330
|
break;
|
|
331
331
|
case 18:
|
|
332
|
-
_context7.
|
|
333
|
-
|
|
332
|
+
_context7.next = 20;
|
|
333
|
+
return options === null || options === void 0 ? void 0 : (_options$onSuccess6 = options.onSuccess) === null || _options$onSuccess6 === void 0 ? void 0 : _options$onSuccess6.call(options, res);
|
|
334
334
|
case 20:
|
|
335
|
+
return _context7.abrupt("return", res);
|
|
336
|
+
case 21:
|
|
337
|
+
case "end":
|
|
338
|
+
return _context7.stop();
|
|
339
|
+
}
|
|
340
|
+
}, _callee7, this);
|
|
341
|
+
}));
|
|
342
|
+
function _delete(_x13, _x14) {
|
|
343
|
+
return _delete2.apply(this, arguments);
|
|
344
|
+
}
|
|
345
|
+
return _delete;
|
|
346
|
+
}();
|
|
347
|
+
_proto.showError = /*#__PURE__*/function () {
|
|
348
|
+
var _showError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(type, msg) {
|
|
349
|
+
var props;
|
|
350
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
351
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
352
|
+
case 0:
|
|
353
|
+
_context8.prev = 0;
|
|
354
|
+
if (!msg) {
|
|
355
|
+
_context8.next = 18;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
props = JSON.parse(msg);
|
|
359
|
+
props.content = props.message;
|
|
360
|
+
if (props.title) {
|
|
361
|
+
props.title = "" + this.title + type;
|
|
362
|
+
}
|
|
363
|
+
if (!(props.type == "message")) {
|
|
364
|
+
_context8.next = 10;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
_message.error(props);
|
|
368
|
+
return _context8.abrupt("return");
|
|
369
|
+
case 10:
|
|
370
|
+
if (!(props.type == "modal")) {
|
|
371
|
+
_context8.next = 15;
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
_Modal.error(props);
|
|
375
|
+
return _context8.abrupt("return");
|
|
376
|
+
case 15:
|
|
377
|
+
if (!(props.type == "notification")) {
|
|
378
|
+
_context8.next = 18;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
_notification.error(props);
|
|
382
|
+
return _context8.abrupt("return");
|
|
383
|
+
case 18:
|
|
384
|
+
_context8.next = 23;
|
|
385
|
+
break;
|
|
386
|
+
case 20:
|
|
387
|
+
_context8.prev = 20;
|
|
388
|
+
_context8.t0 = _context8["catch"](0);
|
|
389
|
+
console.log("`showError`解析异常:", _context8.t0);
|
|
390
|
+
case 23:
|
|
335
391
|
console.error("{" + this.title + "}" + type + (msg || ""));
|
|
336
392
|
_message === null || _message === void 0 ? void 0 : _message.error("{" + this.title + "}" + type + (msg || "")).then();
|
|
337
|
-
case
|
|
393
|
+
case 25:
|
|
338
394
|
case "end":
|
|
339
|
-
return
|
|
395
|
+
return _context8.stop();
|
|
340
396
|
}
|
|
341
|
-
},
|
|
397
|
+
}, _callee8, this, [[0, 20]]);
|
|
342
398
|
}));
|
|
343
|
-
function showError(
|
|
399
|
+
function showError(_x15, _x16) {
|
|
344
400
|
return _showError.apply(this, arguments);
|
|
345
401
|
}
|
|
346
402
|
return showError;
|
|
347
403
|
}();
|
|
348
404
|
return BaseRestApi;
|
|
349
405
|
}();
|
|
406
|
+
function getStringId(item) {
|
|
407
|
+
if (typeof (item === null || item === void 0 ? void 0 : item.id) === "string") {
|
|
408
|
+
return item.id;
|
|
409
|
+
} else if (typeof item === "string") {
|
|
410
|
+
return item;
|
|
411
|
+
}
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
350
414
|
export var RestApi = /*#__PURE__*/function (_BaseRestApi2) {
|
|
351
415
|
function RestApi(uri, options) {
|
|
352
416
|
return _BaseRestApi2.call(this, uri, options) || this;
|
|
@@ -354,16 +418,16 @@ export var RestApi = /*#__PURE__*/function (_BaseRestApi2) {
|
|
|
354
418
|
_inheritsLoose(RestApi, _BaseRestApi2);
|
|
355
419
|
var _proto2 = RestApi.prototype;
|
|
356
420
|
_proto2.handleRequestConfig = /*#__PURE__*/function () {
|
|
357
|
-
var _handleRequestConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
358
|
-
return _regeneratorRuntime.wrap(function
|
|
359
|
-
while (1) switch (
|
|
421
|
+
var _handleRequestConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(config) {
|
|
422
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
423
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
360
424
|
case 0:
|
|
361
425
|
case "end":
|
|
362
|
-
return
|
|
426
|
+
return _context9.stop();
|
|
363
427
|
}
|
|
364
|
-
},
|
|
428
|
+
}, _callee9);
|
|
365
429
|
}));
|
|
366
|
-
function handleRequestConfig(
|
|
430
|
+
function handleRequestConfig(_x17) {
|
|
367
431
|
return _handleRequestConfig.apply(this, arguments);
|
|
368
432
|
}
|
|
369
433
|
return handleRequestConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function transformerId(value: any): any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function transformerId(value) {
|
|
2
|
+
if (value == null) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(value)) {
|
|
6
|
+
return value.map(transformerId).filter(function (value) {
|
|
7
|
+
return !!value;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
if (typeof value == "object") {
|
|
11
|
+
return (value === null || value === void 0 ? void 0 : value.id) || (value === null || value === void 0 ? void 0 : value.value) || value;
|
|
12
|
+
}
|
|
13
|
+
if (typeof value == "string") {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value == "number") {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
return (value === null || value === void 0 ? void 0 : value.id) || value.value || value;
|
|
20
|
+
}
|
|
@@ -15,7 +15,7 @@ export var PageLayout = /*#__PURE__*/function (_Component) {
|
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
_this.getWith = function () {
|
|
18
|
-
return Math.min(window.innerWidth,
|
|
18
|
+
return Math.min(window.innerWidth, 1600);
|
|
19
19
|
};
|
|
20
20
|
_this.handleResize = function () {
|
|
21
21
|
if (_this.props.layout == "drawer") {
|