@zhubangyun/lowcode-core 5.10.91 → 5.10.220
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/log-error-content.js +2 -2
- package/es/components/react-render/index.js +1 -2
- package/es/utils/api/form-api.d.ts +1 -1
- package/es/utils/api/form-api.js +22 -40
- package/es/utils/api/form-api.utils.d.ts +5 -0
- package/es/utils/api/form-api.utils.js +39 -9
- package/es/utils/api/schema-api.js +12 -4
- package/es/utils/cache/index.d.ts +7 -6
- package/es/utils/cache/index.js +13 -29
- package/es/utils/page/page-load-schema.js +2 -2
- package/lib/components/log-error-content.js +2 -2
- package/lib/components/react-render/index.js +1 -2
- package/lib/utils/api/form-api.d.ts +1 -1
- package/lib/utils/api/form-api.js +22 -40
- package/lib/utils/api/form-api.utils.d.ts +5 -0
- package/lib/utils/api/form-api.utils.js +39 -9
- package/lib/utils/api/schema-api.js +12 -4
- package/lib/utils/cache/index.d.ts +7 -6
- package/lib/utils/cache/index.js +15 -31
- package/lib/utils/page/page-load-schema.js +2 -2
- package/package.json +1 -1
|
@@ -16,10 +16,10 @@ export function LogErrorContent(props) {
|
|
|
16
16
|
_Modal.destroyAll();
|
|
17
17
|
_message.destroy();
|
|
18
18
|
_notification.destroy();
|
|
19
|
-
(_window$utils = window.utils) === null || _window$utils === void 0 ? void 0 : _window$utils.showForm({
|
|
19
|
+
(_window$utils = window.utils) === null || _window$utils === void 0 ? void 0 : _window$utils.page.showForm({
|
|
20
20
|
layout: "modal",
|
|
21
21
|
form: {
|
|
22
|
-
id: "
|
|
22
|
+
id: "40120d0c-2b35-4ae7-8711-acae048f1a0"
|
|
23
23
|
},
|
|
24
24
|
mode: "detail",
|
|
25
25
|
dataId: props.requestId
|
|
@@ -3,7 +3,6 @@ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
|
3
3
|
import { PureComponent } from 'react';
|
|
4
4
|
import { createFetchHandler } from "@alilc/lowcode-datasource-fetch-handler";
|
|
5
5
|
import ReactRenderFactory from "./react-render-factory";
|
|
6
|
-
import utils from "../../utils";
|
|
7
6
|
export var ReactRender = /*#__PURE__*/function (_PureComponent) {
|
|
8
7
|
function ReactRender() {
|
|
9
8
|
var _this;
|
|
@@ -29,7 +28,7 @@ export var ReactRender = /*#__PURE__*/function (_PureComponent) {
|
|
|
29
28
|
thisRequiredInJSE: true,
|
|
30
29
|
components: components,
|
|
31
30
|
appHelper: {
|
|
32
|
-
utils: utils,
|
|
31
|
+
utils: window.utils,
|
|
33
32
|
requestHandlersMap: {
|
|
34
33
|
fetch: createFetchHandler()
|
|
35
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseRequestOptions, ManyResult, OneResult, RestApi, RestSearchParams } from "./rest-api";
|
|
2
2
|
import { AxiosRequestConfig } from "axios";
|
|
3
|
-
export declare function getFormApi(formId: string, fieldId?: string, mock?: boolean):
|
|
3
|
+
export declare function getFormApi(formId: string, fieldId?: string, mock?: boolean): RestFormApi<any>;
|
|
4
4
|
export declare class RestFormApi<DataType> extends RestApi<DataType> {
|
|
5
5
|
private readonly formId;
|
|
6
6
|
private readonly fieldId?;
|
package/es/utils/api/form-api.js
CHANGED
|
@@ -1,43 +1,25 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
3
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import { RestApi } from "./rest-api";
|
|
6
6
|
import { getSchema } from "./index";
|
|
7
7
|
import { assembleAssociationField, convertSaveData, handleFilterRules } from "./form-api.utils";
|
|
8
8
|
import { formApi } from "../cache";
|
|
9
|
-
export function getFormApi(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
key = [formId, fieldId, mock ? "mock" : ""].filter(function (key) {
|
|
24
|
-
return !!key;
|
|
25
|
-
}).join("_");
|
|
26
|
-
_context9.next = 4;
|
|
27
|
-
return formApi.getInstance(key, {
|
|
28
|
-
mock: mock,
|
|
29
|
-
fieldId: fieldId,
|
|
30
|
-
formId: formId
|
|
31
|
-
});
|
|
32
|
-
case 4:
|
|
33
|
-
return _context9.abrupt("return", _context9.sent);
|
|
34
|
-
case 5:
|
|
35
|
-
case "end":
|
|
36
|
-
return _context9.stop();
|
|
37
|
-
}
|
|
38
|
-
}, _callee9);
|
|
39
|
-
}));
|
|
40
|
-
return _getFormApi.apply(this, arguments);
|
|
9
|
+
export function getFormApi(formId, fieldId, mock) {
|
|
10
|
+
if (typeof mock != "boolean") {
|
|
11
|
+
if (typeof window.__mock == "boolean") {
|
|
12
|
+
mock = window.__mock;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
var key = [formId, fieldId, mock ? "mock" : ""].filter(function (key) {
|
|
16
|
+
return !!key;
|
|
17
|
+
}).join("_");
|
|
18
|
+
return formApi.getInstance(key, {
|
|
19
|
+
mock: mock,
|
|
20
|
+
fieldId: fieldId,
|
|
21
|
+
formId: formId
|
|
22
|
+
});
|
|
41
23
|
}
|
|
42
24
|
export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
43
25
|
function RestFormApi(formId, fieldId, mock) {
|
|
@@ -139,7 +121,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
139
121
|
}
|
|
140
122
|
}, _callee2, this);
|
|
141
123
|
}));
|
|
142
|
-
function handleRequestConfig(
|
|
124
|
+
function handleRequestConfig(_x) {
|
|
143
125
|
return _handleRequestConfig.apply(this, arguments);
|
|
144
126
|
}
|
|
145
127
|
return handleRequestConfig;
|
|
@@ -187,7 +169,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
187
169
|
}
|
|
188
170
|
}, _callee3, this);
|
|
189
171
|
}));
|
|
190
|
-
function search(
|
|
172
|
+
function search(_x2) {
|
|
191
173
|
return _search.apply(this, arguments);
|
|
192
174
|
}
|
|
193
175
|
return search;
|
|
@@ -212,7 +194,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
212
194
|
}
|
|
213
195
|
}, _callee4, this);
|
|
214
196
|
}));
|
|
215
|
-
function getById(
|
|
197
|
+
function getById(_x3, _x4) {
|
|
216
198
|
return _getById.apply(this, arguments);
|
|
217
199
|
}
|
|
218
200
|
return getById;
|
|
@@ -229,7 +211,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
229
211
|
}
|
|
230
212
|
}, _callee5, this);
|
|
231
213
|
}));
|
|
232
|
-
function save(
|
|
214
|
+
function save(_x5, _x6) {
|
|
233
215
|
return _save.apply(this, arguments);
|
|
234
216
|
}
|
|
235
217
|
return save;
|
|
@@ -246,7 +228,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
246
228
|
}
|
|
247
229
|
}, _callee6, this);
|
|
248
230
|
}));
|
|
249
|
-
function create(
|
|
231
|
+
function create(_x7, _x8) {
|
|
250
232
|
return _create.apply(this, arguments);
|
|
251
233
|
}
|
|
252
234
|
return create;
|
|
@@ -263,7 +245,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
263
245
|
}
|
|
264
246
|
}, _callee7, this);
|
|
265
247
|
}));
|
|
266
|
-
function update(
|
|
248
|
+
function update(_x9, _x10, _x11) {
|
|
267
249
|
return _update.apply(this, arguments);
|
|
268
250
|
}
|
|
269
251
|
return update;
|
|
@@ -280,7 +262,7 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
280
262
|
}
|
|
281
263
|
}, _callee8, this);
|
|
282
264
|
}));
|
|
283
|
-
function serviceUpdate(
|
|
265
|
+
function serviceUpdate(_x12, _x13) {
|
|
284
266
|
return _serviceUpdate.apply(this, arguments);
|
|
285
267
|
}
|
|
286
268
|
return serviceUpdate;
|
|
@@ -3,6 +3,11 @@ export declare function convertSaveData(data: any): any;
|
|
|
3
3
|
export declare function handleEntityLabel(data: BaseType | BaseType[]): void;
|
|
4
4
|
export declare function dataToLabel(value: any): any;
|
|
5
5
|
export declare function assembleAssociationFieldV2(data: BaseType | BaseType[], refs?: Refs): void;
|
|
6
|
+
/**
|
|
7
|
+
* 加载字段
|
|
8
|
+
* @param data
|
|
9
|
+
* @param dataMap
|
|
10
|
+
*/
|
|
6
11
|
export declare function assembleAssociationFieldDataV2(data: BaseType | BaseType[], dataMap: Map<string, BaseType>): void;
|
|
7
12
|
export declare function assembleAssociationField(data: BaseType | BaseType[], refs?: Refs): void;
|
|
8
13
|
export declare function handleFilterRules(filters: FilterRule[], options: {
|
|
@@ -33,7 +33,7 @@ export function handleEntityLabel(data) {
|
|
|
33
33
|
var labelField = (_item$form = item.form) === null || _item$form === void 0 ? void 0 : _item$form.labelField;
|
|
34
34
|
if (labelField) {
|
|
35
35
|
// @ts-ignore
|
|
36
|
-
var value = item
|
|
36
|
+
var value = safeGet(item, labelField);
|
|
37
37
|
item.label = dataToLabel(value);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -87,6 +87,7 @@ export function assembleAssociationFieldV2(data, refs) {
|
|
|
87
87
|
return loopAssembleAssociation(item);
|
|
88
88
|
});
|
|
89
89
|
} else if (value !== null && value !== void 0 && value.id) {
|
|
90
|
+
handleEntityLabel(value);
|
|
90
91
|
assembleAssociationFieldDataV2(value, dataMap);
|
|
91
92
|
//处理子表
|
|
92
93
|
for (var _i = 0, _Object$values = Object.values(value); _i < _Object$values.length; _i++) {
|
|
@@ -98,8 +99,13 @@ export function assembleAssociationFieldV2(data, refs) {
|
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
loopAssembleAssociation(data);
|
|
101
|
-
handleEntityLabel(data);
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 加载字段
|
|
106
|
+
* @param data
|
|
107
|
+
* @param dataMap
|
|
108
|
+
*/
|
|
103
109
|
export function assembleAssociationFieldDataV2(data, dataMap) {
|
|
104
110
|
if (data == null) {
|
|
105
111
|
return;
|
|
@@ -109,14 +115,16 @@ export function assembleAssociationFieldDataV2(data, dataMap) {
|
|
|
109
115
|
return assembleAssociationFieldDataV2(item, dataMap);
|
|
110
116
|
});
|
|
111
117
|
} else {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var key = getDataKey(data);
|
|
116
|
-
var value = dataMap.get(key);
|
|
117
|
-
if (value) {
|
|
118
|
-
Object.assign(data, value);
|
|
118
|
+
if (data._load == false) {
|
|
119
|
+
var _data$form3;
|
|
120
|
+
if (data !== null && data !== void 0 && (_data$form3 = data.form) !== null && _data$form3 !== void 0 && _data$form3.id && data !== null && data !== void 0 && data.id) {
|
|
119
121
|
delete data._load;
|
|
122
|
+
var key = getDataKey(data);
|
|
123
|
+
var value = dataMap.get(key);
|
|
124
|
+
if (value) {
|
|
125
|
+
Object.assign(data, value);
|
|
126
|
+
delete data._load;
|
|
127
|
+
}
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
130
|
}
|
|
@@ -152,4 +160,26 @@ export function handleFilterRules(filters, options) {
|
|
|
152
160
|
} else {
|
|
153
161
|
return undefined;
|
|
154
162
|
}
|
|
163
|
+
}
|
|
164
|
+
function safeGet(value, key) {
|
|
165
|
+
if (typeof value !== "object") {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
if (typeof key !== "string") {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
if (!value || !key) return undefined;
|
|
172
|
+
var paths = key.split(".");
|
|
173
|
+
function safeGetValue(v) {
|
|
174
|
+
if (typeof v !== "object") {
|
|
175
|
+
return v;
|
|
176
|
+
}
|
|
177
|
+
if (paths.length) {
|
|
178
|
+
var k = paths.shift();
|
|
179
|
+
return safeGetValue(v === null || v === void 0 ? void 0 : v[k]);
|
|
180
|
+
} else {
|
|
181
|
+
return v;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return safeGetValue(value);
|
|
155
185
|
}
|
|
@@ -10,15 +10,16 @@ function _getSchema() {
|
|
|
10
10
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
11
11
|
while (1) switch (_context.prev = _context.next) {
|
|
12
12
|
case 0:
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
mock = getMock(mock);
|
|
14
|
+
key = mock ? pageId + ":mock" : pageId;
|
|
15
|
+
_context.next = 4;
|
|
15
16
|
return schema.getInstance(key, {
|
|
16
17
|
mock: mock,
|
|
17
18
|
pageId: pageId
|
|
18
19
|
});
|
|
19
|
-
case 3:
|
|
20
|
-
return _context.abrupt("return", _context.sent);
|
|
21
20
|
case 4:
|
|
21
|
+
return _context.abrupt("return", _context.sent);
|
|
22
|
+
case 5:
|
|
22
23
|
case "end":
|
|
23
24
|
return _context.stop();
|
|
24
25
|
}
|
|
@@ -30,6 +31,13 @@ export function getSchemaFromCache(pageId, mock) {
|
|
|
30
31
|
if (!pageId) {
|
|
31
32
|
return null;
|
|
32
33
|
}
|
|
34
|
+
mock = getMock(mock);
|
|
33
35
|
var key = mock ? pageId + "_mock" : pageId;
|
|
34
36
|
return schema.get(key);
|
|
37
|
+
}
|
|
38
|
+
function getMock(mock) {
|
|
39
|
+
if (typeof mock !== "boolean") {
|
|
40
|
+
mock = !!window.__mock;
|
|
41
|
+
}
|
|
42
|
+
return mock;
|
|
35
43
|
}
|
|
@@ -7,11 +7,12 @@ export declare class SchemaCache extends SingletonInstanceMap<any, {
|
|
|
7
7
|
createInstance(key: string, options: any): Promise<any>;
|
|
8
8
|
}
|
|
9
9
|
export declare const schema: SchemaCache;
|
|
10
|
-
export declare class FormApiCache
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export declare class FormApiCache {
|
|
11
|
+
apiMap: Map<string, RestFormApi<any>>;
|
|
12
|
+
getInstance(key: string, options: {
|
|
13
|
+
formId: string;
|
|
14
|
+
fieldId?: string;
|
|
15
|
+
mock?: boolean;
|
|
16
|
+
}): RestFormApi<any>;
|
|
16
17
|
}
|
|
17
18
|
export declare const formApi: FormApiCache;
|
package/es/utils/cache/index.js
CHANGED
|
@@ -48,38 +48,22 @@ export var SchemaCache = /*#__PURE__*/function (_SingletonInstanceMap) {
|
|
|
48
48
|
return SchemaCache;
|
|
49
49
|
}(SingletonInstanceMap);
|
|
50
50
|
export var schema = new SchemaCache();
|
|
51
|
-
export var FormApiCache = /*#__PURE__*/function (
|
|
51
|
+
export var FormApiCache = /*#__PURE__*/function () {
|
|
52
52
|
function FormApiCache() {
|
|
53
|
-
|
|
53
|
+
this.apiMap = new Map();
|
|
54
54
|
}
|
|
55
|
-
_inheritsLoose(FormApiCache, _SingletonInstanceMap2);
|
|
56
55
|
var _proto2 = FormApiCache.prototype;
|
|
57
|
-
_proto2.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
61
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
62
|
-
case 0:
|
|
63
|
-
if (options === void 0) {
|
|
64
|
-
options = {};
|
|
65
|
-
}
|
|
66
|
-
_options = options, formId = _options.formId, fieldId = _options.fieldId, mock = _options.mock;
|
|
67
|
-
formApi = new RestFormApi(formId, fieldId, mock);
|
|
68
|
-
_context2.next = 5;
|
|
69
|
-
return formApi.initialize();
|
|
70
|
-
case 5:
|
|
71
|
-
return _context2.abrupt("return", formApi);
|
|
72
|
-
case 6:
|
|
73
|
-
case "end":
|
|
74
|
-
return _context2.stop();
|
|
75
|
-
}
|
|
76
|
-
}, _callee2);
|
|
77
|
-
}));
|
|
78
|
-
function createInstance(_x3, _x4) {
|
|
79
|
-
return _createInstance2.apply(this, arguments);
|
|
56
|
+
_proto2.getInstance = function getInstance(key, options) {
|
|
57
|
+
if (this.apiMap.has(key)) {
|
|
58
|
+
return this.apiMap.get(key);
|
|
80
59
|
}
|
|
81
|
-
|
|
82
|
-
|
|
60
|
+
var formId = options.formId,
|
|
61
|
+
fieldId = options.fieldId,
|
|
62
|
+
mock = options.mock;
|
|
63
|
+
var formApi = new RestFormApi(formId, fieldId, mock);
|
|
64
|
+
this.apiMap.set(key, formApi);
|
|
65
|
+
return formApi;
|
|
66
|
+
};
|
|
83
67
|
return FormApiCache;
|
|
84
|
-
}(
|
|
68
|
+
}();
|
|
85
69
|
export var formApi = new FormApiCache();
|
|
@@ -8,10 +8,10 @@ export function PageLoadSchema(props) {
|
|
|
8
8
|
var pageId = props.pageId,
|
|
9
9
|
children = props.children;
|
|
10
10
|
var cache = getSchemaFromCache(pageId);
|
|
11
|
-
var _useState = useState(
|
|
11
|
+
var _useState = useState(!cache),
|
|
12
12
|
loading = _useState[0],
|
|
13
13
|
setLoading = _useState[1];
|
|
14
|
-
var _useState2 = useState(),
|
|
14
|
+
var _useState2 = useState(cache === null || cache === void 0 ? void 0 : cache.data),
|
|
15
15
|
schema = _useState2[0],
|
|
16
16
|
setSchema = _useState2[1];
|
|
17
17
|
var _useState3 = useState(),
|
|
@@ -21,10 +21,10 @@ function LogErrorContent(props) {
|
|
|
21
21
|
_modal["default"].destroyAll();
|
|
22
22
|
_message2["default"].destroy();
|
|
23
23
|
_notification2["default"].destroy();
|
|
24
|
-
(_window$utils = window.utils) === null || _window$utils === void 0 ? void 0 : _window$utils.showForm({
|
|
24
|
+
(_window$utils = window.utils) === null || _window$utils === void 0 ? void 0 : _window$utils.page.showForm({
|
|
25
25
|
layout: "modal",
|
|
26
26
|
form: {
|
|
27
|
-
id: "
|
|
27
|
+
id: "40120d0c-2b35-4ae7-8711-acae048f1a0"
|
|
28
28
|
},
|
|
29
29
|
mode: "detail",
|
|
30
30
|
dataId: props.requestId
|
|
@@ -8,7 +8,6 @@ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inh
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _lowcodeDatasourceFetchHandler = require("@alilc/lowcode-datasource-fetch-handler");
|
|
10
10
|
var _reactRenderFactory = _interopRequireDefault(require("./react-render-factory"));
|
|
11
|
-
var _utils = _interopRequireDefault(require("../../utils"));
|
|
12
11
|
var ReactRender = exports.ReactRender = /*#__PURE__*/function (_PureComponent) {
|
|
13
12
|
function ReactRender() {
|
|
14
13
|
var _this;
|
|
@@ -34,7 +33,7 @@ var ReactRender = exports.ReactRender = /*#__PURE__*/function (_PureComponent) {
|
|
|
34
33
|
thisRequiredInJSE: true,
|
|
35
34
|
components: components,
|
|
36
35
|
appHelper: {
|
|
37
|
-
utils:
|
|
36
|
+
utils: window.utils,
|
|
38
37
|
requestHandlersMap: {
|
|
39
38
|
fetch: (0, _lowcodeDatasourceFetchHandler.createFetchHandler)()
|
|
40
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseRequestOptions, ManyResult, OneResult, RestApi, RestSearchParams } from "./rest-api";
|
|
2
2
|
import { AxiosRequestConfig } from "axios";
|
|
3
|
-
export declare function getFormApi(formId: string, fieldId?: string, mock?: boolean):
|
|
3
|
+
export declare function getFormApi(formId: string, fieldId?: string, mock?: boolean): RestFormApi<any>;
|
|
4
4
|
export declare class RestFormApi<DataType> extends RestApi<DataType> {
|
|
5
5
|
private readonly formId;
|
|
6
6
|
private readonly fieldId?;
|
|
@@ -6,44 +6,26 @@ exports.RestFormApi = void 0;
|
|
|
6
6
|
exports.getFormApi = getFormApi;
|
|
7
7
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
-
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
10
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
11
11
|
var _restApi = require("./rest-api");
|
|
12
12
|
var _index = require("./index");
|
|
13
13
|
var _formApi = require("./form-api.utils");
|
|
14
14
|
var _cache = require("../cache");
|
|
15
|
-
function getFormApi(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
key = [formId, fieldId, mock ? "mock" : ""].filter(function (key) {
|
|
30
|
-
return !!key;
|
|
31
|
-
}).join("_");
|
|
32
|
-
_context9.next = 4;
|
|
33
|
-
return _cache.formApi.getInstance(key, {
|
|
34
|
-
mock: mock,
|
|
35
|
-
fieldId: fieldId,
|
|
36
|
-
formId: formId
|
|
37
|
-
});
|
|
38
|
-
case 4:
|
|
39
|
-
return _context9.abrupt("return", _context9.sent);
|
|
40
|
-
case 5:
|
|
41
|
-
case "end":
|
|
42
|
-
return _context9.stop();
|
|
43
|
-
}
|
|
44
|
-
}, _callee9);
|
|
45
|
-
}));
|
|
46
|
-
return _getFormApi.apply(this, arguments);
|
|
15
|
+
function getFormApi(formId, fieldId, mock) {
|
|
16
|
+
if (typeof mock != "boolean") {
|
|
17
|
+
if (typeof window.__mock == "boolean") {
|
|
18
|
+
mock = window.__mock;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
var key = [formId, fieldId, mock ? "mock" : ""].filter(function (key) {
|
|
22
|
+
return !!key;
|
|
23
|
+
}).join("_");
|
|
24
|
+
return _cache.formApi.getInstance(key, {
|
|
25
|
+
mock: mock,
|
|
26
|
+
fieldId: fieldId,
|
|
27
|
+
formId: formId
|
|
28
|
+
});
|
|
47
29
|
}
|
|
48
30
|
var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
49
31
|
function RestFormApi(formId, fieldId, mock) {
|
|
@@ -145,7 +127,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
145
127
|
}
|
|
146
128
|
}, _callee2, this);
|
|
147
129
|
}));
|
|
148
|
-
function handleRequestConfig(
|
|
130
|
+
function handleRequestConfig(_x) {
|
|
149
131
|
return _handleRequestConfig.apply(this, arguments);
|
|
150
132
|
}
|
|
151
133
|
return handleRequestConfig;
|
|
@@ -193,7 +175,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
193
175
|
}
|
|
194
176
|
}, _callee3, this);
|
|
195
177
|
}));
|
|
196
|
-
function search(
|
|
178
|
+
function search(_x2) {
|
|
197
179
|
return _search.apply(this, arguments);
|
|
198
180
|
}
|
|
199
181
|
return search;
|
|
@@ -218,7 +200,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
218
200
|
}
|
|
219
201
|
}, _callee4, this);
|
|
220
202
|
}));
|
|
221
|
-
function getById(
|
|
203
|
+
function getById(_x3, _x4) {
|
|
222
204
|
return _getById.apply(this, arguments);
|
|
223
205
|
}
|
|
224
206
|
return getById;
|
|
@@ -235,7 +217,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
235
217
|
}
|
|
236
218
|
}, _callee5, this);
|
|
237
219
|
}));
|
|
238
|
-
function save(
|
|
220
|
+
function save(_x5, _x6) {
|
|
239
221
|
return _save.apply(this, arguments);
|
|
240
222
|
}
|
|
241
223
|
return save;
|
|
@@ -252,7 +234,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
252
234
|
}
|
|
253
235
|
}, _callee6, this);
|
|
254
236
|
}));
|
|
255
|
-
function create(
|
|
237
|
+
function create(_x7, _x8) {
|
|
256
238
|
return _create.apply(this, arguments);
|
|
257
239
|
}
|
|
258
240
|
return create;
|
|
@@ -269,7 +251,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
269
251
|
}
|
|
270
252
|
}, _callee7, this);
|
|
271
253
|
}));
|
|
272
|
-
function update(
|
|
254
|
+
function update(_x9, _x10, _x11) {
|
|
273
255
|
return _update.apply(this, arguments);
|
|
274
256
|
}
|
|
275
257
|
return update;
|
|
@@ -286,7 +268,7 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
|
|
|
286
268
|
}
|
|
287
269
|
}, _callee8, this);
|
|
288
270
|
}));
|
|
289
|
-
function serviceUpdate(
|
|
271
|
+
function serviceUpdate(_x12, _x13) {
|
|
290
272
|
return _serviceUpdate.apply(this, arguments);
|
|
291
273
|
}
|
|
292
274
|
return serviceUpdate;
|
|
@@ -3,6 +3,11 @@ export declare function convertSaveData(data: any): any;
|
|
|
3
3
|
export declare function handleEntityLabel(data: BaseType | BaseType[]): void;
|
|
4
4
|
export declare function dataToLabel(value: any): any;
|
|
5
5
|
export declare function assembleAssociationFieldV2(data: BaseType | BaseType[], refs?: Refs): void;
|
|
6
|
+
/**
|
|
7
|
+
* 加载字段
|
|
8
|
+
* @param data
|
|
9
|
+
* @param dataMap
|
|
10
|
+
*/
|
|
6
11
|
export declare function assembleAssociationFieldDataV2(data: BaseType | BaseType[], dataMap: Map<string, BaseType>): void;
|
|
7
12
|
export declare function assembleAssociationField(data: BaseType | BaseType[], refs?: Refs): void;
|
|
8
13
|
export declare function handleFilterRules(filters: FilterRule[], options: {
|
|
@@ -44,7 +44,7 @@ function handleEntityLabel(data) {
|
|
|
44
44
|
var labelField = (_item$form = item.form) === null || _item$form === void 0 ? void 0 : _item$form.labelField;
|
|
45
45
|
if (labelField) {
|
|
46
46
|
// @ts-ignore
|
|
47
|
-
var value = item
|
|
47
|
+
var value = safeGet(item, labelField);
|
|
48
48
|
item.label = dataToLabel(value);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -98,6 +98,7 @@ function assembleAssociationFieldV2(data, refs) {
|
|
|
98
98
|
return loopAssembleAssociation(item);
|
|
99
99
|
});
|
|
100
100
|
} else if (value !== null && value !== void 0 && value.id) {
|
|
101
|
+
handleEntityLabel(value);
|
|
101
102
|
assembleAssociationFieldDataV2(value, dataMap);
|
|
102
103
|
//处理子表
|
|
103
104
|
for (var _i = 0, _Object$values = Object.values(value); _i < _Object$values.length; _i++) {
|
|
@@ -109,8 +110,13 @@ function assembleAssociationFieldV2(data, refs) {
|
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
loopAssembleAssociation(data);
|
|
112
|
-
handleEntityLabel(data);
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 加载字段
|
|
117
|
+
* @param data
|
|
118
|
+
* @param dataMap
|
|
119
|
+
*/
|
|
114
120
|
function assembleAssociationFieldDataV2(data, dataMap) {
|
|
115
121
|
if (data == null) {
|
|
116
122
|
return;
|
|
@@ -120,14 +126,16 @@ function assembleAssociationFieldDataV2(data, dataMap) {
|
|
|
120
126
|
return assembleAssociationFieldDataV2(item, dataMap);
|
|
121
127
|
});
|
|
122
128
|
} else {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var key = getDataKey(data);
|
|
127
|
-
var value = dataMap.get(key);
|
|
128
|
-
if (value) {
|
|
129
|
-
Object.assign(data, value);
|
|
129
|
+
if (data._load == false) {
|
|
130
|
+
var _data$form3;
|
|
131
|
+
if (data !== null && data !== void 0 && (_data$form3 = data.form) !== null && _data$form3 !== void 0 && _data$form3.id && data !== null && data !== void 0 && data.id) {
|
|
130
132
|
delete data._load;
|
|
133
|
+
var key = getDataKey(data);
|
|
134
|
+
var value = dataMap.get(key);
|
|
135
|
+
if (value) {
|
|
136
|
+
Object.assign(data, value);
|
|
137
|
+
delete data._load;
|
|
138
|
+
}
|
|
131
139
|
}
|
|
132
140
|
}
|
|
133
141
|
}
|
|
@@ -163,4 +171,26 @@ function handleFilterRules(filters, options) {
|
|
|
163
171
|
} else {
|
|
164
172
|
return undefined;
|
|
165
173
|
}
|
|
174
|
+
}
|
|
175
|
+
function safeGet(value, key) {
|
|
176
|
+
if (typeof value !== "object") {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
if (typeof key !== "string") {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
if (!value || !key) return undefined;
|
|
183
|
+
var paths = key.split(".");
|
|
184
|
+
function safeGetValue(v) {
|
|
185
|
+
if (typeof v !== "object") {
|
|
186
|
+
return v;
|
|
187
|
+
}
|
|
188
|
+
if (paths.length) {
|
|
189
|
+
var k = paths.shift();
|
|
190
|
+
return safeGetValue(v === null || v === void 0 ? void 0 : v[k]);
|
|
191
|
+
} else {
|
|
192
|
+
return v;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return safeGetValue(value);
|
|
166
196
|
}
|
|
@@ -16,15 +16,16 @@ function _getSchema() {
|
|
|
16
16
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
17
17
|
while (1) switch (_context.prev = _context.next) {
|
|
18
18
|
case 0:
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
mock = getMock(mock);
|
|
20
|
+
key = mock ? pageId + ":mock" : pageId;
|
|
21
|
+
_context.next = 4;
|
|
21
22
|
return _cache.schema.getInstance(key, {
|
|
22
23
|
mock: mock,
|
|
23
24
|
pageId: pageId
|
|
24
25
|
});
|
|
25
|
-
case 3:
|
|
26
|
-
return _context.abrupt("return", _context.sent);
|
|
27
26
|
case 4:
|
|
27
|
+
return _context.abrupt("return", _context.sent);
|
|
28
|
+
case 5:
|
|
28
29
|
case "end":
|
|
29
30
|
return _context.stop();
|
|
30
31
|
}
|
|
@@ -36,6 +37,13 @@ function getSchemaFromCache(pageId, mock) {
|
|
|
36
37
|
if (!pageId) {
|
|
37
38
|
return null;
|
|
38
39
|
}
|
|
40
|
+
mock = getMock(mock);
|
|
39
41
|
var key = mock ? pageId + "_mock" : pageId;
|
|
40
42
|
return _cache.schema.get(key);
|
|
43
|
+
}
|
|
44
|
+
function getMock(mock) {
|
|
45
|
+
if (typeof mock !== "boolean") {
|
|
46
|
+
mock = !!window.__mock;
|
|
47
|
+
}
|
|
48
|
+
return mock;
|
|
41
49
|
}
|
|
@@ -7,11 +7,12 @@ export declare class SchemaCache extends SingletonInstanceMap<any, {
|
|
|
7
7
|
createInstance(key: string, options: any): Promise<any>;
|
|
8
8
|
}
|
|
9
9
|
export declare const schema: SchemaCache;
|
|
10
|
-
export declare class FormApiCache
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export declare class FormApiCache {
|
|
11
|
+
apiMap: Map<string, RestFormApi<any>>;
|
|
12
|
+
getInstance(key: string, options: {
|
|
13
|
+
formId: string;
|
|
14
|
+
fieldId?: string;
|
|
15
|
+
mock?: boolean;
|
|
16
|
+
}): RestFormApi<any>;
|
|
16
17
|
}
|
|
17
18
|
export declare const formApi: FormApiCache;
|
package/lib/utils/cache/index.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.schema = exports.formApi = exports.SchemaCache = exports.FormApiCache =
|
|
|
6
6
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
7
7
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
8
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
9
|
-
var
|
|
9
|
+
var _SingletonInstanceMap2 = require("../common/SingletonInstanceMap");
|
|
10
10
|
var _api = require("../api");
|
|
11
11
|
var _schema = require("./schema");
|
|
12
12
|
var SchemaCache = exports.SchemaCache = /*#__PURE__*/function (_SingletonInstanceMap) {
|
|
@@ -50,40 +50,24 @@ var SchemaCache = exports.SchemaCache = /*#__PURE__*/function (_SingletonInstanc
|
|
|
50
50
|
return createInstance;
|
|
51
51
|
}();
|
|
52
52
|
return SchemaCache;
|
|
53
|
-
}(
|
|
53
|
+
}(_SingletonInstanceMap2.SingletonInstanceMap);
|
|
54
54
|
var schema = exports.schema = new SchemaCache();
|
|
55
|
-
var FormApiCache = exports.FormApiCache = /*#__PURE__*/function (
|
|
55
|
+
var FormApiCache = exports.FormApiCache = /*#__PURE__*/function () {
|
|
56
56
|
function FormApiCache() {
|
|
57
|
-
|
|
57
|
+
this.apiMap = new Map();
|
|
58
58
|
}
|
|
59
|
-
(0, _inheritsLoose2["default"])(FormApiCache, _SingletonInstanceMap2);
|
|
60
59
|
var _proto2 = FormApiCache.prototype;
|
|
61
|
-
_proto2.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
65
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
66
|
-
case 0:
|
|
67
|
-
if (options === void 0) {
|
|
68
|
-
options = {};
|
|
69
|
-
}
|
|
70
|
-
_options = options, formId = _options.formId, fieldId = _options.fieldId, mock = _options.mock;
|
|
71
|
-
formApi = new _api.RestFormApi(formId, fieldId, mock);
|
|
72
|
-
_context2.next = 5;
|
|
73
|
-
return formApi.initialize();
|
|
74
|
-
case 5:
|
|
75
|
-
return _context2.abrupt("return", formApi);
|
|
76
|
-
case 6:
|
|
77
|
-
case "end":
|
|
78
|
-
return _context2.stop();
|
|
79
|
-
}
|
|
80
|
-
}, _callee2);
|
|
81
|
-
}));
|
|
82
|
-
function createInstance(_x3, _x4) {
|
|
83
|
-
return _createInstance2.apply(this, arguments);
|
|
60
|
+
_proto2.getInstance = function getInstance(key, options) {
|
|
61
|
+
if (this.apiMap.has(key)) {
|
|
62
|
+
return this.apiMap.get(key);
|
|
84
63
|
}
|
|
85
|
-
|
|
86
|
-
|
|
64
|
+
var formId = options.formId,
|
|
65
|
+
fieldId = options.fieldId,
|
|
66
|
+
mock = options.mock;
|
|
67
|
+
var formApi = new _api.RestFormApi(formId, fieldId, mock);
|
|
68
|
+
this.apiMap.set(key, formApi);
|
|
69
|
+
return formApi;
|
|
70
|
+
};
|
|
87
71
|
return FormApiCache;
|
|
88
|
-
}(
|
|
72
|
+
}();
|
|
89
73
|
var formApi = exports.formApi = new FormApiCache();
|
|
@@ -13,10 +13,10 @@ function PageLoadSchema(props) {
|
|
|
13
13
|
var pageId = props.pageId,
|
|
14
14
|
children = props.children;
|
|
15
15
|
var cache = (0, _schemaApi.getSchemaFromCache)(pageId);
|
|
16
|
-
var _useState = (0, _react.useState)(
|
|
16
|
+
var _useState = (0, _react.useState)(!cache),
|
|
17
17
|
loading = _useState[0],
|
|
18
18
|
setLoading = _useState[1];
|
|
19
|
-
var _useState2 = (0, _react.useState)(),
|
|
19
|
+
var _useState2 = (0, _react.useState)(cache === null || cache === void 0 ? void 0 : cache.data),
|
|
20
20
|
schema = _useState2[0],
|
|
21
21
|
setSchema = _useState2[1];
|
|
22
22
|
var _useState3 = (0, _react.useState)(),
|