@zhubangyun/lowcode-core 5.6.191 → 5.6.211

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.
@@ -1,4 +1,4 @@
1
- import { RestApi } from "./rest-api";
1
+ import { BaseRequestOptions, ManyResult, OneResult, RestApi, RestSearchParams } from "./rest-api";
2
2
  import { AxiosRequestConfig } from "axios";
3
3
  export declare class RestFormApi<DataType> extends RestApi<DataType> {
4
4
  private readonly formId;
@@ -9,4 +9,9 @@ export declare class RestFormApi<DataType> extends RestApi<DataType> {
9
9
  constructor(formId: string, fieldId?: string, mock?: boolean);
10
10
  initialize(): Promise<boolean>;
11
11
  handleRequestConfig(config: AxiosRequestConfig): Promise<void>;
12
+ search(params?: RestSearchParams): Promise<ManyResult<DataType>>;
13
+ getById(id: string, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
14
+ save(data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
15
+ create(data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
16
+ update(id: string, data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
12
17
  }
@@ -1,5 +1,8 @@
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; }
3
6
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
7
  import { RestApi } from "./rest-api";
5
8
  import { getSchema } from "./index";
@@ -105,5 +108,154 @@ export var RestFormApi = /*#__PURE__*/function (_RestApi) {
105
108
  }
106
109
  return handleRequestConfig;
107
110
  }();
111
+ _proto.search = /*#__PURE__*/function () {
112
+ var _search = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
113
+ var res;
114
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
115
+ while (1) switch (_context3.prev = _context3.next) {
116
+ case 0:
117
+ _context3.next = 2;
118
+ return _RestApi.prototype.search.call(this, params);
119
+ case 2:
120
+ res = _context3.sent;
121
+ res.data = assembleAssociationField(res.data, res.refs);
122
+ return _context3.abrupt("return", res);
123
+ case 5:
124
+ case "end":
125
+ return _context3.stop();
126
+ }
127
+ }, _callee3, this);
128
+ }));
129
+ function search(_x2) {
130
+ return _search.apply(this, arguments);
131
+ }
132
+ return search;
133
+ }();
134
+ _proto.getById = /*#__PURE__*/function () {
135
+ var _getById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, options) {
136
+ var res;
137
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
138
+ while (1) switch (_context4.prev = _context4.next) {
139
+ case 0:
140
+ _context4.next = 2;
141
+ return _RestApi.prototype.getById.call(this, id, options);
142
+ case 2:
143
+ res = _context4.sent;
144
+ res.data = assembleAssociationField(res.data, res.refs);
145
+ return _context4.abrupt("return", res);
146
+ case 5:
147
+ case "end":
148
+ return _context4.stop();
149
+ }
150
+ }, _callee4, this);
151
+ }));
152
+ function getById(_x3, _x4) {
153
+ return _getById.apply(this, arguments);
154
+ }
155
+ return getById;
156
+ }();
157
+ _proto.save = /*#__PURE__*/function () {
158
+ var _save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(data, options) {
159
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
160
+ while (1) switch (_context5.prev = _context5.next) {
161
+ case 0:
162
+ return _context5.abrupt("return", _RestApi.prototype.save.call(this, convertSaveData(data), options));
163
+ case 1:
164
+ case "end":
165
+ return _context5.stop();
166
+ }
167
+ }, _callee5, this);
168
+ }));
169
+ function save(_x5, _x6) {
170
+ return _save.apply(this, arguments);
171
+ }
172
+ return save;
173
+ }();
174
+ _proto.create = /*#__PURE__*/function () {
175
+ var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(data, options) {
176
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
177
+ while (1) switch (_context6.prev = _context6.next) {
178
+ case 0:
179
+ return _context6.abrupt("return", _RestApi.prototype.create.call(this, convertSaveData(data), options));
180
+ case 1:
181
+ case "end":
182
+ return _context6.stop();
183
+ }
184
+ }, _callee6, this);
185
+ }));
186
+ function create(_x7, _x8) {
187
+ return _create.apply(this, arguments);
188
+ }
189
+ return create;
190
+ }();
191
+ _proto.update = /*#__PURE__*/function () {
192
+ var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(id, data, options) {
193
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
194
+ while (1) switch (_context7.prev = _context7.next) {
195
+ case 0:
196
+ return _context7.abrupt("return", _RestApi.prototype.update.call(this, id, convertSaveData(data), options));
197
+ case 1:
198
+ case "end":
199
+ return _context7.stop();
200
+ }
201
+ }, _callee7, this);
202
+ }));
203
+ function update(_x9, _x10, _x11) {
204
+ return _update.apply(this, arguments);
205
+ }
206
+ return update;
207
+ }();
108
208
  return RestFormApi;
109
- }(RestApi);
209
+ }(RestApi);
210
+ function convertSaveData(data) {
211
+ if (!data) return data;
212
+ return JSON.parse(JSON.stringify(data, function (key, value) {
213
+ if (key == "parent") {
214
+ return value === null || value === void 0 ? void 0 : value.id;
215
+ }
216
+ return value;
217
+ }));
218
+ }
219
+ function assembleAssociationField(data, refs) {
220
+ if (!data || !refs) return;
221
+ var fieldIdDataMap = new Map();
222
+ for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
223
+ var ref = _step.value;
224
+ var dataMap = new Map();
225
+ for (var _iterator2 = _createForOfIteratorHelperLoose(ref.data), _step2; !(_step2 = _iterator2()).done;) {
226
+ var datum = _step2.value;
227
+ dataMap.set(datum.id, datum);
228
+ }
229
+ for (var _iterator3 = _createForOfIteratorHelperLoose(ref.fieldIds), _step3; !(_step3 = _iterator3()).done;) {
230
+ var fieldId = _step3.value;
231
+ fieldIdDataMap.set(fieldId + "Id", dataMap);
232
+ }
233
+ }
234
+ var jsonText = JSON.stringify(data, function (key, value) {
235
+ if (value !== null && value !== void 0 && value.id) {
236
+ var _loop = function _loop() {
237
+ var fieldIdName = _Object$keys[_i];
238
+ var dataMap = fieldIdDataMap.get(fieldIdName);
239
+ if (dataMap) {
240
+ var fieldIdValue = value[fieldIdName];
241
+ var fieldValue = null;
242
+ if (Array.isArray(fieldIdValue)) {
243
+ fieldValue = fieldIdValue.map(function (id) {
244
+ return dataMap.get(id);
245
+ }).filter(function (v) {
246
+ return !!v;
247
+ });
248
+ } else if (typeof fieldIdValue == "string") {
249
+ fieldValue = dataMap.get(fieldIdValue);
250
+ }
251
+ value[fieldIdName.slice(0, -2)] = fieldValue;
252
+ }
253
+ };
254
+ for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
255
+ _loop();
256
+ }
257
+ }
258
+ return value;
259
+ });
260
+ return JSON.parse(jsonText);
261
+ }
@@ -87,7 +87,17 @@ export interface BaseType {
87
87
  export interface BaseResult<DataType> {
88
88
  success: boolean;
89
89
  message?: string;
90
+ refs?: Refs;
90
91
  }
92
+ export interface Ref {
93
+ form: {
94
+ id: string;
95
+ fieldId?: string;
96
+ };
97
+ fieldIds: string[];
98
+ data: BaseType[];
99
+ }
100
+ export declare type Refs = Ref[];
91
101
  export interface OneResult<DataType> extends BaseResult<DataType> {
92
102
  data: DataType & BaseType;
93
103
  }
@@ -141,7 +141,7 @@ function _handleAssociationForm() {
141
141
  //处理关联属性 赋值schema
142
142
  _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
143
143
  var _attrField$props, _attrField$props$fiel, _findField$props, _findField$props$fiel;
144
- var attrField, associationAttribute, findField, associationForm, associationFormSchema, associationAttributeField, field, key, keys;
144
+ var attrField, associationAttribute, findField, associationForm, associationFormSchema, associationAttributeField, field, associationField, depth1, depth2;
145
145
  return _regeneratorRuntime.wrap(function _loop$(_context2) {
146
146
  while (1) switch (_context2.prev = _context2.next) {
147
147
  case 0:
@@ -185,31 +185,33 @@ function _handleAssociationForm() {
185
185
  //向关联表单中注册关联属性填充 开始
186
186
  findField.props.fieldProps.associationAttributes = findField.props.fieldProps.associationAttributes || [];
187
187
  field = rootSchema.findFieldById(attrField.props.fieldId);
188
- if (field) {
189
- key = field.getFieldPaths();
190
- findField.props.fieldProps.associationAttributes.push({
191
- key: key,
192
- value: associationAttribute === null || associationAttribute === void 0 ? void 0 : associationAttribute[1]
193
- });
194
- //向关联表单中注册关联属性填充 结束
195
- //设置关联属性默认值 开始
196
- keys = field.getFieldPaths().split(".");
197
- keys.pop();
198
- if (keys.length > 0) {
199
- keys = keys.map(function (item) {
200
- return "parent";
201
- });
202
- keys.push(associationAttribute[0]);
203
- keys.push(associationAttribute[1]);
204
- attrField.props.defaultValue = {
205
- "type": "express",
206
- "value": keys.join("?.")
207
- };
208
- console.log(attrField);
209
- }
188
+ associationField = rootSchema.findFieldById(associationAttribute[0]);
189
+ if (field && associationField) {
190
+ depth1 = field.getFieldPaths().split(".").length;
191
+ depth2 = associationField.getFieldPaths().split(".").length;
192
+ attrField.props.fieldProps.associationDepth = depth1 - depth2;
193
+ /* findField.props.fieldProps.associationAttributes.push({
194
+ key: key,
195
+ value: associationAttribute?.[1]
196
+ })
197
+ console.log(field.getFieldPaths())
198
+ //向关联表单中注册关联属性填充 结束
199
+ //设置关联属性默认值 开始
200
+ let keys = field.getFieldPaths().split(".");
201
+ keys.pop();
202
+ attrField.props.fieldProps.associationDepth = keys.length;
203
+ if (keys.length > 0) {
204
+ keys = keys.map(item => "parent");
205
+ keys.push(associationAttribute[0])
206
+ keys.push(associationAttribute[1])
207
+ attrField.props.defaultValue = {
208
+ "type": "express",
209
+ "value": keys.join("?.")
210
+ }
211
+ }*/
210
212
  }
211
213
  //设置关联属性默认值 结束
212
- case 17:
214
+ case 18:
213
215
  case "end":
214
216
  return _context2.stop();
215
217
  }
@@ -1,4 +1,5 @@
1
1
  export { showForm } from "./page-form";
2
+ export { showFormDataManager } from "./page-form-data-manager";
2
3
  export declare function showLoading(): Promise<void>;
3
4
  export declare function hideLoading(): Promise<void>;
4
5
  export declare function openPage(url: string, target?: string): Promise<any>;
@@ -1,6 +1,7 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  export { showForm } from "./page-form";
4
+ export { showFormDataManager } from "./page-form-data-manager";
4
5
  var timerRef;
5
6
  function debounceHide() {
6
7
  if (timerRef) {
@@ -0,0 +1,15 @@
1
+ import { PageLayoutType } from "./page-layout";
2
+ export declare type PageFormDataManagerModeType = "dataManager" | "selectOne" | "selectMore";
3
+ export interface ShowPageFormDataManagerProps {
4
+ container?: HTMLDivElement;
5
+ layout?: PageLayoutType;
6
+ form?: {
7
+ id: string;
8
+ fieldId?: string;
9
+ };
10
+ mode?: PageFormDataManagerModeType;
11
+ onSubmitOk?: () => void;
12
+ onRemoveOk?: () => void;
13
+ onClose?: () => void | Promise<void>;
14
+ }
15
+ export declare function showFormDataManager(options: ShowPageFormDataManagerProps): Promise<void>;
@@ -0,0 +1,132 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
5
+ var _excluded = ["layout", "form", "onClose"],
6
+ _excluded2 = ["container", "onClose"];
7
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
8
+ import { PageLayout } from "./page-layout";
9
+ import ReactDOM from "react-dom";
10
+ import React, { Component } from "react";
11
+ import { PageLoadSchema } from "./page-load-schema";
12
+ import { ReactRender } from "../../components/react-render";
13
+ import { openPage } from "./index";
14
+ import { forEachFormSchema } from "../cache/schema";
15
+ export function showFormDataManager(_x) {
16
+ return _showFormDataManager.apply(this, arguments);
17
+ }
18
+ function _showFormDataManager() {
19
+ _showFormDataManager = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
20
+ var container, onClose, restProps, unmount, _options$form, paths, mode, params, url, page;
21
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
22
+ while (1) switch (_context2.prev = _context2.next) {
23
+ case 0:
24
+ container = options.container, onClose = options.onClose, restProps = _objectWithoutPropertiesLoose(options, _excluded2); //容器不存在需要手动取消挂载
25
+ unmount = !container;
26
+ if (container) {
27
+ _context2.next = 15;
28
+ break;
29
+ }
30
+ if (!(options.layout == "page")) {
31
+ _context2.next = 13;
32
+ break;
33
+ }
34
+ paths = window.location.pathname.split("/");
35
+ mode = options.mode;
36
+ params = new URLSearchParams();
37
+ url = "/" + paths[1] + "/" + paths[2] + "/" + ((_options$form = options.form) === null || _options$form === void 0 ? void 0 : _options$form.id) + "/" + mode + "?" + params.toString();
38
+ _context2.next = 10;
39
+ return openPage(url, url);
40
+ case 10:
41
+ page = _context2.sent;
42
+ console.debug("openPage", page);
43
+ return _context2.abrupt("return");
44
+ case 13:
45
+ container = document.createElement("div");
46
+ document.body.append(container);
47
+ case 15:
48
+ ReactDOM.render( /*#__PURE__*/React.createElement(FormRender, _extends({}, restProps, {
49
+ onClose: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
50
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
51
+ while (1) switch (_context.prev = _context.next) {
52
+ case 0:
53
+ if (unmount) {
54
+ //等待动画结束
55
+ setTimeout(function () {
56
+ var _container;
57
+ //取消挂载
58
+ ReactDOM.unmountComponentAtNode(container);
59
+ //移除
60
+ (_container = container) === null || _container === void 0 ? void 0 : _container.remove();
61
+ }, 1000);
62
+ }
63
+ onClose === null || onClose === void 0 ? void 0 : onClose();
64
+ case 2:
65
+ case "end":
66
+ return _context.stop();
67
+ }
68
+ }, _callee);
69
+ }))
70
+ })), container);
71
+ case 16:
72
+ case "end":
73
+ return _context2.stop();
74
+ }
75
+ }, _callee2);
76
+ }));
77
+ return _showFormDataManager.apply(this, arguments);
78
+ }
79
+ var FormRender = /*#__PURE__*/function (_Component) {
80
+ function FormRender() {
81
+ var _this;
82
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
83
+ args[_key] = arguments[_key];
84
+ }
85
+ _this = _Component.call.apply(_Component, [this].concat(args)) || this;
86
+ _this.layoutRef = void 0;
87
+ return _this;
88
+ }
89
+ _inheritsLoose(FormRender, _Component);
90
+ var _proto = FormRender.prototype;
91
+ _proto.render = function render() {
92
+ var _this2 = this;
93
+ var self = this;
94
+ var _this$props = this.props,
95
+ layout = _this$props.layout,
96
+ form = _this$props.form,
97
+ onClose = _this$props.onClose,
98
+ restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
99
+ // @ts-ignore
100
+ restProps.layout = layout || "drawer";
101
+ // @ts-ignore
102
+ restProps.onClose = function () {
103
+ var _self$layoutRef;
104
+ (_self$layoutRef = self.layoutRef) === null || _self$layoutRef === void 0 ? void 0 : _self$layoutRef.close();
105
+ onClose === null || onClose === void 0 ? void 0 : onClose();
106
+ };
107
+ return /*#__PURE__*/React.createElement(PageLayout, {
108
+ layout: layout,
109
+ ref: function ref(layout) {
110
+ return _this2.layoutRef = layout;
111
+ }
112
+ }, /*#__PURE__*/React.createElement(PageLoadSchema, {
113
+ pageId: form === null || form === void 0 ? void 0 : form.id
114
+ }, function (schema) {
115
+ var fdmSchema = schema.children[0].fdmSchema;
116
+ if (form !== null && form !== void 0 && form.fieldId) {
117
+ forEachFormSchema(schema, function (field) {
118
+ if (form.fieldId == field.props.fieldId) {
119
+ fdmSchema = field.fdmSchema;
120
+ return false;
121
+ }
122
+ return true;
123
+ });
124
+ }
125
+ return /*#__PURE__*/React.createElement(ReactRender, _extends({
126
+ schema: schema,
127
+ components: window._components || window.components || window.__components
128
+ }, restProps));
129
+ }));
130
+ };
131
+ return FormRender;
132
+ }(Component);
@@ -1,4 +1,4 @@
1
- import { RestApi } from "./rest-api";
1
+ import { BaseRequestOptions, ManyResult, OneResult, RestApi, RestSearchParams } from "./rest-api";
2
2
  import { AxiosRequestConfig } from "axios";
3
3
  export declare class RestFormApi<DataType> extends RestApi<DataType> {
4
4
  private readonly formId;
@@ -9,4 +9,9 @@ export declare class RestFormApi<DataType> extends RestApi<DataType> {
9
9
  constructor(formId: string, fieldId?: string, mock?: boolean);
10
10
  initialize(): Promise<boolean>;
11
11
  handleRequestConfig(config: AxiosRequestConfig): Promise<void>;
12
+ search(params?: RestSearchParams): Promise<ManyResult<DataType>>;
13
+ getById(id: string, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
14
+ save(data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
15
+ create(data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
16
+ update(id: string, data: DataType, options?: BaseRequestOptions<DataType>): Promise<OneResult<DataType>>;
12
17
  }
@@ -8,6 +8,9 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
8
8
  var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
9
9
  var _restApi = require("./rest-api");
10
10
  var _index = require("./index");
11
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
14
  var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
12
15
  function RestFormApi(formId, fieldId, mock) {
13
16
  var _this;
@@ -110,5 +113,154 @@ var RestFormApi = exports.RestFormApi = /*#__PURE__*/function (_RestApi) {
110
113
  }
111
114
  return handleRequestConfig;
112
115
  }();
116
+ _proto.search = /*#__PURE__*/function () {
117
+ var _search = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(params) {
118
+ var res;
119
+ return _regenerator["default"].wrap(function _callee3$(_context3) {
120
+ while (1) switch (_context3.prev = _context3.next) {
121
+ case 0:
122
+ _context3.next = 2;
123
+ return _RestApi.prototype.search.call(this, params);
124
+ case 2:
125
+ res = _context3.sent;
126
+ res.data = assembleAssociationField(res.data, res.refs);
127
+ return _context3.abrupt("return", res);
128
+ case 5:
129
+ case "end":
130
+ return _context3.stop();
131
+ }
132
+ }, _callee3, this);
133
+ }));
134
+ function search(_x2) {
135
+ return _search.apply(this, arguments);
136
+ }
137
+ return search;
138
+ }();
139
+ _proto.getById = /*#__PURE__*/function () {
140
+ var _getById = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(id, options) {
141
+ var res;
142
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
143
+ while (1) switch (_context4.prev = _context4.next) {
144
+ case 0:
145
+ _context4.next = 2;
146
+ return _RestApi.prototype.getById.call(this, id, options);
147
+ case 2:
148
+ res = _context4.sent;
149
+ res.data = assembleAssociationField(res.data, res.refs);
150
+ return _context4.abrupt("return", res);
151
+ case 5:
152
+ case "end":
153
+ return _context4.stop();
154
+ }
155
+ }, _callee4, this);
156
+ }));
157
+ function getById(_x3, _x4) {
158
+ return _getById.apply(this, arguments);
159
+ }
160
+ return getById;
161
+ }();
162
+ _proto.save = /*#__PURE__*/function () {
163
+ var _save = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(data, options) {
164
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
165
+ while (1) switch (_context5.prev = _context5.next) {
166
+ case 0:
167
+ return _context5.abrupt("return", _RestApi.prototype.save.call(this, convertSaveData(data), options));
168
+ case 1:
169
+ case "end":
170
+ return _context5.stop();
171
+ }
172
+ }, _callee5, this);
173
+ }));
174
+ function save(_x5, _x6) {
175
+ return _save.apply(this, arguments);
176
+ }
177
+ return save;
178
+ }();
179
+ _proto.create = /*#__PURE__*/function () {
180
+ var _create = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(data, options) {
181
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
182
+ while (1) switch (_context6.prev = _context6.next) {
183
+ case 0:
184
+ return _context6.abrupt("return", _RestApi.prototype.create.call(this, convertSaveData(data), options));
185
+ case 1:
186
+ case "end":
187
+ return _context6.stop();
188
+ }
189
+ }, _callee6, this);
190
+ }));
191
+ function create(_x7, _x8) {
192
+ return _create.apply(this, arguments);
193
+ }
194
+ return create;
195
+ }();
196
+ _proto.update = /*#__PURE__*/function () {
197
+ var _update = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(id, data, options) {
198
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
199
+ while (1) switch (_context7.prev = _context7.next) {
200
+ case 0:
201
+ return _context7.abrupt("return", _RestApi.prototype.update.call(this, id, convertSaveData(data), options));
202
+ case 1:
203
+ case "end":
204
+ return _context7.stop();
205
+ }
206
+ }, _callee7, this);
207
+ }));
208
+ function update(_x9, _x10, _x11) {
209
+ return _update.apply(this, arguments);
210
+ }
211
+ return update;
212
+ }();
113
213
  return RestFormApi;
114
- }(_restApi.RestApi);
214
+ }(_restApi.RestApi);
215
+ function convertSaveData(data) {
216
+ if (!data) return data;
217
+ return JSON.parse(JSON.stringify(data, function (key, value) {
218
+ if (key == "parent") {
219
+ return value === null || value === void 0 ? void 0 : value.id;
220
+ }
221
+ return value;
222
+ }));
223
+ }
224
+ function assembleAssociationField(data, refs) {
225
+ if (!data || !refs) return;
226
+ var fieldIdDataMap = new Map();
227
+ for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
228
+ var ref = _step.value;
229
+ var dataMap = new Map();
230
+ for (var _iterator2 = _createForOfIteratorHelperLoose(ref.data), _step2; !(_step2 = _iterator2()).done;) {
231
+ var datum = _step2.value;
232
+ dataMap.set(datum.id, datum);
233
+ }
234
+ for (var _iterator3 = _createForOfIteratorHelperLoose(ref.fieldIds), _step3; !(_step3 = _iterator3()).done;) {
235
+ var fieldId = _step3.value;
236
+ fieldIdDataMap.set(fieldId + "Id", dataMap);
237
+ }
238
+ }
239
+ var jsonText = JSON.stringify(data, function (key, value) {
240
+ if (value !== null && value !== void 0 && value.id) {
241
+ var _loop = function _loop() {
242
+ var fieldIdName = _Object$keys[_i];
243
+ var dataMap = fieldIdDataMap.get(fieldIdName);
244
+ if (dataMap) {
245
+ var fieldIdValue = value[fieldIdName];
246
+ var fieldValue = null;
247
+ if (Array.isArray(fieldIdValue)) {
248
+ fieldValue = fieldIdValue.map(function (id) {
249
+ return dataMap.get(id);
250
+ }).filter(function (v) {
251
+ return !!v;
252
+ });
253
+ } else if (typeof fieldIdValue == "string") {
254
+ fieldValue = dataMap.get(fieldIdValue);
255
+ }
256
+ value[fieldIdName.slice(0, -2)] = fieldValue;
257
+ }
258
+ };
259
+ for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
260
+ _loop();
261
+ }
262
+ }
263
+ return value;
264
+ });
265
+ return JSON.parse(jsonText);
266
+ }
@@ -87,7 +87,17 @@ export interface BaseType {
87
87
  export interface BaseResult<DataType> {
88
88
  success: boolean;
89
89
  message?: string;
90
+ refs?: Refs;
90
91
  }
92
+ export interface Ref {
93
+ form: {
94
+ id: string;
95
+ fieldId?: string;
96
+ };
97
+ fieldIds: string[];
98
+ data: BaseType[];
99
+ }
100
+ export declare type Refs = Ref[];
91
101
  export interface OneResult<DataType> extends BaseResult<DataType> {
92
102
  data: DataType & BaseType;
93
103
  }
@@ -145,7 +145,7 @@ function _handleAssociationForm() {
145
145
  //处理关联属性 赋值schema
146
146
  _loop = /*#__PURE__*/_regenerator["default"].mark(function _loop() {
147
147
  var _attrField$props, _attrField$props$fiel, _findField$props, _findField$props$fiel;
148
- var attrField, associationAttribute, findField, associationForm, associationFormSchema, associationAttributeField, field, key, keys;
148
+ var attrField, associationAttribute, findField, associationForm, associationFormSchema, associationAttributeField, field, associationField, depth1, depth2;
149
149
  return _regenerator["default"].wrap(function _loop$(_context2) {
150
150
  while (1) switch (_context2.prev = _context2.next) {
151
151
  case 0:
@@ -189,31 +189,33 @@ function _handleAssociationForm() {
189
189
  //向关联表单中注册关联属性填充 开始
190
190
  findField.props.fieldProps.associationAttributes = findField.props.fieldProps.associationAttributes || [];
191
191
  field = rootSchema.findFieldById(attrField.props.fieldId);
192
- if (field) {
193
- key = field.getFieldPaths();
194
- findField.props.fieldProps.associationAttributes.push({
195
- key: key,
196
- value: associationAttribute === null || associationAttribute === void 0 ? void 0 : associationAttribute[1]
197
- });
198
- //向关联表单中注册关联属性填充 结束
199
- //设置关联属性默认值 开始
200
- keys = field.getFieldPaths().split(".");
201
- keys.pop();
202
- if (keys.length > 0) {
203
- keys = keys.map(function (item) {
204
- return "parent";
205
- });
206
- keys.push(associationAttribute[0]);
207
- keys.push(associationAttribute[1]);
208
- attrField.props.defaultValue = {
209
- "type": "express",
210
- "value": keys.join("?.")
211
- };
212
- console.log(attrField);
213
- }
192
+ associationField = rootSchema.findFieldById(associationAttribute[0]);
193
+ if (field && associationField) {
194
+ depth1 = field.getFieldPaths().split(".").length;
195
+ depth2 = associationField.getFieldPaths().split(".").length;
196
+ attrField.props.fieldProps.associationDepth = depth1 - depth2;
197
+ /* findField.props.fieldProps.associationAttributes.push({
198
+ key: key,
199
+ value: associationAttribute?.[1]
200
+ })
201
+ console.log(field.getFieldPaths())
202
+ //向关联表单中注册关联属性填充 结束
203
+ //设置关联属性默认值 开始
204
+ let keys = field.getFieldPaths().split(".");
205
+ keys.pop();
206
+ attrField.props.fieldProps.associationDepth = keys.length;
207
+ if (keys.length > 0) {
208
+ keys = keys.map(item => "parent");
209
+ keys.push(associationAttribute[0])
210
+ keys.push(associationAttribute[1])
211
+ attrField.props.defaultValue = {
212
+ "type": "express",
213
+ "value": keys.join("?.")
214
+ }
215
+ }*/
214
216
  }
215
217
  //设置关联属性默认值 结束
216
- case 17:
218
+ case 18:
217
219
  case "end":
218
220
  return _context2.stop();
219
221
  }
@@ -1,4 +1,5 @@
1
1
  export { showForm } from "./page-form";
2
+ export { showFormDataManager } from "./page-form-data-manager";
2
3
  export declare function showLoading(): Promise<void>;
3
4
  export declare function hideLoading(): Promise<void>;
4
5
  export declare function openPage(url: string, target?: string): Promise<any>;
@@ -5,12 +5,14 @@ exports.__esModule = true;
5
5
  exports.closePage = closePage;
6
6
  exports.hideLoading = hideLoading;
7
7
  exports.openPage = openPage;
8
- exports.showForm = void 0;
8
+ exports.showFormDataManager = exports.showForm = void 0;
9
9
  exports.showLoading = showLoading;
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
12
  var _pageForm = require("./page-form");
13
13
  exports.showForm = _pageForm.showForm;
14
+ var _pageFormDataManager = require("./page-form-data-manager");
15
+ exports.showFormDataManager = _pageFormDataManager.showFormDataManager;
14
16
  var timerRef;
15
17
  function debounceHide() {
16
18
  if (timerRef) {
@@ -0,0 +1,15 @@
1
+ import { PageLayoutType } from "./page-layout";
2
+ export declare type PageFormDataManagerModeType = "dataManager" | "selectOne" | "selectMore";
3
+ export interface ShowPageFormDataManagerProps {
4
+ container?: HTMLDivElement;
5
+ layout?: PageLayoutType;
6
+ form?: {
7
+ id: string;
8
+ fieldId?: string;
9
+ };
10
+ mode?: PageFormDataManagerModeType;
11
+ onSubmitOk?: () => void;
12
+ onRemoveOk?: () => void;
13
+ onClose?: () => void | Promise<void>;
14
+ }
15
+ export declare function showFormDataManager(options: ShowPageFormDataManagerProps): Promise<void>;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.showFormDataManager = showFormDataManager;
6
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
7
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
+ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var _pageLayout = require("./page-layout");
12
+ var _reactDom = _interopRequireDefault(require("react-dom"));
13
+ var _react = _interopRequireWildcard(require("react"));
14
+ var _pageLoadSchema = require("./page-load-schema");
15
+ var _reactRender = require("../../components/react-render");
16
+ var _index = require("./index");
17
+ var _schema = require("../cache/schema");
18
+ var _excluded = ["layout", "form", "onClose"],
19
+ _excluded2 = ["container", "onClose"];
20
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
22
+ function showFormDataManager(_x) {
23
+ return _showFormDataManager.apply(this, arguments);
24
+ }
25
+ function _showFormDataManager() {
26
+ _showFormDataManager = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(options) {
27
+ var container, onClose, restProps, unmount, _options$form, paths, mode, params, url, page;
28
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
29
+ while (1) switch (_context2.prev = _context2.next) {
30
+ case 0:
31
+ container = options.container, onClose = options.onClose, restProps = (0, _objectWithoutPropertiesLoose2["default"])(options, _excluded2); //容器不存在需要手动取消挂载
32
+ unmount = !container;
33
+ if (container) {
34
+ _context2.next = 15;
35
+ break;
36
+ }
37
+ if (!(options.layout == "page")) {
38
+ _context2.next = 13;
39
+ break;
40
+ }
41
+ paths = window.location.pathname.split("/");
42
+ mode = options.mode;
43
+ params = new URLSearchParams();
44
+ url = "/" + paths[1] + "/" + paths[2] + "/" + ((_options$form = options.form) === null || _options$form === void 0 ? void 0 : _options$form.id) + "/" + mode + "?" + params.toString();
45
+ _context2.next = 10;
46
+ return (0, _index.openPage)(url, url);
47
+ case 10:
48
+ page = _context2.sent;
49
+ console.debug("openPage", page);
50
+ return _context2.abrupt("return");
51
+ case 13:
52
+ container = document.createElement("div");
53
+ document.body.append(container);
54
+ case 15:
55
+ _reactDom["default"].render( /*#__PURE__*/_react["default"].createElement(FormRender, (0, _extends2["default"])({}, restProps, {
56
+ onClose: /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
57
+ return _regenerator["default"].wrap(function _callee$(_context) {
58
+ while (1) switch (_context.prev = _context.next) {
59
+ case 0:
60
+ if (unmount) {
61
+ //等待动画结束
62
+ setTimeout(function () {
63
+ var _container;
64
+ //取消挂载
65
+ _reactDom["default"].unmountComponentAtNode(container);
66
+ //移除
67
+ (_container = container) === null || _container === void 0 ? void 0 : _container.remove();
68
+ }, 1000);
69
+ }
70
+ onClose === null || onClose === void 0 ? void 0 : onClose();
71
+ case 2:
72
+ case "end":
73
+ return _context.stop();
74
+ }
75
+ }, _callee);
76
+ }))
77
+ })), container);
78
+ case 16:
79
+ case "end":
80
+ return _context2.stop();
81
+ }
82
+ }, _callee2);
83
+ }));
84
+ return _showFormDataManager.apply(this, arguments);
85
+ }
86
+ var FormRender = /*#__PURE__*/function (_Component) {
87
+ function FormRender() {
88
+ var _this;
89
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
90
+ args[_key] = arguments[_key];
91
+ }
92
+ _this = _Component.call.apply(_Component, [this].concat(args)) || this;
93
+ _this.layoutRef = void 0;
94
+ return _this;
95
+ }
96
+ (0, _inheritsLoose2["default"])(FormRender, _Component);
97
+ var _proto = FormRender.prototype;
98
+ _proto.render = function render() {
99
+ var _this2 = this;
100
+ var self = this;
101
+ var _this$props = this.props,
102
+ layout = _this$props.layout,
103
+ form = _this$props.form,
104
+ onClose = _this$props.onClose,
105
+ restProps = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
106
+ // @ts-ignore
107
+ restProps.layout = layout || "drawer";
108
+ // @ts-ignore
109
+ restProps.onClose = function () {
110
+ var _self$layoutRef;
111
+ (_self$layoutRef = self.layoutRef) === null || _self$layoutRef === void 0 ? void 0 : _self$layoutRef.close();
112
+ onClose === null || onClose === void 0 ? void 0 : onClose();
113
+ };
114
+ return /*#__PURE__*/_react["default"].createElement(_pageLayout.PageLayout, {
115
+ layout: layout,
116
+ ref: function ref(layout) {
117
+ return _this2.layoutRef = layout;
118
+ }
119
+ }, /*#__PURE__*/_react["default"].createElement(_pageLoadSchema.PageLoadSchema, {
120
+ pageId: form === null || form === void 0 ? void 0 : form.id
121
+ }, function (schema) {
122
+ var fdmSchema = schema.children[0].fdmSchema;
123
+ if (form !== null && form !== void 0 && form.fieldId) {
124
+ (0, _schema.forEachFormSchema)(schema, function (field) {
125
+ if (form.fieldId == field.props.fieldId) {
126
+ fdmSchema = field.fdmSchema;
127
+ return false;
128
+ }
129
+ return true;
130
+ });
131
+ }
132
+ return /*#__PURE__*/_react["default"].createElement(_reactRender.ReactRender, (0, _extends2["default"])({
133
+ schema: schema,
134
+ components: window._components || window.components || window.__components
135
+ }, restProps));
136
+ }));
137
+ };
138
+ return FormRender;
139
+ }(_react.Component);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhubangyun/lowcode-core",
3
- "version": "5.6.191",
3
+ "version": "5.6.211",
4
4
  "description": "低代码核心",
5
5
  "files": [
6
6
  "lib",
@@ -1,26 +0,0 @@
1
- import { FormInstance } from "antd/lib";
2
- import { NamePath, StoreValue } from "antd/es/form/interface";
3
- declare type NamePaths = (string | number)[];
4
- export declare class SubFormInstance implements FormInstance {
5
- parentForm: FormInstance;
6
- namePath: NamePaths;
7
- constructor(form: FormInstance, namePath: NamePaths);
8
- overwritePathName(name: NamePath): any[];
9
- overwriteFields(fields: any[]): any[];
10
- getFieldError(name: NamePath): string[];
11
- getFieldValue(name: NamePath): StoreValue;
12
- getFieldWarning(name: NamePath): string[];
13
- getFieldsError(nameList: NamePath[] | undefined): any[];
14
- getFieldsValue(nameList?: NamePath[] | true, filterFunc?: (meta: any) => boolean): any;
15
- isFieldTouched(name: NamePath): boolean;
16
- isFieldValidating(name: NamePath): boolean;
17
- isFieldsTouched(): boolean;
18
- isFieldsValidating(nameList: NamePath[]): boolean;
19
- resetFields(fields: NamePath[] | undefined): void;
20
- setFieldValue(name: NamePath, value: any): void;
21
- setFields(fields: any[]): void;
22
- setFieldsValue(values: any): void;
23
- submit(): void;
24
- validateFields(nameList: NamePath[] | undefined): Promise<any>;
25
- }
26
- export {};
@@ -1,100 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- export var SubFormInstance = /*#__PURE__*/function () {
3
- function SubFormInstance(form, namePath) {
4
- this.parentForm = void 0;
5
- this.namePath = void 0;
6
- this.parentForm = form;
7
- this.namePath = namePath;
8
- }
9
- var _proto = SubFormInstance.prototype;
10
- _proto.overwritePathName = function overwritePathName(name) {
11
- if (Array.isArray(name)) {
12
- return [].concat(this.namePath, name);
13
- } else {
14
- return [].concat(this.namePath, [name]);
15
- }
16
- };
17
- _proto.overwriteFields = function overwriteFields(fields) {
18
- var _this = this;
19
- return fields === null || fields === void 0 ? void 0 : fields.map(function (field) {
20
- return _extends({}, field, {
21
- name: _this.overwritePathName(field.name)
22
- });
23
- });
24
- };
25
- _proto.getFieldError = function getFieldError(name) {
26
- return this.parentForm.getFieldError(this.overwritePathName(name));
27
- };
28
- _proto.getFieldValue = function getFieldValue(name) {
29
- return this.parentForm.getFieldValue(this.overwritePathName(name));
30
- };
31
- _proto.getFieldWarning = function getFieldWarning(name) {
32
- return this.parentForm.getFieldWarning(this.overwritePathName(name));
33
- }
34
-
35
- // @ts-ignore
36
- ;
37
- _proto.getFieldsError = function getFieldsError(nameList) {
38
- var _this2 = this;
39
- return this.parentForm.getFieldsError(nameList === null || nameList === void 0 ? void 0 : nameList.map(function (name) {
40
- return _this2.overwritePathName(name);
41
- }));
42
- }
43
-
44
- // @ts-ignore
45
- ;
46
- _proto.getFieldsValue = function getFieldsValue(nameList, filterFunc) {
47
- var values = _extends({}, this.parentForm.getFieldValue(this.namePath));
48
- values.parent = this.parentForm.getFieldsValue(true);
49
- return values;
50
- };
51
- _proto.isFieldTouched = function isFieldTouched(name) {
52
- return this.parentForm.isFieldTouched(this.overwritePathName(name));
53
- };
54
- _proto.isFieldValidating = function isFieldValidating(name) {
55
- return this.parentForm.isFieldValidating(this.overwritePathName(name));
56
- };
57
- _proto.isFieldsTouched = function isFieldsTouched() {
58
- return this.parentForm.isFieldsTouched();
59
- };
60
- // @ts-ignore
61
- _proto.isFieldsValidating = function isFieldsValidating(nameList) {
62
- var _this3 = this;
63
- return this.parentForm.isFieldsValidating(nameList.map(function (name) {
64
- return _this3.overwritePathName(name);
65
- }));
66
- };
67
- _proto.resetFields = function resetFields(fields) {
68
- if (Array.isArray(fields)) {
69
- // @ts-ignore
70
- this.parentForm.resetFields(this.overwriteFields(fields));
71
- } else {
72
- this.parentForm.resetFields();
73
- }
74
- };
75
- _proto.setFieldValue = function setFieldValue(name, value) {
76
- return this.parentForm.setFieldValue(this.overwritePathName(name), value);
77
- };
78
- _proto.setFields = function setFields(fields) {
79
- this.parentForm.setFields(this.overwriteFields(fields));
80
- };
81
- _proto.setFieldsValue = function setFieldsValue(values) {
82
- var _this4 = this;
83
- if (!values) return;
84
- //删除父值
85
- delete values.parent;
86
- Object.keys(values).forEach(function (name) {
87
- return _this4.parentForm.setFieldValue(_this4.overwritePathName(name), values[name]);
88
- });
89
- };
90
- _proto.submit = function submit() {
91
- this.parentForm.submit();
92
- }
93
-
94
- // @ts-ignore
95
- ;
96
- _proto.validateFields = function validateFields(nameList) {
97
- return this.parentForm.validateFields(nameList);
98
- };
99
- return SubFormInstance;
100
- }();
@@ -1,26 +0,0 @@
1
- import { FormInstance } from "antd/lib";
2
- import { NamePath, StoreValue } from "antd/es/form/interface";
3
- declare type NamePaths = (string | number)[];
4
- export declare class SubFormInstance implements FormInstance {
5
- parentForm: FormInstance;
6
- namePath: NamePaths;
7
- constructor(form: FormInstance, namePath: NamePaths);
8
- overwritePathName(name: NamePath): any[];
9
- overwriteFields(fields: any[]): any[];
10
- getFieldError(name: NamePath): string[];
11
- getFieldValue(name: NamePath): StoreValue;
12
- getFieldWarning(name: NamePath): string[];
13
- getFieldsError(nameList: NamePath[] | undefined): any[];
14
- getFieldsValue(nameList?: NamePath[] | true, filterFunc?: (meta: any) => boolean): any;
15
- isFieldTouched(name: NamePath): boolean;
16
- isFieldValidating(name: NamePath): boolean;
17
- isFieldsTouched(): boolean;
18
- isFieldsValidating(nameList: NamePath[]): boolean;
19
- resetFields(fields: NamePath[] | undefined): void;
20
- setFieldValue(name: NamePath, value: any): void;
21
- setFields(fields: any[]): void;
22
- setFieldsValue(values: any): void;
23
- submit(): void;
24
- validateFields(nameList: NamePath[] | undefined): Promise<any>;
25
- }
26
- export {};
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- exports.__esModule = true;
5
- exports.SubFormInstance = void 0;
6
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
- var SubFormInstance = exports.SubFormInstance = /*#__PURE__*/function () {
8
- function SubFormInstance(form, namePath) {
9
- this.parentForm = void 0;
10
- this.namePath = void 0;
11
- this.parentForm = form;
12
- this.namePath = namePath;
13
- }
14
- var _proto = SubFormInstance.prototype;
15
- _proto.overwritePathName = function overwritePathName(name) {
16
- if (Array.isArray(name)) {
17
- return [].concat(this.namePath, name);
18
- } else {
19
- return [].concat(this.namePath, [name]);
20
- }
21
- };
22
- _proto.overwriteFields = function overwriteFields(fields) {
23
- var _this = this;
24
- return fields === null || fields === void 0 ? void 0 : fields.map(function (field) {
25
- return (0, _extends2["default"])({}, field, {
26
- name: _this.overwritePathName(field.name)
27
- });
28
- });
29
- };
30
- _proto.getFieldError = function getFieldError(name) {
31
- return this.parentForm.getFieldError(this.overwritePathName(name));
32
- };
33
- _proto.getFieldValue = function getFieldValue(name) {
34
- return this.parentForm.getFieldValue(this.overwritePathName(name));
35
- };
36
- _proto.getFieldWarning = function getFieldWarning(name) {
37
- return this.parentForm.getFieldWarning(this.overwritePathName(name));
38
- }
39
-
40
- // @ts-ignore
41
- ;
42
- _proto.getFieldsError = function getFieldsError(nameList) {
43
- var _this2 = this;
44
- return this.parentForm.getFieldsError(nameList === null || nameList === void 0 ? void 0 : nameList.map(function (name) {
45
- return _this2.overwritePathName(name);
46
- }));
47
- }
48
-
49
- // @ts-ignore
50
- ;
51
- _proto.getFieldsValue = function getFieldsValue(nameList, filterFunc) {
52
- var values = (0, _extends2["default"])({}, this.parentForm.getFieldValue(this.namePath));
53
- values.parent = this.parentForm.getFieldsValue(true);
54
- return values;
55
- };
56
- _proto.isFieldTouched = function isFieldTouched(name) {
57
- return this.parentForm.isFieldTouched(this.overwritePathName(name));
58
- };
59
- _proto.isFieldValidating = function isFieldValidating(name) {
60
- return this.parentForm.isFieldValidating(this.overwritePathName(name));
61
- };
62
- _proto.isFieldsTouched = function isFieldsTouched() {
63
- return this.parentForm.isFieldsTouched();
64
- };
65
- // @ts-ignore
66
- _proto.isFieldsValidating = function isFieldsValidating(nameList) {
67
- var _this3 = this;
68
- return this.parentForm.isFieldsValidating(nameList.map(function (name) {
69
- return _this3.overwritePathName(name);
70
- }));
71
- };
72
- _proto.resetFields = function resetFields(fields) {
73
- if (Array.isArray(fields)) {
74
- // @ts-ignore
75
- this.parentForm.resetFields(this.overwriteFields(fields));
76
- } else {
77
- this.parentForm.resetFields();
78
- }
79
- };
80
- _proto.setFieldValue = function setFieldValue(name, value) {
81
- return this.parentForm.setFieldValue(this.overwritePathName(name), value);
82
- };
83
- _proto.setFields = function setFields(fields) {
84
- this.parentForm.setFields(this.overwriteFields(fields));
85
- };
86
- _proto.setFieldsValue = function setFieldsValue(values) {
87
- var _this4 = this;
88
- if (!values) return;
89
- //删除父值
90
- delete values.parent;
91
- Object.keys(values).forEach(function (name) {
92
- return _this4.parentForm.setFieldValue(_this4.overwritePathName(name), values[name]);
93
- });
94
- };
95
- _proto.submit = function submit() {
96
- this.parentForm.submit();
97
- }
98
-
99
- // @ts-ignore
100
- ;
101
- _proto.validateFields = function validateFields(nameList) {
102
- return this.parentForm.validateFields(nameList);
103
- };
104
- return SubFormInstance;
105
- }();