@zhubangyun/lowcode-core 6.2.30 → 6.3.25
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/react-render/index.js +11 -1
- package/es/utils/api/form-api/form-api.assemble-entity.d.ts +2 -0
- package/es/utils/api/form-api/form-api.assemble-entity.js +101 -0
- package/es/utils/api/form-api/form-api.entity-map.d.ts +12 -0
- package/es/utils/api/form-api/form-api.entity-map.js +50 -0
- package/es/utils/api/{form-api.utils.d.ts → form-api/form-api.utils.d.ts} +3 -2
- package/es/utils/api/{form-api.utils.js → form-api/form-api.utils.js} +46 -23
- package/es/utils/api/form-api.js +10 -17
- package/es/utils/api/index.d.ts +6 -1
- package/es/utils/api/rest-api.d.ts +3 -1
- package/es/utils/api/schema-api.d.ts +2 -1
- package/es/utils/api/schema-api.js +1 -1
- package/es/utils/api/schema.util.d.ts +1 -0
- package/es/utils/api/schema.util.js +10 -0
- package/es/utils/cache/index.d.ts +0 -1
- package/es/utils/cache/index.js +58 -35
- package/es/utils/cache/index_db_cache.d.ts +9 -0
- package/es/utils/cache/index_db_cache.js +7 -0
- package/es/utils/common/SingletonInstanceMap.d.ts +2 -2
- package/es/utils/data/index.d.ts +3 -1
- package/es/utils/data/index.js +10 -3
- package/es/utils/page/index.d.ts +1 -0
- package/es/utils/page/index.js +1 -1
- package/es/utils/page/page-create-element.d.ts +6 -0
- package/es/utils/page/page-create-element.js +23 -0
- package/es/utils/page/page-form-group.js +10 -4
- package/es/utils/page/page-render.js +1 -1
- package/es/utils/page/page-schema-utils.js +19 -2
- package/es/utils/page/print-form.d.ts +1 -1
- package/es/utils/page/print-form.js +13 -7
- package/es/utils/uni-bridge.js +1 -3
- package/es/utils/util.common.d.ts +1 -1
- package/es/utils/util.common.js +1 -2
- package/lib/components/react-render/index.js +11 -1
- package/lib/utils/api/form-api/form-api.assemble-entity.d.ts +2 -0
- package/lib/utils/api/form-api/form-api.assemble-entity.js +105 -0
- package/lib/utils/api/form-api/form-api.entity-map.d.ts +12 -0
- package/lib/utils/api/form-api/form-api.entity-map.js +54 -0
- package/lib/utils/api/{form-api.utils.d.ts → form-api/form-api.utils.d.ts} +3 -2
- package/lib/utils/api/{form-api.utils.js → form-api/form-api.utils.js} +46 -22
- package/lib/utils/api/form-api.js +10 -17
- package/lib/utils/api/index.d.ts +6 -1
- package/lib/utils/api/rest-api.d.ts +3 -1
- package/lib/utils/api/schema-api.d.ts +2 -1
- package/lib/utils/api/schema-api.js +1 -1
- package/lib/utils/api/schema.util.d.ts +1 -0
- package/lib/utils/api/schema.util.js +11 -0
- package/lib/utils/cache/index.d.ts +0 -1
- package/lib/utils/cache/index.js +57 -34
- package/lib/utils/cache/index_db_cache.d.ts +9 -0
- package/lib/utils/cache/index_db_cache.js +11 -0
- package/lib/utils/common/SingletonInstanceMap.d.ts +2 -2
- package/lib/utils/data/index.d.ts +3 -1
- package/lib/utils/data/index.js +10 -3
- package/lib/utils/page/index.d.ts +1 -0
- package/lib/utils/page/index.js +4 -2
- package/lib/utils/page/page-create-element.d.ts +6 -0
- package/lib/utils/page/page-create-element.js +29 -0
- package/lib/utils/page/page-form-group.js +10 -4
- package/lib/utils/page/page-render.js +1 -1
- package/lib/utils/page/page-schema-utils.js +19 -2
- package/lib/utils/page/print-form.d.ts +1 -1
- package/lib/utils/page/print-form.js +13 -7
- package/lib/utils/uni-bridge.js +1 -3
- package/lib/utils/util.common.d.ts +1 -1
- package/lib/utils/util.common.js +2 -3
- package/package.json +5 -4
- package/es/utils/cache/schema.d.ts +0 -6
- package/es/utils/cache/schema.js +0 -14
- package/es/utils/utils.scrollbar-size.js +0 -0
- package/lib/utils/cache/schema.d.ts +0 -6
- package/lib/utils/cache/schema.js +0 -18
- package/lib/utils/utils.scrollbar-size.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare abstract class SingletonInstanceMap<Value, Options> {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
protected readonly valueMap: Map<string, Value>;
|
|
3
|
+
protected readonly lockMap: Map<string, boolean>;
|
|
4
4
|
getInstance(key: string, options: Options): Promise<Value>;
|
|
5
5
|
get(key: string): Value;
|
|
6
6
|
clear(): void;
|
package/es/utils/data/index.d.ts
CHANGED
package/es/utils/data/index.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
export function transformerId(value) {
|
|
1
|
+
export function transformerId(value, options) {
|
|
2
2
|
if (value == null) {
|
|
3
3
|
return null;
|
|
4
4
|
}
|
|
5
5
|
if (Array.isArray(value)) {
|
|
6
|
-
|
|
7
|
-
return
|
|
6
|
+
var values = value.map(function (item) {
|
|
7
|
+
return transformerId(item, options);
|
|
8
8
|
});
|
|
9
|
+
if (options !== null && options !== void 0 && options.includeNull) {
|
|
10
|
+
return values;
|
|
11
|
+
} else {
|
|
12
|
+
return values.filter(function (v) {
|
|
13
|
+
return !!v;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
9
16
|
}
|
|
10
17
|
if (typeof value == "object") {
|
|
11
18
|
return (value === null || value === void 0 ? void 0 : value.id) || (value === null || value === void 0 ? void 0 : value.value) || value;
|
package/es/utils/page/index.d.ts
CHANGED
package/es/utils/page/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { uniBridge } from "../uni-bridge";
|
|
4
|
+
export { createForm, getSchema } from "./page-create-element";
|
|
4
5
|
export { print, getFormPrintTemplates } from "./print-form";
|
|
5
6
|
export { showForm } from "./page-form";
|
|
6
7
|
export { showFormGroup } from "./page-form-group";
|
|
@@ -55,7 +56,6 @@ function _hideLoading() {
|
|
|
55
56
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
56
57
|
while (1) switch (_context2.prev = _context2.next) {
|
|
57
58
|
case 0:
|
|
58
|
-
console.log("page.hide.loading");
|
|
59
59
|
loading = document.getElementById("fullscreen-loading");
|
|
60
60
|
if (loading) {
|
|
61
61
|
loading.style.display = "none";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface PageCreateOptions {
|
|
3
|
+
formId: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function getSchema(pageId: string): import("../api/schema.util").Schema & import("../api/rest-api").IBaseEntity;
|
|
6
|
+
export declare function createForm(options: PageCreateOptions): JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["formId"];
|
|
4
|
+
import { getSchemaFromCache } from "../api/schema-api";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { ReactRender } from "../../components/react-render";
|
|
7
|
+
export function getSchema(pageId) {
|
|
8
|
+
var _getSchemaFromCache;
|
|
9
|
+
return (_getSchemaFromCache = getSchemaFromCache(pageId)) === null || _getSchemaFromCache === void 0 ? void 0 : _getSchemaFromCache.data;
|
|
10
|
+
}
|
|
11
|
+
export function createForm(options) {
|
|
12
|
+
var formId = options.formId,
|
|
13
|
+
restProps = _objectWithoutPropertiesLoose(options, _excluded);
|
|
14
|
+
var schemaRes = getSchemaFromCache(formId, window.__mock);
|
|
15
|
+
if (schemaRes !== null && schemaRes !== void 0 && schemaRes.success) {
|
|
16
|
+
var schema = schemaRes.data;
|
|
17
|
+
return /*#__PURE__*/React.createElement(ReactRender, _extends({
|
|
18
|
+
schema: schema,
|
|
19
|
+
components: window._components || window.components || window.__components
|
|
20
|
+
}, restProps));
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
3
|
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
5
|
-
var _excluded = ["layout", "form", "
|
|
5
|
+
var _excluded = ["layout", "form", "onClose", "onSubmitOk"],
|
|
6
6
|
_excluded2 = ["container", "onClose"];
|
|
7
7
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
8
|
import { PageLayout } from "./page-layout";
|
|
@@ -55,8 +55,8 @@ var FormGroupRender = /*#__PURE__*/function (_Component) {
|
|
|
55
55
|
var _this$props = this.props,
|
|
56
56
|
layout = _this$props.layout,
|
|
57
57
|
form = _this$props.form,
|
|
58
|
-
items = _this$props.items,
|
|
59
58
|
onClose = _this$props.onClose,
|
|
59
|
+
onSubmitOk = _this$props.onSubmitOk,
|
|
60
60
|
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
61
61
|
// @ts-ignore
|
|
62
62
|
restProps.layout = layout || "modal";
|
|
@@ -66,6 +66,12 @@ var FormGroupRender = /*#__PURE__*/function (_Component) {
|
|
|
66
66
|
(_self$layoutRef = self.layoutRef) === null || _self$layoutRef === void 0 ? void 0 : _self$layoutRef.close();
|
|
67
67
|
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
68
68
|
};
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
restProps.onSubmitOk = function (data) {
|
|
71
|
+
var _self$layoutRef2;
|
|
72
|
+
onSubmitOk === null || onSubmitOk === void 0 ? void 0 : onSubmitOk(data);
|
|
73
|
+
(_self$layoutRef2 = self.layoutRef) === null || _self$layoutRef2 === void 0 ? void 0 : _self$layoutRef2.close();
|
|
74
|
+
};
|
|
69
75
|
return /*#__PURE__*/React.createElement(PageLayout, {
|
|
70
76
|
ref: function ref(layout) {
|
|
71
77
|
return _this2.layoutRef = layout;
|
|
@@ -85,9 +91,9 @@ var FormGroupRender = /*#__PURE__*/function (_Component) {
|
|
|
85
91
|
children: [{
|
|
86
92
|
componentName: "PageFormGroup",
|
|
87
93
|
props: {
|
|
94
|
+
mode: "show",
|
|
88
95
|
title: schema.label,
|
|
89
|
-
form: form
|
|
90
|
-
items: items
|
|
96
|
+
form: form
|
|
91
97
|
}
|
|
92
98
|
}]
|
|
93
99
|
}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
function replacer(key, value) {
|
|
3
|
+
if (value == null) {
|
|
4
|
+
return null;
|
|
5
|
+
} else if (Array.isArray(value)) {
|
|
6
|
+
return value;
|
|
7
|
+
} else if (value !== null && value !== void 0 && value.id) {
|
|
8
|
+
return {
|
|
9
|
+
id: value.id,
|
|
10
|
+
label: value.label,
|
|
11
|
+
form: value.form
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
2
16
|
export function cloneDataView(dataView, extraProps) {
|
|
3
17
|
if (!dataView) {
|
|
4
18
|
return {};
|
|
@@ -60,10 +74,13 @@ function compileFilterRules(rules) {
|
|
|
60
74
|
if (value === "") {
|
|
61
75
|
value = "undefined";
|
|
62
76
|
}
|
|
63
|
-
} else if (rule.valueType == "value" || !rule.valueType || typeof value === "object") {
|
|
64
|
-
value = JSON.stringify(value);
|
|
77
|
+
} else if (rule.valueType == "value" || rule.valueType == "column" || !rule.valueType || typeof value === "object") {
|
|
78
|
+
value = JSON.stringify(value, replacer);
|
|
65
79
|
}
|
|
66
80
|
scripts.push("\"key\":\"" + rule.key + "\",");
|
|
81
|
+
if (rule.valueType) {
|
|
82
|
+
scripts.push("\"valueType\":\"" + rule.valueType + "\",");
|
|
83
|
+
}
|
|
67
84
|
scripts.push("\"operator\":\"" + rule.operator + "\",");
|
|
68
85
|
scripts.push("\"value\":" + value + ",");
|
|
69
86
|
}
|
|
@@ -4,6 +4,6 @@ interface PrintOptions {
|
|
|
4
4
|
mode?: "print" | "export" | "cloud_print";
|
|
5
5
|
data: any;
|
|
6
6
|
}
|
|
7
|
-
export declare function getFormPrintTemplates(formId: string): Promise<any>;
|
|
7
|
+
export declare function getFormPrintTemplates(formId: string, disableCache?: boolean): Promise<any>;
|
|
8
8
|
export declare function print(options: PrintOptions): Promise<void>;
|
|
9
9
|
export {};
|
|
@@ -5,15 +5,19 @@ import { apiRequest } from "../api";
|
|
|
5
5
|
import { FormIds } from "../formIds";
|
|
6
6
|
import { hideLoading, showLoading } from "./index";
|
|
7
7
|
var cache = new Map();
|
|
8
|
-
export function getFormPrintTemplates(_x) {
|
|
8
|
+
export function getFormPrintTemplates(_x, _x2) {
|
|
9
9
|
return _getFormPrintTemplates.apply(this, arguments);
|
|
10
10
|
}
|
|
11
11
|
function _getFormPrintTemplates() {
|
|
12
|
-
_getFormPrintTemplates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(formId) {
|
|
12
|
+
_getFormPrintTemplates = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(formId, disableCache) {
|
|
13
13
|
var res;
|
|
14
14
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
15
15
|
while (1) switch (_context2.prev = _context2.next) {
|
|
16
16
|
case 0:
|
|
17
|
+
if (disableCache) {
|
|
18
|
+
_context2.next = 1;
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
17
21
|
if (!cache.has(formId)) {
|
|
18
22
|
_context2.next = 1;
|
|
19
23
|
break;
|
|
@@ -50,7 +54,7 @@ function _getFormPrintTemplates() {
|
|
|
50
54
|
}));
|
|
51
55
|
return _getFormPrintTemplates.apply(this, arguments);
|
|
52
56
|
}
|
|
53
|
-
export function print(
|
|
57
|
+
export function print(_x3) {
|
|
54
58
|
return _print.apply(this, arguments);
|
|
55
59
|
}
|
|
56
60
|
function _print() {
|
|
@@ -103,7 +107,7 @@ function _print() {
|
|
|
103
107
|
}));
|
|
104
108
|
return _print.apply(this, arguments);
|
|
105
109
|
}
|
|
106
|
-
function openPrint(
|
|
110
|
+
function openPrint(_x4, _x5) {
|
|
107
111
|
return _openPrint.apply(this, arguments);
|
|
108
112
|
}
|
|
109
113
|
function _openPrint() {
|
|
@@ -198,7 +202,7 @@ function _openPrint() {
|
|
|
198
202
|
}
|
|
199
203
|
}, _callee5);
|
|
200
204
|
}));
|
|
201
|
-
return function (
|
|
205
|
+
return function (_x7, _x8) {
|
|
202
206
|
return _ref.apply(this, arguments);
|
|
203
207
|
};
|
|
204
208
|
}()));
|
|
@@ -268,7 +272,9 @@ var CloudPrinter = /*#__PURE__*/function () {
|
|
|
268
272
|
});
|
|
269
273
|
case 3:
|
|
270
274
|
res = _context.sent;
|
|
271
|
-
if (
|
|
275
|
+
if (res.success) {
|
|
276
|
+
_message.success(res.message);
|
|
277
|
+
} else {
|
|
272
278
|
_message.error(res.message);
|
|
273
279
|
}
|
|
274
280
|
case 4:
|
|
@@ -277,7 +283,7 @@ var CloudPrinter = /*#__PURE__*/function () {
|
|
|
277
283
|
}
|
|
278
284
|
}, _callee, this);
|
|
279
285
|
}));
|
|
280
|
-
function post(
|
|
286
|
+
function post(_x6) {
|
|
281
287
|
return _post.apply(this, arguments);
|
|
282
288
|
}
|
|
283
289
|
return post;
|
package/es/utils/uni-bridge.js
CHANGED
|
@@ -124,13 +124,11 @@ var UniBridge = /*#__PURE__*/function () {
|
|
|
124
124
|
case 1:
|
|
125
125
|
messageId = v7();
|
|
126
126
|
return _context5.abrupt("return", new Promise(function (resolve, reject) {
|
|
127
|
-
console.log("UniBridge.doAction", messageId, action, options);
|
|
128
127
|
_this.callbacks[messageId] = {
|
|
129
128
|
resolve: resolve,
|
|
130
129
|
reject: reject
|
|
131
130
|
};
|
|
132
131
|
try {
|
|
133
|
-
console.log("postMessage", messageId, action, options);
|
|
134
132
|
uni.postMessage({
|
|
135
133
|
data: {
|
|
136
134
|
action: action,
|
|
@@ -157,7 +155,7 @@ var UniBridge = /*#__PURE__*/function () {
|
|
|
157
155
|
_proto.receiveMessage = function receiveMessage(message) {
|
|
158
156
|
var callback = this.callbacks[message.messageId];
|
|
159
157
|
console.log('客户端收到 UniApp 消息:', JSON.stringify(message));
|
|
160
|
-
console.log('客户端收到 UniApp 消息:callbacks', this.callbacks);
|
|
158
|
+
console.log('客户端收到 UniApp 消息:callbacks', JSON.stringify(Object.keys(this.callbacks)), callback);
|
|
161
159
|
if (callback) {
|
|
162
160
|
if (message.success) {
|
|
163
161
|
callback.resolve(message.data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function isTemplateHost(): boolean;
|
package/es/utils/util.common.js
CHANGED
|
@@ -24,6 +24,10 @@ var ReactRender = exports.ReactRender = /*#__PURE__*/function (_PureComponent) {
|
|
|
24
24
|
_proto.render = function render() {
|
|
25
25
|
var _this2 = this;
|
|
26
26
|
var components = this.props.components || window._components;
|
|
27
|
+
if (!components.Page) {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
components["Page"] = Page;
|
|
30
|
+
}
|
|
27
31
|
return /*#__PURE__*/React.createElement(_reactRenderFactory["default"], (0, _extends2["default"])({
|
|
28
32
|
key: this.key
|
|
29
33
|
}, this.props, {
|
|
@@ -41,4 +45,10 @@ var ReactRender = exports.ReactRender = /*#__PURE__*/function (_PureComponent) {
|
|
|
41
45
|
}));
|
|
42
46
|
};
|
|
43
47
|
return ReactRender;
|
|
44
|
-
}(_react.PureComponent);
|
|
48
|
+
}(_react.PureComponent);
|
|
49
|
+
function Page(props) {
|
|
50
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
51
|
+
className: "lce-page",
|
|
52
|
+
style: props.style
|
|
53
|
+
}, props.children);
|
|
54
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.formApiAssembleEntity = formApiAssembleEntity;
|
|
5
|
+
var _formApi = require("./form-api.entity-map");
|
|
6
|
+
var _formApi2 = require("./form-api.utils");
|
|
7
|
+
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
8
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
9
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
10
|
+
function formApiAssembleEntity(data, refs) {
|
|
11
|
+
if (!data || !refs) return;
|
|
12
|
+
var dataMap = new _formApi.FormApiEntityMap();
|
|
13
|
+
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
14
|
+
var ref = _step.value;
|
|
15
|
+
ref.label = ref.form.label;
|
|
16
|
+
dataMap.addEntities(ref.data);
|
|
17
|
+
}
|
|
18
|
+
assembleRefs(refs, dataMap);
|
|
19
|
+
var dataArray = Array.isArray(data) ? data : [data];
|
|
20
|
+
assembleData(dataArray, dataMap);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 装配数据
|
|
25
|
+
*/
|
|
26
|
+
function assembleData(data, dataMap) {
|
|
27
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(data), _step2; !(_step2 = _iterator2()).done;) {
|
|
28
|
+
var item = _step2.value;
|
|
29
|
+
assembleObject(item, dataMap, {
|
|
30
|
+
maxDepth: 3,
|
|
31
|
+
depth: 1
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 装配相关数据
|
|
38
|
+
*/
|
|
39
|
+
function assembleRefs(refs, dataMap) {
|
|
40
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(refs), _step3; !(_step3 = _iterator3()).done;) {
|
|
41
|
+
var ref = _step3.value;
|
|
42
|
+
ref.label = ref.form.label;
|
|
43
|
+
var data = ref.data;
|
|
44
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose(data), _step4; !(_step4 = _iterator4()).done;) {
|
|
45
|
+
var item = _step4.value;
|
|
46
|
+
assembleObject(item, dataMap, {
|
|
47
|
+
maxDepth: 3,
|
|
48
|
+
depth: 1
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function assembleObject(values, dataMap, options) {
|
|
54
|
+
var depth = options.depth,
|
|
55
|
+
maxDepth = options.maxDepth;
|
|
56
|
+
if (options.depth >= options.maxDepth) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (dataMap.isEntity(values)) {
|
|
60
|
+
handleEntityLabel(values);
|
|
61
|
+
}
|
|
62
|
+
for (var _i = 0, _Object$keys = Object.keys(values); _i < _Object$keys.length; _i++) {
|
|
63
|
+
var key = _Object$keys[_i];
|
|
64
|
+
var value = values[key];
|
|
65
|
+
if (Array.isArray(value)) {
|
|
66
|
+
if (dataMap.needLoad(value[0])) {
|
|
67
|
+
//需要加载的属性
|
|
68
|
+
values[key] = value.map(function (item) {
|
|
69
|
+
if (dataMap.hasEntity(item)) {
|
|
70
|
+
return dataMap.getEntity(item);
|
|
71
|
+
}
|
|
72
|
+
return item;
|
|
73
|
+
});
|
|
74
|
+
} else if (dataMap.isEntity(value[0])) {
|
|
75
|
+
//子表属性
|
|
76
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose(value), _step5; !(_step5 = _iterator5()).done;) {
|
|
77
|
+
var valueElement = _step5.value;
|
|
78
|
+
assembleObject(valueElement, dataMap, {
|
|
79
|
+
maxDepth: maxDepth,
|
|
80
|
+
depth: depth
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else if (typeof value == "object") {
|
|
85
|
+
if (dataMap.needLoad(value)) {
|
|
86
|
+
if (dataMap.hasEntity(value)) {
|
|
87
|
+
values[key] = dataMap.getEntity(value);
|
|
88
|
+
}
|
|
89
|
+
} else if (key == "parent") {
|
|
90
|
+
//values.parent = dataMap.getEntity(value);
|
|
91
|
+
Object.defineProperty(values, "parent", {
|
|
92
|
+
value: dataMap.getEntity(value),
|
|
93
|
+
writable: true
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function handleEntityLabel(data) {
|
|
100
|
+
var _data$form;
|
|
101
|
+
var labelField = data === null || data === void 0 ? void 0 : (_data$form = data.form) === null || _data$form === void 0 ? void 0 : _data$form.labelField;
|
|
102
|
+
if (labelField) {
|
|
103
|
+
data.label = (0, _formApi2.dataToLabel)((0, _formApi2.safeGet)(data, labelField));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IBaseEntity } from "../rest-api";
|
|
2
|
+
export declare class FormApiEntityMap {
|
|
3
|
+
dataMap: Map<string, IBaseEntity>;
|
|
4
|
+
hasEntity(entity: IBaseEntity): boolean;
|
|
5
|
+
getEntity(entity: IBaseEntity): IBaseEntity;
|
|
6
|
+
addEntity(entity: IBaseEntity): void;
|
|
7
|
+
addEntities(entities: IBaseEntity[]): void;
|
|
8
|
+
isEntity(value: any): boolean;
|
|
9
|
+
needLoad(entity: IBaseEntity): boolean;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
private createEntityKey;
|
|
12
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.FormApiEntityMap = void 0;
|
|
5
|
+
var FormApiEntityMap = exports.FormApiEntityMap = /*#__PURE__*/function () {
|
|
6
|
+
function FormApiEntityMap() {
|
|
7
|
+
this.dataMap = new Map();
|
|
8
|
+
}
|
|
9
|
+
var _proto = FormApiEntityMap.prototype;
|
|
10
|
+
_proto.hasEntity = function hasEntity(entity) {
|
|
11
|
+
var key = this.createEntityKey(entity);
|
|
12
|
+
return this.dataMap.has(key);
|
|
13
|
+
};
|
|
14
|
+
_proto.getEntity = function getEntity(entity) {
|
|
15
|
+
var key = this.createEntityKey(entity);
|
|
16
|
+
return this.dataMap.get(key);
|
|
17
|
+
};
|
|
18
|
+
_proto.addEntity = function addEntity(entity) {
|
|
19
|
+
var key = this.createEntityKey(entity);
|
|
20
|
+
this.dataMap.set(key, entity);
|
|
21
|
+
};
|
|
22
|
+
_proto.addEntities = function addEntities(entities) {
|
|
23
|
+
var _this = this;
|
|
24
|
+
entities === null || entities === void 0 ? void 0 : entities.forEach(function (item) {
|
|
25
|
+
return _this.addEntity(item);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
_proto.isEntity = function isEntity(value) {
|
|
29
|
+
if (value == null) {
|
|
30
|
+
return false;
|
|
31
|
+
} else if (Array.isArray(value)) {
|
|
32
|
+
return false;
|
|
33
|
+
} else if (typeof value == "object") {
|
|
34
|
+
var _value$form;
|
|
35
|
+
return !!value.id && !!((_value$form = value.form) !== null && _value$form !== void 0 && _value$form.id);
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
_proto.needLoad = function needLoad(entity) {
|
|
40
|
+
return this.isEntity(entity) && entity._load == false;
|
|
41
|
+
};
|
|
42
|
+
_proto.destroy = function destroy() {
|
|
43
|
+
this.dataMap.clear();
|
|
44
|
+
};
|
|
45
|
+
_proto.createEntityKey = function createEntityKey(entity) {
|
|
46
|
+
var _entity$form, _entity$form2;
|
|
47
|
+
var key = (_entity$form = entity.form) === null || _entity$form === void 0 ? void 0 : _entity$form.id;
|
|
48
|
+
if ((_entity$form2 = entity.form) !== null && _entity$form2 !== void 0 && _entity$form2.fieldId) {
|
|
49
|
+
key += "." + entity.form.fieldId;
|
|
50
|
+
}
|
|
51
|
+
return key + "." + entity.id;
|
|
52
|
+
};
|
|
53
|
+
return FormApiEntityMap;
|
|
54
|
+
}();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FilterRule, IBaseEntity, Refs } from "
|
|
1
|
+
import { FilterRule, IBaseEntity, Refs } from "../rest-api";
|
|
2
2
|
export declare function convertSaveData(data: any): any;
|
|
3
3
|
export declare function dataToLabel(value: any): any;
|
|
4
4
|
export declare function assembleAssociationFieldV2(data: IBaseEntity | IBaseEntity[], refs?: Refs): void;
|
|
@@ -9,7 +9,8 @@ export declare function assembleAssociationFieldV2(data: IBaseEntity | IBaseEnti
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function assembleAssociationFieldDataV2(data: IBaseEntity | IBaseEntity[], dataMap: Map<string, IBaseEntity>): void;
|
|
11
11
|
export declare function handleEntityLabel(data: IBaseEntity | IBaseEntity[]): void;
|
|
12
|
-
export declare function assembleAssociationField(data: IBaseEntity | IBaseEntity[], refs?: Refs):
|
|
12
|
+
export declare function assembleAssociationField(data: IBaseEntity | IBaseEntity[], refs?: Refs): number;
|
|
13
13
|
export declare function handleFilterRules(filters: FilterRule[], options: {
|
|
14
14
|
filterNullValue: boolean;
|
|
15
15
|
}): FilterRule[];
|
|
16
|
+
export declare function safeGet(value: any, key: string | null): any;
|
|
@@ -9,20 +9,47 @@ exports.convertSaveData = convertSaveData;
|
|
|
9
9
|
exports.dataToLabel = dataToLabel;
|
|
10
10
|
exports.handleEntityLabel = handleEntityLabel;
|
|
11
11
|
exports.handleFilterRules = handleFilterRules;
|
|
12
|
+
exports.safeGet = safeGet;
|
|
12
13
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
var _data = require("
|
|
14
|
+
var _data = require("../../data");
|
|
15
|
+
var _common = require("../../common");
|
|
16
|
+
var _formApi = require("./form-api.assemble-entity");
|
|
17
|
+
var _util = require("../../util.common");
|
|
14
18
|
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
19
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
16
20
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
17
21
|
var SimpleSerialFieldNames = ["parent", "instance"];
|
|
18
22
|
function convertSaveData(data) {
|
|
19
23
|
if (!data) return data;
|
|
24
|
+
var seen = new WeakSet(); // WeakSet 只存储对象,非常适合检测引用
|
|
20
25
|
return JSON.parse(JSON.stringify(data, function (key, value) {
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
if (value == null) {
|
|
27
|
+
return null;
|
|
28
|
+
} else if (Array.isArray(value)) {
|
|
29
|
+
return value;
|
|
30
|
+
} else if (typeof value == "object") {
|
|
31
|
+
if (key == "form") {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
if (SimpleSerialFieldNames.includes(key)) {
|
|
35
|
+
var id = value === null || value === void 0 ? void 0 : value.id;
|
|
36
|
+
return id ? {
|
|
37
|
+
id: id,
|
|
38
|
+
form: value === null || value === void 0 ? void 0 : value.form
|
|
39
|
+
} : undefined;
|
|
40
|
+
} else if (seen.has(value)) {
|
|
41
|
+
if (value.id && value.form) {
|
|
42
|
+
return {
|
|
43
|
+
id: value.id,
|
|
44
|
+
form: value.form
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
seen.add(value);
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
26
53
|
}
|
|
27
54
|
return value;
|
|
28
55
|
}));
|
|
@@ -145,23 +172,14 @@ function handleEntityLabel(data) {
|
|
|
145
172
|
}
|
|
146
173
|
}
|
|
147
174
|
}
|
|
148
|
-
function valueToFormDataArray(value) {
|
|
149
|
-
if (typeof value == null || typeof value !== "object") {
|
|
150
|
-
return [];
|
|
151
|
-
}
|
|
152
|
-
if (Array.isArray(value)) {
|
|
153
|
-
return value === null || value === void 0 ? void 0 : value.filter(function (item) {
|
|
154
|
-
var _item$form;
|
|
155
|
-
return (item === null || item === void 0 ? void 0 : item.id) && (item === null || item === void 0 ? void 0 : (_item$form = item.form) === null || _item$form === void 0 ? void 0 : _item$form.id);
|
|
156
|
-
});
|
|
157
|
-
} else if (typeof value == "object" && value !== null) {
|
|
158
|
-
return valueToFormDataArray([value]);
|
|
159
|
-
} else {
|
|
160
|
-
return [];
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
175
|
function assembleAssociationField(data, refs) {
|
|
176
|
+
var start = Date.now();
|
|
177
|
+
if ((0, _common.isLocalhost)() || (0, _util.isTemplateHost)() || window.__mock) {
|
|
178
|
+
(0, _formApi.formApiAssembleEntity)(data, refs);
|
|
179
|
+
return Date.now() - start;
|
|
180
|
+
}
|
|
164
181
|
assembleAssociationFieldV2(data, refs);
|
|
182
|
+
return Date.now() - start;
|
|
165
183
|
}
|
|
166
184
|
function handleFilterRules(filters, options) {
|
|
167
185
|
var filterNullValue = options.filterNullValue;
|
|
@@ -170,13 +188,19 @@ function handleFilterRules(filters, options) {
|
|
|
170
188
|
return !!rule;
|
|
171
189
|
}).map(function (rule) {
|
|
172
190
|
return (0, _extends2["default"])({}, rule, {
|
|
173
|
-
value: (0, _data.transformerId)(rule.value
|
|
191
|
+
value: (0, _data.transformerId)(rule.value, {
|
|
192
|
+
includeNull: true
|
|
193
|
+
}),
|
|
174
194
|
rules: handleFilterRules(rule.rules || [], options)
|
|
175
195
|
});
|
|
176
196
|
});
|
|
177
197
|
if (filterNullValue) {
|
|
178
198
|
cloneRules = cloneRules.filter(function (rule) {
|
|
179
199
|
if (rule.value == null) {
|
|
200
|
+
var _rule$rules;
|
|
201
|
+
if ((_rule$rules = rule.rules) !== null && _rule$rules !== void 0 && _rule$rules.length) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
180
204
|
if (rule.operator != "isNull" && rule.operator != "isNotNull") {
|
|
181
205
|
return false;
|
|
182
206
|
}
|