ronds-metadata 1.1.3 → 1.1.4
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/api/index.d.ts +1 -0
- package/es/api/index.js +32 -1
- package/es/comps/MetadataForm/DataCell/Ref.js +7 -2
- package/es/comps/MetadataForm/DataCell/Select.js +193 -42
- package/es/comps/MetadataForm/hooks/index.js +2 -10
- package/es/comps/MetadataForm/index.js +13 -4
- package/es/comps/MetadataForm/interface.d.ts +2 -0
- package/es/comps/MetadataForm/interface.js +1 -1
- package/es/framework/hooks/use-async-memo.d.ts +3 -0
- package/es/framework/hooks/use-async-memo.js +32 -0
- package/es/framework/metadata/MetadataService.d.ts +2 -0
- package/es/framework/metadata/MetadataService.js +27 -1
- package/es/framework/metadata/types.d.ts +11 -0
- package/package.json +1 -1
package/es/api/index.d.ts
CHANGED
package/es/api/index.js
CHANGED
@@ -6,7 +6,7 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
6
6
|
/*
|
7
7
|
* @Author:wangxian
|
8
8
|
* @Date: 2021-09-18 14:15:04
|
9
|
-
* @LastEditTime: 2022-
|
9
|
+
* @LastEditTime: 2022-05-21 08:37:14
|
10
10
|
*/
|
11
11
|
import { HttpHelper } from '../framework/http';
|
12
12
|
var http = new HttpHelper();
|
@@ -173,6 +173,37 @@ var Api = /*#__PURE__*/function () {
|
|
173
173
|
}
|
174
174
|
|
175
175
|
return GetMetadataObjList;
|
176
|
+
}() // 通过扩展规则获取枚举类型的值
|
177
|
+
|
178
|
+
}, {
|
179
|
+
key: "GetEnumDataByUrl",
|
180
|
+
value: function () {
|
181
|
+
var _GetEnumDataByUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url) {
|
182
|
+
var res;
|
183
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
184
|
+
while (1) {
|
185
|
+
switch (_context5.prev = _context5.next) {
|
186
|
+
case 0:
|
187
|
+
_context5.next = 2;
|
188
|
+
return http.get(encodeURI(url));
|
189
|
+
|
190
|
+
case 2:
|
191
|
+
res = _context5.sent;
|
192
|
+
return _context5.abrupt("return", res.successed ? res.data : []);
|
193
|
+
|
194
|
+
case 4:
|
195
|
+
case "end":
|
196
|
+
return _context5.stop();
|
197
|
+
}
|
198
|
+
}
|
199
|
+
}, _callee5);
|
200
|
+
}));
|
201
|
+
|
202
|
+
function GetEnumDataByUrl(_x6) {
|
203
|
+
return _GetEnumDataByUrl.apply(this, arguments);
|
204
|
+
}
|
205
|
+
|
206
|
+
return GetEnumDataByUrl;
|
176
207
|
}()
|
177
208
|
}]);
|
178
209
|
|
@@ -156,12 +156,17 @@ function Index(props) {
|
|
156
156
|
}, [refId]);
|
157
157
|
|
158
158
|
if (isRefForm && !field && schema.length > 0) {
|
159
|
-
var _fieldRule$, _fieldRule$$value, _fieldRule$2, _fieldRule$2$value;
|
159
|
+
var _fieldRule$, _fieldRule$$value, _fieldRule$2, _fieldRule$2$value, _fieldRule$2$value$co;
|
160
160
|
|
161
161
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
162
162
|
style: {
|
163
163
|
display: 'flex',
|
164
164
|
alignItems: 'center'
|
165
|
+
},
|
166
|
+
onClick: function onClick() {
|
167
|
+
if (formContext.isFoldForm) {
|
168
|
+
setIsFold(!isFold);
|
169
|
+
}
|
165
170
|
}
|
166
171
|
}, /*#__PURE__*/React.createElement("div", {
|
167
172
|
className: "ant-form-item-label",
|
@@ -172,7 +177,7 @@ function Index(props) {
|
|
172
177
|
}
|
173
178
|
}, /*#__PURE__*/React.createElement("label", {
|
174
179
|
className: "".concat((extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.require) && 'ant-form-item-required')
|
175
|
-
}, extraInfo.label || fieldRule && ((_fieldRule$ = fieldRule[0]) === null || _fieldRule$ === void 0 ? void 0 : (_fieldRule$$value = _fieldRule$.value) === null || _fieldRule$$value === void 0 ? void 0 : _fieldRule$$value.label) || fieldRule && ((_fieldRule$2 = fieldRule[0]) === null || _fieldRule$2 === void 0 ? void 0 : (_fieldRule$2$value = _fieldRule$2.value) === null || _fieldRule$2$value === void 0 ? void 0 : _fieldRule$2$value.common.label) || id)), formContext.isFoldForm && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Button, {
|
180
|
+
}, (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.label) || fieldRule && ((_fieldRule$ = fieldRule[0]) === null || _fieldRule$ === void 0 ? void 0 : (_fieldRule$$value = _fieldRule$.value) === null || _fieldRule$$value === void 0 ? void 0 : _fieldRule$$value.label) || fieldRule && ((_fieldRule$2 = fieldRule[0]) === null || _fieldRule$2 === void 0 ? void 0 : (_fieldRule$2$value = _fieldRule$2.value) === null || _fieldRule$2$value === void 0 ? void 0 : (_fieldRule$2$value$co = _fieldRule$2$value.common) === null || _fieldRule$2$value$co === void 0 ? void 0 : _fieldRule$2$value$co.label) || id)), formContext.isFoldForm && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Button, {
|
176
181
|
type: "link",
|
177
182
|
onClick: function onClick() {
|
178
183
|
setIsFold(!isFold);
|
@@ -3,20 +3,28 @@ import _Form from "antd/es/form";
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
4
4
|
import "antd/es/select/style";
|
5
5
|
import _Select from "antd/es/select";
|
6
|
+
import "antd/es/cascader/style";
|
7
|
+
import _Cascader from "antd/es/cascader";
|
6
8
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
9
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
10
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
7
11
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
12
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
8
13
|
|
9
14
|
/*
|
10
15
|
* @Author:wangxian
|
11
16
|
* @Date: 2021-09-18 14:15:04
|
12
|
-
* @LastEditTime: 2022-05-11
|
17
|
+
* @LastEditTime: 2022-05-23 11:14:04
|
13
18
|
*/
|
14
19
|
import React from 'react';
|
15
20
|
import { MetadataFormContext, MetadataRefContext } from '../interface';
|
16
21
|
import { useGetExtraInfo } from '../hooks';
|
22
|
+
import { MetadataService } from '../../../framework/metadata/MetadataService';
|
23
|
+
import { deepClone } from '@/utils';
|
24
|
+
import { useAsyncMemo } from '@/framework/hooks/use-async-memo';
|
17
25
|
|
18
26
|
function Index(props) {
|
19
|
-
var _extraInfo$
|
27
|
+
var _extraInfo$http3, _extraInfo$http4;
|
20
28
|
|
21
29
|
var id = props.id,
|
22
30
|
name = props.name,
|
@@ -25,11 +33,26 @@ function Index(props) {
|
|
25
33
|
initEnumValue = _props$initEnumValue === void 0 ? {} : _props$initEnumValue,
|
26
34
|
disabled = props.disabled,
|
27
35
|
field = props.field,
|
28
|
-
isObj = props.isObj
|
36
|
+
isObj = props.isObj,
|
37
|
+
_props$enum = props.enum,
|
38
|
+
myEnum = _props$enum === void 0 ? [] : _props$enum;
|
29
39
|
var formContext = React.useContext(MetadataFormContext) || {};
|
30
40
|
var formRefContext = React.useContext(MetadataRefContext);
|
31
41
|
var extraInfo = useGetExtraInfo(formRefContext ? formRefContext.fields : formContext.fields, id, formContext.form, props.type);
|
32
42
|
|
43
|
+
var _React$useState = React.useState([{
|
44
|
+
value: 'zhejiang',
|
45
|
+
label: 'Zhejiang',
|
46
|
+
isLeaf: false
|
47
|
+
}, {
|
48
|
+
value: 'jiangsu',
|
49
|
+
label: 'Jiangsu',
|
50
|
+
isLeaf: false
|
51
|
+
}]),
|
52
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
53
|
+
cascaderOption = _React$useState2[0],
|
54
|
+
setCascaderOption = _React$useState2[1];
|
55
|
+
|
33
56
|
var onSelect = function onSelect(value) {
|
34
57
|
formContext.stream$ && formContext.stream$.next({
|
35
58
|
type: 'onSelectChange',
|
@@ -37,18 +60,80 @@ function Index(props) {
|
|
37
60
|
});
|
38
61
|
};
|
39
62
|
|
40
|
-
var
|
63
|
+
var getEnumDataByUrl = React.useCallback( /*#__PURE__*/function () {
|
64
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(http, pid) {
|
65
|
+
var server, _url, res;
|
66
|
+
|
67
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
68
|
+
while (1) {
|
69
|
+
switch (_context.prev = _context.next) {
|
70
|
+
case 0:
|
71
|
+
server = new MetadataService();
|
72
|
+
_url = pid ? http.url.replace('{pid}', pid) : http.url;
|
73
|
+
_context.next = 4;
|
74
|
+
return server.GetEnumDataByUrl(_url);
|
75
|
+
|
76
|
+
case 4:
|
77
|
+
res = _context.sent;
|
78
|
+
|
79
|
+
if (!(res && res.length > 0)) {
|
80
|
+
_context.next = 9;
|
81
|
+
break;
|
82
|
+
}
|
83
|
+
|
84
|
+
return _context.abrupt("return", res.map(function (it) {
|
85
|
+
if (http === null || http === void 0 ? void 0 : http.isCascader) {
|
86
|
+
if (pid === 'child_1') {
|
87
|
+
return {
|
88
|
+
value: it[(http === null || http === void 0 ? void 0 : http.key) || 'id'],
|
89
|
+
label: it[(http === null || http === void 0 ? void 0 : http.value) || 'name'],
|
90
|
+
isLeaf: it['isLeaf'] ? it['isLeaf'] : true
|
91
|
+
};
|
92
|
+
}
|
93
|
+
|
94
|
+
return {
|
95
|
+
value: it[(http === null || http === void 0 ? void 0 : http.key) || 'id'],
|
96
|
+
label: it[(http === null || http === void 0 ? void 0 : http.value) || 'name'],
|
97
|
+
isLeaf: it['isLeaf'] ? it['isLeaf'] : false
|
98
|
+
};
|
99
|
+
} else {
|
100
|
+
return {
|
101
|
+
value: it[(http === null || http === void 0 ? void 0 : http.key) || 'id'],
|
102
|
+
label: it[(http === null || http === void 0 ? void 0 : http.value) || 'name']
|
103
|
+
};
|
104
|
+
}
|
105
|
+
}));
|
106
|
+
|
107
|
+
case 9:
|
108
|
+
console.warn("".concat(_url, " is not return success result"));
|
109
|
+
return _context.abrupt("return", []);
|
110
|
+
|
111
|
+
case 11:
|
112
|
+
case "end":
|
113
|
+
return _context.stop();
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}, _callee);
|
117
|
+
}));
|
118
|
+
|
119
|
+
return function (_x, _x2) {
|
120
|
+
return _ref.apply(this, arguments);
|
121
|
+
};
|
122
|
+
}(), []);
|
123
|
+
|
124
|
+
var processSelectOptionsData = function processSelectOptionsData() {
|
41
125
|
var _options = [];
|
42
126
|
|
43
|
-
var _enum =
|
127
|
+
var _enum = deepClone(myEnum || []); // 扩展规则的value
|
128
|
+
|
44
129
|
|
45
130
|
if (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.value) {
|
46
|
-
_enum = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.value;
|
131
|
+
_enum = deepClone(extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.value);
|
47
132
|
} // 目前是更具那么的id判断的,暂未考虑重名问题
|
48
133
|
|
49
134
|
|
50
135
|
if (initEnumValue[id]) {
|
51
|
-
_enum = initEnumValue[id];
|
136
|
+
_enum = deepClone(initEnumValue[id]);
|
52
137
|
}
|
53
138
|
|
54
139
|
_enum.forEach(function (it) {
|
@@ -61,10 +146,106 @@ function Index(props) {
|
|
61
146
|
});
|
62
147
|
|
63
148
|
return _options;
|
64
|
-
}
|
149
|
+
};
|
150
|
+
|
151
|
+
var options = React.useMemo(function () {
|
152
|
+
return processSelectOptionsData();
|
153
|
+
}, [initEnumValue, myEnum, id]);
|
154
|
+
var httpOptions = useAsyncMemo( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
155
|
+
var _extraInfo$http, res;
|
156
|
+
|
157
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
158
|
+
while (1) {
|
159
|
+
switch (_context2.prev = _context2.next) {
|
160
|
+
case 0:
|
161
|
+
if (!((extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.http) && (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.http.url))) {
|
162
|
+
_context2.next = 6;
|
163
|
+
break;
|
164
|
+
}
|
165
|
+
|
166
|
+
_context2.next = 3;
|
167
|
+
return getEnumDataByUrl(deepClone(extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.http));
|
168
|
+
|
169
|
+
case 3:
|
170
|
+
res = _context2.sent;
|
171
|
+
|
172
|
+
if (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http = extraInfo.http) === null || _extraInfo$http === void 0 ? void 0 : _extraInfo$http.isCascader) {
|
173
|
+
setCascaderOption(_toConsumableArray(res));
|
174
|
+
}
|
175
|
+
|
176
|
+
return _context2.abrupt("return", res);
|
177
|
+
|
178
|
+
case 6:
|
179
|
+
return _context2.abrupt("return", []);
|
180
|
+
|
181
|
+
case 7:
|
182
|
+
case "end":
|
183
|
+
return _context2.stop();
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}, _callee2);
|
187
|
+
})), [extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.http]);
|
188
|
+
|
189
|
+
var loadData = /*#__PURE__*/function () {
|
190
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(selectedOptions) {
|
191
|
+
var targetOption, _children;
|
192
|
+
|
193
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
194
|
+
while (1) {
|
195
|
+
switch (_context3.prev = _context3.next) {
|
196
|
+
case 0:
|
197
|
+
targetOption = selectedOptions[selectedOptions.length - 1];
|
198
|
+
targetOption.loading = true;
|
199
|
+
_context3.next = 4;
|
200
|
+
return getEnumDataByUrl(extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.http, targetOption.value);
|
201
|
+
|
202
|
+
case 4:
|
203
|
+
_children = _context3.sent;
|
204
|
+
setTimeout(function () {
|
205
|
+
targetOption.loading = false;
|
206
|
+
targetOption.children = _children;
|
207
|
+
setCascaderOption(_toConsumableArray(cascaderOption));
|
208
|
+
}, 500);
|
209
|
+
|
210
|
+
case 6:
|
211
|
+
case "end":
|
212
|
+
return _context3.stop();
|
213
|
+
}
|
214
|
+
}
|
215
|
+
}, _callee3);
|
216
|
+
}));
|
217
|
+
|
218
|
+
return function loadData(_x3) {
|
219
|
+
return _ref3.apply(this, arguments);
|
220
|
+
};
|
221
|
+
}();
|
222
|
+
|
223
|
+
var processSelectType = function processSelectType(b) {
|
224
|
+
if (b) {
|
225
|
+
return /*#__PURE__*/React.createElement(_Cascader, {
|
226
|
+
multiple: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.isMutiple,
|
227
|
+
options: cascaderOption,
|
228
|
+
loadData: loadData
|
229
|
+
});
|
230
|
+
} else {
|
231
|
+
var _extraInfo$disabled;
|
232
|
+
|
233
|
+
return /*#__PURE__*/React.createElement(_Select, {
|
234
|
+
mode: (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.isMutiple) ? 'multiple' : extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.mode,
|
235
|
+
onSelect: onSelect,
|
236
|
+
disabled: (_extraInfo$disabled = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.disabled) !== null && _extraInfo$disabled !== void 0 ? _extraInfo$disabled : disabled,
|
237
|
+
placeholder: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.placeholder,
|
238
|
+
options: httpOptions || options,
|
239
|
+
getPopupContainer: function getPopupContainer(triggerNode) {
|
240
|
+
return triggerNode.parentNode;
|
241
|
+
},
|
242
|
+
allowClear: true
|
243
|
+
});
|
244
|
+
}
|
245
|
+
};
|
65
246
|
|
66
247
|
if (isObj && isRefForm && field) {
|
67
|
-
var _extraInfo$
|
248
|
+
var _extraInfo$http2;
|
68
249
|
|
69
250
|
return /*#__PURE__*/React.createElement(_Form.Item, _extends({}, field, {
|
70
251
|
style: {
|
@@ -79,17 +260,7 @@ function Index(props) {
|
|
79
260
|
}],
|
80
261
|
help: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.help,
|
81
262
|
tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
|
82
|
-
}),
|
83
|
-
mode: (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.isMutiple) ? 'multiple' : extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.mode,
|
84
|
-
onSelect: onSelect,
|
85
|
-
disabled: (_extraInfo$disabled = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.disabled) !== null && _extraInfo$disabled !== void 0 ? _extraInfo$disabled : disabled,
|
86
|
-
placeholder: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.placeholder,
|
87
|
-
options: options,
|
88
|
-
getPopupContainer: function getPopupContainer(triggerNode) {
|
89
|
-
return triggerNode.parentNode;
|
90
|
-
},
|
91
|
-
allowClear: true
|
92
|
-
}));
|
263
|
+
}), processSelectType((_extraInfo$http2 = extraInfo.http) === null || _extraInfo$http2 === void 0 ? void 0 : _extraInfo$http2.isCascader));
|
93
264
|
}
|
94
265
|
|
95
266
|
return !field ? /*#__PURE__*/React.createElement(_Form.Item, {
|
@@ -105,17 +276,7 @@ function Index(props) {
|
|
105
276
|
}],
|
106
277
|
help: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.help,
|
107
278
|
tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
|
108
|
-
}, /*#__PURE__*/React.createElement(
|
109
|
-
mode: (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.isMutiple) ? 'multiple' : extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.mode,
|
110
|
-
onSelect: onSelect,
|
111
|
-
disabled: (_extraInfo$disabled2 = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.disabled) !== null && _extraInfo$disabled2 !== void 0 ? _extraInfo$disabled2 : disabled,
|
112
|
-
placeholder: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.placeholder,
|
113
|
-
options: options,
|
114
|
-
getPopupContainer: function getPopupContainer(triggerNode) {
|
115
|
-
return triggerNode.parentNode;
|
116
|
-
},
|
117
|
-
allowClear: true
|
118
|
-
})) : /*#__PURE__*/React.createElement(_Form.Item, _extends({}, field, {
|
279
|
+
}, processSelectType((_extraInfo$http3 = extraInfo.http) === null || _extraInfo$http3 === void 0 ? void 0 : _extraInfo$http3.isCascader)) : /*#__PURE__*/React.createElement(_Form.Item, _extends({}, field, {
|
119
280
|
style: {
|
120
281
|
flex: 1,
|
121
282
|
paddingRight: '10px'
|
@@ -127,17 +288,7 @@ function Index(props) {
|
|
127
288
|
}],
|
128
289
|
help: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.help,
|
129
290
|
tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
|
130
|
-
}),
|
131
|
-
mode: (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.isMutiple) ? 'multiple' : extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.mode,
|
132
|
-
onSelect: onSelect,
|
133
|
-
disabled: (_extraInfo$disabled3 = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.disabled) !== null && _extraInfo$disabled3 !== void 0 ? _extraInfo$disabled3 : disabled,
|
134
|
-
placeholder: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.placeholder,
|
135
|
-
options: options,
|
136
|
-
getPopupContainer: function getPopupContainer(triggerNode) {
|
137
|
-
return triggerNode.parentNode;
|
138
|
-
},
|
139
|
-
allowClear: true
|
140
|
-
}));
|
291
|
+
}), processSelectType((_extraInfo$http4 = extraInfo.http) === null || _extraInfo$http4 === void 0 ? void 0 : _extraInfo$http4.isCascader));
|
141
292
|
}
|
142
293
|
|
143
294
|
export default /*#__PURE__*/React.memo(Index);
|
@@ -5,7 +5,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
5
|
/*
|
6
6
|
* @Author: your name
|
7
7
|
* @Date: 2021-09-18 14:15:04
|
8
|
-
* @LastEditTime: 2022-05-
|
8
|
+
* @LastEditTime: 2022-05-21 08:51:08
|
9
9
|
* @LastEditors: Please set LastEditors
|
10
10
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
11
11
|
* @FilePath: \ronds.metadata\src\comps\MetadataForm\hooks\index.tsx
|
@@ -28,10 +28,6 @@ export var useGetExtraInfo = function useGetExtraInfo(fields, id, form, type) {
|
|
28
28
|
if (fields) {
|
29
29
|
var extraInfo = fields.get(id);
|
30
30
|
|
31
|
-
if (id === 'kafkaSource') {
|
32
|
-
debugger;
|
33
|
-
}
|
34
|
-
|
35
31
|
if (extraInfo) {
|
36
32
|
// 将map转化为对象
|
37
33
|
var _extraInfo = {};
|
@@ -54,11 +50,7 @@ export var useGetExtraInfo = function useGetExtraInfo(fields, id, form, type) {
|
|
54
50
|
// 时间格式转化
|
55
51
|
if (_extraInfo.type === 'datePicker' && form.getFieldValue(id)) {
|
56
52
|
form.setFieldsValue(_defineProperty({}, id, moment(form.getFieldValue(id), 'YYYY-MM-DD HH:mm:ss')));
|
57
|
-
}
|
58
|
-
// if (_extraInfo?.defaultValue) {
|
59
|
-
// form.setFieldsValue({ [id]: _extraInfo?.defaultValue });
|
60
|
-
// }
|
61
|
-
|
53
|
+
}
|
62
54
|
|
63
55
|
setExtra(_objectSpread({}, _extraInfo));
|
64
56
|
}
|
@@ -39,10 +39,15 @@ var MetadataForm = function MetadataForm(props) {
|
|
39
39
|
mySchma = _React$useState2[0],
|
40
40
|
setMySchema = _React$useState2[1];
|
41
41
|
|
42
|
-
var _React$useState3 = React.useState(),
|
42
|
+
var _React$useState3 = React.useState([]),
|
43
43
|
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
44
|
-
|
45
|
-
|
44
|
+
innerSchemas = _React$useState4[0],
|
45
|
+
setInnerSchemas = _React$useState4[1];
|
46
|
+
|
47
|
+
var _React$useState5 = React.useState(),
|
48
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
49
|
+
fields = _React$useState6[0],
|
50
|
+
setFields = _React$useState6[1];
|
46
51
|
|
47
52
|
var firstLoadRef = React.useRef(true);
|
48
53
|
var firstLoadForm = React.useRef(true);
|
@@ -99,12 +104,15 @@ var MetadataForm = function MetadataForm(props) {
|
|
99
104
|
}, [refId]);
|
100
105
|
React.useEffect(function () {
|
101
106
|
if (mySchma && mySchma.length > 0) {
|
107
|
+
var _mySchma$;
|
108
|
+
|
102
109
|
var provider = new JsonMetadataProvider();
|
103
110
|
provider.add_types(mySchma);
|
104
111
|
var FormCls = provider.get_type(mySchma[0].id);
|
105
112
|
var formCls = new FormCls();
|
106
113
|
var _fields = formCls.__type__.__fields__;
|
107
114
|
setFields(_fields);
|
115
|
+
setInnerSchemas(((_mySchma$ = mySchma[0]) === null || _mySchma$ === void 0 ? void 0 : _mySchma$.types) || []);
|
108
116
|
return function () {
|
109
117
|
provider = null;
|
110
118
|
};
|
@@ -127,7 +135,8 @@ var MetadataForm = function MetadataForm(props) {
|
|
127
135
|
stream$: stream$,
|
128
136
|
initialValues: initialValues,
|
129
137
|
isShowTypeInfo: isShowTypeInfo,
|
130
|
-
isFoldForm: isFoldForm
|
138
|
+
isFoldForm: isFoldForm,
|
139
|
+
__TYPE__: innerSchemas
|
131
140
|
}
|
132
141
|
}, /*#__PURE__*/React.createElement(_Form, {
|
133
142
|
className: "metadata-form",
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { FormInstance } from 'antd/lib/form/hooks/useForm';
|
3
|
+
import { IMetaData } from '../../framework/metadata/types';
|
3
4
|
export interface IMetadataFormContextProps {
|
4
5
|
fields: any;
|
5
6
|
form: FormInstance;
|
@@ -7,6 +8,7 @@ export interface IMetadataFormContextProps {
|
|
7
8
|
initialValues: any;
|
8
9
|
isShowTypeInfo: boolean;
|
9
10
|
isFoldForm: boolean;
|
11
|
+
__TYPE__: IMetaData[];
|
10
12
|
}
|
11
13
|
export declare const MetadataFormContext: React.Context<IMetadataFormContextProps>;
|
12
14
|
export interface IMetadataRefContextProps {
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { DependencyList } from 'react';
|
2
|
+
export declare function useAsyncMemo<T>(factory: () => Promise<T> | undefined | null, deps: DependencyList): T | undefined;
|
3
|
+
export declare function useAsyncMemo<T>(factory: () => Promise<T> | undefined | null, deps: DependencyList, initial: T): T;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
+
|
3
|
+
/*
|
4
|
+
* @Author: wangxian
|
5
|
+
* @Date: 2022-05-21 11:04:53
|
6
|
+
* @LastEditTime: 2022-05-21 11:07:34
|
7
|
+
*/
|
8
|
+
import { useEffect, useState } from 'react';
|
9
|
+
export function useAsyncMemo(factory, deps, initial) {
|
10
|
+
var _useState = useState(initial),
|
11
|
+
_useState2 = _slicedToArray(_useState, 2),
|
12
|
+
val = _useState2[0],
|
13
|
+
setVal = _useState2[1];
|
14
|
+
|
15
|
+
useEffect(function () {
|
16
|
+
var cancel = false;
|
17
|
+
var promise = factory();
|
18
|
+
|
19
|
+
if (promise) {
|
20
|
+
promise.then(function (val) {
|
21
|
+
if (!cancel) {
|
22
|
+
setVal(val);
|
23
|
+
}
|
24
|
+
});
|
25
|
+
}
|
26
|
+
|
27
|
+
return function () {
|
28
|
+
cancel = true;
|
29
|
+
};
|
30
|
+
}, deps);
|
31
|
+
return val;
|
32
|
+
}
|
@@ -6,7 +6,7 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
6
6
|
/*
|
7
7
|
* @Author: wangxian
|
8
8
|
* @Date: 2021-09-18 14:15:04
|
9
|
-
* @LastEditTime: 2022-
|
9
|
+
* @LastEditTime: 2022-05-21 08:35:21
|
10
10
|
*/
|
11
11
|
import Api from '../../api';
|
12
12
|
var globalAPI = new Api();
|
@@ -132,6 +132,32 @@ export var MetadataService = /*#__PURE__*/function () {
|
|
132
132
|
|
133
133
|
return GetMetadataObjList;
|
134
134
|
}()
|
135
|
+
/** 通过扩展规则获取枚举类型的值 */
|
136
|
+
|
137
|
+
}, {
|
138
|
+
key: "GetEnumDataByUrl",
|
139
|
+
value: function () {
|
140
|
+
var _GetEnumDataByUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url) {
|
141
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
142
|
+
while (1) {
|
143
|
+
switch (_context5.prev = _context5.next) {
|
144
|
+
case 0:
|
145
|
+
return _context5.abrupt("return", this.api.GetEnumDataByUrl(url));
|
146
|
+
|
147
|
+
case 1:
|
148
|
+
case "end":
|
149
|
+
return _context5.stop();
|
150
|
+
}
|
151
|
+
}
|
152
|
+
}, _callee5, this);
|
153
|
+
}));
|
154
|
+
|
155
|
+
function GetEnumDataByUrl(_x6) {
|
156
|
+
return _GetEnumDataByUrl.apply(this, arguments);
|
157
|
+
}
|
158
|
+
|
159
|
+
return GetEnumDataByUrl;
|
160
|
+
}()
|
135
161
|
}]);
|
136
162
|
|
137
163
|
return MetadataService;
|
@@ -1,3 +1,8 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: wangxian
|
3
|
+
* @Date: 2021-09-18 14:15:04
|
4
|
+
* @LastEditTime: 2022-05-23 12:00:58
|
5
|
+
*/
|
1
6
|
export type IMetaType = 'object' | 'ref' | 'bool' | 'number' | 'text' | 'enum' | 'array' | string;
|
2
7
|
|
3
8
|
export type IMetaData = {
|
@@ -22,6 +27,10 @@ export type IMetaData = {
|
|
22
27
|
* 静态的变量
|
23
28
|
*/
|
24
29
|
fields?: IMetaFileds[];
|
30
|
+
/**
|
31
|
+
* 内部类
|
32
|
+
*/
|
33
|
+
types?: IMetaData[];
|
25
34
|
};
|
26
35
|
|
27
36
|
export type IMetaProperties = {
|
@@ -84,4 +93,6 @@ export interface IAPI {
|
|
84
93
|
SaveMetadata(data: any, metadataTag: string): Promise<any>;
|
85
94
|
// 获取元数据的值
|
86
95
|
GetMetadataObjList(data: any): Promise<any[]>;
|
96
|
+
/** 通过扩展规则获取枚举类型的值 */
|
97
|
+
GetEnumDataByUrl(url: string): Promise<any[]>;
|
87
98
|
}
|