@teamix/pro 1.3.14 → 1.3.17

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.
Files changed (53) hide show
  1. package/dist/pro.css +1 -1
  2. package/dist/pro.js +22026 -9580
  3. package/dist/pro.min.css +1 -1
  4. package/dist/pro.min.js +1 -1
  5. package/es/actions/index.scss +13 -0
  6. package/es/form/Filter/index.js +169 -53
  7. package/es/form/Filter/layout.scss +4 -0
  8. package/es/form/Filter/useBindUrl.d.ts +2 -0
  9. package/es/form/Filter/useBindUrl.js +118 -0
  10. package/es/form/ProForm/index.js +5 -3
  11. package/es/form/ProForm/useFieldSchema.js +53 -32
  12. package/es/form/SchemaForm/initializeDataSource.d.ts +1 -2
  13. package/es/form/SchemaForm/initializeDataSource.js +14 -19
  14. package/es/form/SchemaForm/initializeRequest.js +25 -26
  15. package/es/form/SchemaForm/initializeRules.d.ts +2 -2
  16. package/es/form/SchemaForm/initializeRules.js +30 -23
  17. package/es/form/SchemaForm/reactions.d.ts +4 -4
  18. package/es/form/SchemaForm/reactions.js +30 -23
  19. package/es/form/typing.d.ts +12 -5
  20. package/es/form/utils.d.ts +16 -1
  21. package/es/form/utils.js +21 -2
  22. package/es/global.scss +45 -0
  23. package/es/index.d.ts +2 -1
  24. package/es/index.js +3 -2
  25. package/es/page-header/index.d.ts +2 -0
  26. package/es/page-header/index.js +13 -3
  27. package/es/page-header/index.scss +8 -0
  28. package/es/table/components/Layout/index.scss +5 -5
  29. package/lib/actions/index.scss +13 -0
  30. package/lib/form/Filter/index.js +170 -53
  31. package/lib/form/Filter/layout.scss +4 -0
  32. package/lib/form/Filter/useBindUrl.d.ts +2 -0
  33. package/lib/form/Filter/useBindUrl.js +129 -0
  34. package/lib/form/ProForm/index.js +5 -3
  35. package/lib/form/ProForm/useFieldSchema.js +52 -31
  36. package/lib/form/SchemaForm/initializeDataSource.d.ts +1 -2
  37. package/lib/form/SchemaForm/initializeDataSource.js +14 -19
  38. package/lib/form/SchemaForm/initializeRequest.js +26 -26
  39. package/lib/form/SchemaForm/initializeRules.d.ts +2 -2
  40. package/lib/form/SchemaForm/initializeRules.js +30 -22
  41. package/lib/form/SchemaForm/reactions.d.ts +4 -4
  42. package/lib/form/SchemaForm/reactions.js +30 -23
  43. package/lib/form/typing.d.ts +12 -5
  44. package/lib/form/utils.d.ts +16 -1
  45. package/lib/form/utils.js +23 -2
  46. package/lib/global.scss +45 -0
  47. package/lib/index.d.ts +2 -1
  48. package/lib/index.js +3 -1
  49. package/lib/page-header/index.d.ts +2 -0
  50. package/lib/page-header/index.js +12 -2
  51. package/lib/page-header/index.scss +8 -0
  52. package/lib/table/components/Layout/index.scss +5 -5
  53. package/package.json +1 -1
@@ -135,7 +135,7 @@ var ProForm = /*#__PURE__*/(0, _react.memo)(function (_ref) {
135
135
 
136
136
  var mergedComponents = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, globalComponents), components), formilyComponents), _ProField.default);
137
137
 
138
- var onAutoSubmit = (0, _useAutoSubmit.default)(onSubmit); // todo 需要formily支持断点下的属性更新
138
+ var onAutoSubmit = (0, _useAutoSubmit.default)(onSubmit, context); // todo 需要formily支持断点下的属性更新
139
139
 
140
140
  var getTeamixLayout = (0, _react.useMemo)(function () {
141
141
  return breakpoints ? {
@@ -160,7 +160,7 @@ var ProForm = /*#__PURE__*/(0, _react.memo)(function (_ref) {
160
160
  if (initialValues) {
161
161
  form.setInitialValues(initialValues);
162
162
  } else if (initialRequest) {
163
- (0, _useInitialRequest.default)(initialRequest).then(function (values) {
163
+ (0, _useInitialRequest.default)(initialRequest, context).then(function (values) {
164
164
  form.setInitialValues(values);
165
165
  }).finally(function () {
166
166
  onInitialComplete === null || onInitialComplete === void 0 ? void 0 : onInitialComplete(form);
@@ -205,10 +205,12 @@ var ProForm = /*#__PURE__*/(0, _react.memo)(function (_ref) {
205
205
  }) : null, otherProps === null || otherProps === void 0 ? void 0 : otherProps.children);
206
206
  });
207
207
 
208
- ProForm.Field = function () {
208
+ var Field = function Field() {
209
209
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
210
210
  };
211
211
 
212
+ Field.displayName = 'ProFormField';
213
+ ProForm.Field = Field;
212
214
  ProForm.defaultProps = {
213
215
  colon: false,
214
216
  labelAlign: 'left',
@@ -28,45 +28,70 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
28
28
  * @returns schema 配置
29
29
  */
30
30
  var getMergedSchema = function getMergedSchema(field, extra, wholeExtra) {
31
- return field.reduce(function (prev, curr, index) {
31
+ return [].concat(field).reduce(function (prev, curr, index) {
32
+ var _curr$type;
33
+
32
34
  var _ref = curr.props || {},
33
35
  id = _ref.id,
34
36
  _ref$children = _ref.children,
35
37
  children = _ref$children === void 0 ? [] : _ref$children,
36
38
  _ref$reactions = _ref.reactions,
37
39
  reactions = _ref$reactions === void 0 ? [] : _ref$reactions,
38
- rest = _objectWithoutProperties(_ref, _excluded); // 获取字段额外的 schema 配置(From ProForm)
40
+ rest = _objectWithoutProperties(_ref, _excluded);
39
41
 
42
+ var displayName = curr === null || curr === void 0 ? void 0 : (_curr$type = curr.type) === null || _curr$type === void 0 ? void 0 : _curr$type.displayName; // 自定义组件
40
43
 
41
- var extraFieldProps = extra[index] || {};
44
+ var type = curr === null || curr === void 0 ? void 0 : curr.type; // 基本Dom元素
42
45
 
43
- if (id !== extraFieldProps.id) {
44
- // 索引不匹配,通过 id 查找获取
45
- extraFieldProps = (0, _utils.getValueByValue)(extra, id, {
46
- inputKey: 'id',
47
- outputKey: '__whole__'
48
- }) || (0, _utils.getValueByValue)(wholeExtra, id, {
49
- inputKey: 'id',
50
- outputKey: '__whole__'
51
- });
46
+ if (displayName === 'ProFormField') {
47
+ // 获取字段额外的 schema 配置(From ProForm)
48
+ var extraFieldProps = extra[index] || {};
52
49
 
53
- if (extraFieldProps) {
54
- console.warn("Field id \"".concat(id, "\" is not found by index in ProForm schema props, Please pay attention to the order."));
50
+ if (id !== extraFieldProps.id) {
51
+ // 索引不匹配,通过 id 查找获取
52
+ extraFieldProps = (0, _utils.getValueByValue)(extra, id, {
53
+ inputKey: 'id',
54
+ outputKey: '__whole__'
55
+ }) || (0, _utils.getValueByValue)(wholeExtra, id, {
56
+ inputKey: 'id',
57
+ outputKey: '__whole__'
58
+ });
59
+
60
+ if (extraFieldProps) {
61
+ console.warn("Field id \"".concat(id, "\" is not found by index in ProForm schema props, Please pay attention to the order."));
62
+ }
55
63
  }
64
+
65
+ var _ref2 = extraFieldProps || {},
66
+ extraId = _ref2.id,
67
+ _ref2$children = _ref2.children,
68
+ extraChildren = _ref2$children === void 0 ? [] : _ref2$children,
69
+ _ref2$reactions = _ref2.reactions,
70
+ extraReactions = _ref2$reactions === void 0 ? [] : _ref2$reactions,
71
+ extraRest = _objectWithoutProperties(_ref2, _excluded2);
72
+
73
+ var mergedReactions = [].concat(reactions, extraReactions);
74
+ var mergedChildren = children ? getMergedSchema(children, extraChildren, wholeExtra) : [];
75
+ prev.push(_objectSpread(_objectSpread(_objectSpread({}, (0, _utils.deepMerge)(rest, extraRest)), mergedReactions.length && {
76
+ reactions: mergedReactions
77
+ }), mergedChildren.length && {
78
+ children: mergedChildren
79
+ }));
80
+ } else if ((0, _utils.isStr)(type)) {
81
+ prev.push({
82
+ component: type,
83
+ props: curr.props
84
+ });
85
+ } else if ((0, _utils.isStr)(displayName)) {
86
+ prev.push({
87
+ decorator: displayName,
88
+ decoratorProps: _objectSpread({
89
+ id: id
90
+ }, rest),
91
+ children: children ? getMergedSchema(children, [], wholeExtra) : []
92
+ });
56
93
  }
57
94
 
58
- var _ref2 = extraFieldProps || {},
59
- extraId = _ref2.id,
60
- _ref2$children = _ref2.children,
61
- extraChildren = _ref2$children === void 0 ? [] : _ref2$children,
62
- _ref2$reactions = _ref2.reactions,
63
- extraReactions = _ref2$reactions === void 0 ? [] : _ref2$reactions,
64
- extraRest = _objectWithoutProperties(_ref2, _excluded2);
65
-
66
- prev.push(_objectSpread(_objectSpread({}, (0, _utils.deepMerge)(rest, extraRest)), {}, {
67
- reactions: [].concat(reactions, extraReactions),
68
- children: (children === null || children === void 0 ? void 0 : children.length) ? getMergedSchema(children, extraChildren, wholeExtra) : []
69
- }));
70
95
  return prev;
71
96
  }, []);
72
97
  };
@@ -80,11 +105,7 @@ var getMergedSchema = function getMergedSchema(field, extra, wholeExtra) {
80
105
  var _default = function _default(_ref3) {
81
106
  var children = _ref3.children,
82
107
  schema = _ref3.schema;
83
- var field = [].concat(children !== null && children !== void 0 ? children : []).filter(function (item) {
84
- var _item$type, _item$props;
85
-
86
- return (item === null || item === void 0 ? void 0 : (_item$type = item.type) === null || _item$type === void 0 ? void 0 : _item$type.name) === '' && (item === null || item === void 0 ? void 0 : (_item$props = item.props) === null || _item$props === void 0 ? void 0 : _item$props.component);
87
- }); // 如果 ProForm 的 children 含有 Field 字段,则优先使用 Field 渲染表单(仅合并 ProForm 的 schema 属性 )
108
+ var field = [].concat(children !== null && children !== void 0 ? children : []); // 如果 ProForm 的 children 含有 Field 字段,则优先使用 Field 渲染表单(仅合并 ProForm 的 schema 属性 )
88
109
 
89
110
  if (field.length) {
90
111
  return getMergedSchema(field, schema !== null && schema !== void 0 ? schema : [], schema !== null && schema !== void 0 ? schema : []);
@@ -1,6 +1,5 @@
1
- import type { ProFormRequestConfig } from '../typing';
2
1
  interface IInitializeDataSource {
3
- (requestConfig?: ProFormRequestConfig | any, suffix?: string): {
2
+ (requestConfig: any, suffix: string): {
4
3
  dataSource?: any[];
5
4
  reactions: any[];
6
5
  scope: {
@@ -5,30 +5,25 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _utils = require("@teamix/utils");
9
-
10
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+ var _utils = require("../utils");
11
9
 
12
10
  var initializeDataSource = function initializeDataSource(dataSource, suffix) {
13
- if ((0, _utils.isPlainObj)(dataSource)) {
14
- var _requestConfig$extraC;
11
+ var _dataSource$extraConf;
15
12
 
16
- var requestConfig = dataSource;
17
- var requestConfigName = "$requestConfig_".concat(suffix);
18
- return {
19
- reactions: ["{{$dataSource($request,".concat(requestConfigName, ",context)}}")],
20
- scope: _defineProperty({}, requestConfigName, requestConfig),
21
- // dataSource请求时,默认配置字段为只读
22
- data: {
23
- readOnlyOnLoading: (requestConfig === null || requestConfig === void 0 ? void 0 : (_requestConfig$extraC = requestConfig.extraConfig) === null || _requestConfig$extraC === void 0 ? void 0 : _requestConfig$extraC.readOnly) !== false
24
- }
25
- };
26
- }
13
+ var _initializeRequestExp = (0, _utils.initializeRequestExpression)(dataSource, '$dataSource', suffix),
14
+ expression = _initializeRequestExp.expression,
15
+ scope = _initializeRequestExp.scope;
27
16
 
28
- return {
29
- dataSource: dataSource,
17
+ return expression ? {
18
+ reactions: [expression],
19
+ scope: scope,
20
+ data: {
21
+ readOnlyOnLoading: (dataSource === null || dataSource === void 0 ? void 0 : (_dataSource$extraConf = dataSource.extraConfig) === null || _dataSource$extraConf === void 0 ? void 0 : _dataSource$extraConf.readOnly) !== false
22
+ }
23
+ } : {
30
24
  reactions: [],
31
- scope: {}
25
+ scope: {},
26
+ dataSource: dataSource
32
27
  };
33
28
  };
34
29
 
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _utils = require("@teamix/utils");
9
9
 
10
+ var _utils2 = require("../utils");
11
+
10
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
13
 
12
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -25,37 +27,35 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
25
27
 
26
28
  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; }
27
29
 
28
- var initializeRequest = function initializeRequest(requestConfig, suffix) {
29
- if (requestConfig) {
30
- if ((0, _utils.isArr)(requestConfig)) {
31
- var reactionsMap = [];
32
- var scopeMap = {};
33
- requestConfig.forEach(function (item, index) {
34
- var _initializeRequest = initializeRequest(item, "".concat(suffix).concat(index)),
35
- reactions = _initializeRequest.reactions,
36
- scope = _initializeRequest.scope;
37
-
38
- reactionsMap = [].concat(_toConsumableArray(reactionsMap), _toConsumableArray(reactions));
39
- scopeMap = _objectSpread(_objectSpread({}, scopeMap), scope);
40
- });
41
- return {
42
- reactions: reactionsMap,
43
- scope: scopeMap
44
- };
45
- } else {
46
- var requestConfigName = "$requestConfig_".concat(suffix);
47
- return {
48
- reactions: ["{{$common($request,".concat(requestConfigName, ",context)}}")],
49
- scope: _defineProperty({}, requestConfigName, requestConfig)
50
- };
51
- }
52
- }
30
+ var initializeItem = function initializeItem(request, suffix) {
31
+ var _initializeRequestExp = (0, _utils2.initializeRequestExpression)(request, '$common', suffix),
32
+ expression = _initializeRequestExp.expression,
33
+ scope = _initializeRequestExp.scope;
53
34
 
54
- return {
35
+ return expression ? {
36
+ reactions: [expression],
37
+ scope: scope
38
+ } : {
55
39
  reactions: [],
56
40
  scope: {}
57
41
  };
58
42
  };
59
43
 
44
+ var initializeRequest = function initializeRequest(request, suffix) {
45
+ if ((0, _utils.isArr)(request)) {
46
+ return request.reduce(function (prev, current, index) {
47
+ var result = initializeItem(current, "".concat(suffix, "_").concat(index));
48
+ prev.reactions = [].concat(_toConsumableArray(prev.reactions), _toConsumableArray(result.reactions));
49
+ prev.scope = _objectSpread(_objectSpread({}, prev.scope), result.scope);
50
+ return prev;
51
+ }, {
52
+ reactions: [],
53
+ scope: {}
54
+ });
55
+ }
56
+
57
+ return initializeItem(request, suffix);
58
+ };
59
+
60
60
  var _default = initializeRequest;
61
61
  exports.default = _default;
@@ -1,7 +1,7 @@
1
1
  interface IInitializeRules {
2
- (rules?: any, suffix?: string): {
2
+ (rules: any, suffix: string): {
3
3
  rules?: any;
4
- reactions: any[];
4
+ reactions?: any[];
5
5
  scope: {
6
6
  [x: string]: any;
7
7
  };
@@ -7,6 +7,10 @@ exports.default = void 0;
7
7
 
8
8
  var _utils = require("@teamix/utils");
9
9
 
10
+ var _utils2 = require("../utils");
11
+
12
+ var _excluded = ["validator"];
13
+
10
14
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
15
 
12
16
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -25,30 +29,34 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
25
29
 
26
30
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
31
 
28
- var initializeRules = function initializeRules(rules, suffix) {
29
- var initializeValidator = function initializeValidator(rule) {
30
- var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
31
-
32
- if ((0, _utils.isPlainObj)(rule === null || rule === void 0 ? void 0 : rule.validator)) {
33
- var requestConfig = rule.validator;
34
- var requestConfigName = "$requestConfig_".concat(suffix).concat(index);
35
- return {
36
- rules: _objectSpread(_objectSpread({}, rule), {}, {
37
- validator: "{{$validator($request,".concat(requestConfigName, ",context)}}")
38
- }),
39
- scope: _defineProperty({}, requestConfigName, requestConfig)
40
- };
41
- }
42
-
43
- return {
44
- rules: rule,
45
- scope: {}
46
- };
32
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
33
+
34
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
35
+
36
+ var initializeRule = function initializeRule(rule, suffix) {
37
+ var _ref = rule || {},
38
+ validator = _ref.validator,
39
+ rest = _objectWithoutProperties(_ref, _excluded);
40
+
41
+ var _initializeRequestExp = (0, _utils2.initializeRequestExpression)(validator, '$validator', suffix),
42
+ expression = _initializeRequestExp.expression,
43
+ scope = _initializeRequestExp.scope;
44
+
45
+ return expression ? {
46
+ scope: scope,
47
+ rules: _objectSpread({
48
+ validator: expression
49
+ }, rest)
50
+ } : {
51
+ scope: {},
52
+ rules: rule
47
53
  };
54
+ };
48
55
 
56
+ var initializeRules = function initializeRules(rules, suffix) {
49
57
  if ((0, _utils.isArr)(rules)) {
50
- return rules.reduce(function (prev, current, subIndex) {
51
- var result = initializeValidator(current, subIndex);
58
+ return rules.reduce(function (prev, current, index) {
59
+ var result = initializeRule(current, "".concat(suffix, "_").concat(index));
52
60
  prev.rules = [].concat(_toConsumableArray(prev.rules), [result.rules]);
53
61
  prev.scope = _objectSpread(_objectSpread({}, prev.scope), result.scope);
54
62
  return prev;
@@ -58,7 +66,7 @@ var initializeRules = function initializeRules(rules, suffix) {
58
66
  });
59
67
  }
60
68
 
61
- return initializeValidator(rules);
69
+ return initializeRule(rules, suffix);
62
70
  };
63
71
 
64
72
  var _default = initializeRules;
@@ -1,6 +1,6 @@
1
1
  import type { ProFormRequestConfig } from '../typing';
2
- declare const $request: (field: any, { extraConfig, ...requestConfig }: ProFormRequestConfig, context: any, type: 'request' | 'validator' | 'dataSource') => Promise<unknown>;
3
- declare const $common: (services: any, requestConfig: ProFormRequestConfig, context: any) => (field: any) => any;
4
- declare const $validator: (services: any, requestConfig: ProFormRequestConfig, context: any) => (value: any, rules: any, { field }: any) => any;
5
- declare const $dataSource: (services: any, requestConfig: ProFormRequestConfig, context: any) => (field: any) => any;
2
+ declare const $request: (field: any, context: any, { extraConfig, onComplete, ...rest }: ProFormRequestConfig, type: 'request' | 'validator' | 'dataSource') => Promise<unknown>;
3
+ declare const $common: (services: any, context: any, requestConfig: ProFormRequestConfig) => (field: any) => any;
4
+ declare const $validator: (services: any, context: any, requestConfig: ProFormRequestConfig) => (value: any, rules: any, { field }: any) => any;
5
+ declare const $dataSource: (services: any, context: any, requestConfig: ProFormRequestConfig) => (field: any) => any;
6
6
  export { $request, $common, $dataSource, $validator };
@@ -7,7 +7,7 @@ exports.$validator = exports.$request = exports.$dataSource = exports.$common =
7
7
 
8
8
  var _utils = require("@teamix/utils");
9
9
 
10
- var _excluded = ["extraConfig"];
10
+ var _excluded = ["extraConfig", "onComplete"];
11
11
 
12
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
13
 
@@ -20,26 +20,28 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
20
20
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
21
 
22
22
  // 配置请求
23
- var $request = function $request(field, _ref, context, type) {
23
+ var $request = function $request(field, context, _ref, type) {
24
24
  var _field$data;
25
25
 
26
26
  var extraConfig = _ref.extraConfig,
27
- requestConfig = _objectWithoutProperties(_ref, _excluded);
27
+ onComplete = _ref.onComplete,
28
+ rest = _objectWithoutProperties(_ref, _excluded);
28
29
 
30
+ var requestConfig = rest;
29
31
  var params = requestConfig.params,
30
32
  beforeRequest = requestConfig.beforeRequest,
31
33
  formatResult = requestConfig.formatResult,
32
34
  onSuccess = requestConfig.onSuccess;
33
- var beforeRequestResult = (0, _utils.isFn)(beforeRequest) ? beforeRequest(field, context) : {};
34
- /**
35
- * 主动触发的请求刷新
36
- */
37
- // 触发所有配置的请求
35
+ var beforeRequestResult = (0, _utils.isFn)(beforeRequest) ? beforeRequest(field, context) : {}; // 通过字段 data 的 refresh 主动触发的请求刷新
38
36
 
39
37
  var refresh = (_field$data = field.data) === null || _field$data === void 0 ? void 0 : _field$data.refresh;
40
- var refreshResult = (0, _utils.isPlainObj)(refresh) ? refresh : {};
38
+ var refreshResult = (0, _utils.isPlainObj)(refresh) ? refresh : {}; // 合并请求参数
39
+
40
+ var mergedParams = _objectSpread(_objectSpread(_objectSpread({}, params), beforeRequestResult), refreshResult); // 执行通用数据请求
41
+
42
+
41
43
  return (0, _utils.doCommonRequest)(_objectSpread(_objectSpread({}, requestConfig), {}, {
42
- params: _objectSpread(_objectSpread(_objectSpread({}, params), beforeRequestResult), refreshResult),
44
+ params: mergedParams,
43
45
  beforeRequest: function beforeRequest() {
44
46
  return beforeRequestResult;
45
47
  },
@@ -49,18 +51,21 @@ var $request = function $request(field, _ref, context, type) {
49
51
  onSuccess: (0, _utils.isFn)(onSuccess) ? function (res) {
50
52
  return onSuccess(res, field, context);
51
53
  } : onSuccess
52
- }), context);
54
+ }), _objectSpread(_objectSpread({}, context), {}, {
55
+ field: field,
56
+ params: mergedParams
57
+ }));
53
58
  }; // 通用请求配置上下文
54
59
 
55
60
 
56
61
  exports.$request = $request;
57
62
 
58
- var $common = function $common(services, requestConfig, context) {
63
+ var $common = function $common(services, context, requestConfig) {
59
64
  return function (field) {
60
- return services(field, requestConfig, context, 'request').then(function (res) {
65
+ return services(field, context, requestConfig, 'request').then(function (res) {
61
66
  var _requestConfig$onComp;
62
67
 
63
- return (_requestConfig$onComp = requestConfig.onComplete) === null || _requestConfig$onComp === void 0 ? void 0 : _requestConfig$onComp.call(requestConfig, res, field, context);
68
+ return requestConfig === null || requestConfig === void 0 ? void 0 : (_requestConfig$onComp = requestConfig.onComplete) === null || _requestConfig$onComp === void 0 ? void 0 : _requestConfig$onComp.call(requestConfig, res, field, context);
64
69
  });
65
70
  };
66
71
  }; // 配置校验
@@ -68,13 +73,15 @@ var $common = function $common(services, requestConfig, context) {
68
73
 
69
74
  exports.$common = $common;
70
75
 
71
- var $validator = function $validator(services, requestConfig, context) {
76
+ var $validator = function $validator(services, context, requestConfig) {
72
77
  return function (value, rules, _ref2) {
73
78
  var field = _ref2.field;
74
- return services(field, requestConfig, context, 'validator').then(function (res) {
75
- var _requestConfig$onComp2;
76
-
77
- return (_requestConfig$onComp2 = requestConfig.onComplete) === null || _requestConfig$onComp2 === void 0 ? void 0 : _requestConfig$onComp2.call(requestConfig, res, field, context);
79
+ return services(field, context, requestConfig, 'validator').then(function (res) {
80
+ if (requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.onComplete) {
81
+ return requestConfig.onComplete(res, field, context);
82
+ } else {
83
+ return res;
84
+ }
78
85
  });
79
86
  };
80
87
  }; // 配置DataSource
@@ -82,13 +89,13 @@ var $validator = function $validator(services, requestConfig, context) {
82
89
 
83
90
  exports.$validator = $validator;
84
91
 
85
- var $dataSource = function $dataSource(services, requestConfig, context) {
92
+ var $dataSource = function $dataSource(services, context, requestConfig) {
86
93
  return function (field) {
87
94
  field.setState({
88
95
  loading: true
89
96
  });
90
- return services(field, requestConfig, context, 'dataSource').then(function (res) {
91
- var _requestConfig$extraC, _requestConfig$onComp3;
97
+ return services(field, context, requestConfig, 'dataSource').then(function (res) {
98
+ var _requestConfig$extraC, _requestConfig$onComp2;
92
99
 
93
100
  var isValueInDataSource = (0, _utils.getValueByValue)(res, field.value);
94
101
  var clearResult = !isValueInDataSource && (requestConfig === null || requestConfig === void 0 ? void 0 : (_requestConfig$extraC = requestConfig.extraConfig) === null || _requestConfig$extraC === void 0 ? void 0 : _requestConfig$extraC.clearInvalidValue) !== false ? {
@@ -98,7 +105,7 @@ var $dataSource = function $dataSource(services, requestConfig, context) {
98
105
  dataSource: res,
99
106
  loading: false
100
107
  }, clearResult));
101
- return (_requestConfig$onComp3 = requestConfig.onComplete) === null || _requestConfig$onComp3 === void 0 ? void 0 : _requestConfig$onComp3.call(requestConfig, res, field, context);
108
+ return requestConfig === null || requestConfig === void 0 ? void 0 : (_requestConfig$onComp2 = requestConfig.onComplete) === null || _requestConfig$onComp2 === void 0 ? void 0 : _requestConfig$onComp2.call(requestConfig, res, field, context);
102
109
  }).catch(function () {
103
110
  field.setState({
104
111
  loading: false
@@ -1,7 +1,8 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { IFormFeedback, Form as FormType, FieldPatternTypes } from '@formily/core';
3
3
  import type { IFormLayoutProps } from '@teamix/formily';
4
- import { CommonRequestConfig } from '@teamix/utils';
4
+ import type { CommonRequestConfig } from '@teamix/utils';
5
+ import type { UrlStateOptions } from '@teamix/hooks';
5
6
  import React from 'react';
6
7
  interface AnyObject {
7
8
  [propName: string]: any;
@@ -18,12 +19,16 @@ declare type IBaseComponent = 'Input' | 'Password' | 'TextArea' | 'NumberPicker'
18
19
  declare type IButtonComponent = 'Submit' | 'Reset';
19
20
  declare type IComboComponent = 'ArrayCards' | 'ArrayCards.Addition' | 'ArrayCards.Remove' | 'ArrayCards.MoveUp' | 'ArrayCards.MoveDown' | 'ArrayCards.Index' | 'ArrayCollapse' | 'ArrayCollapse.CollapsePanel' | 'ArrayCollapse.Addition' | 'ArrayCollapse.Remove' | 'ArrayCollapse.MoveUp' | 'ArrayCollapse.MoveDown' | 'ArrayCollapse.Index' | 'ArrayTable' | 'ArrayTable.Column' | 'ArrayTable.SortHandle' | 'ArrayTable.Addition' | 'ArrayTable.Remove' | 'ArrayTable.MoveDown' | 'ArrayTable.MoveUp' | 'ArrayTable.Index' | 'ArrayItems' | 'ArrayItems.Item' | 'ArrayItems.SortHandle' | 'ArrayItems.Addition' | 'ArrayItems.Remove' | 'ArrayItems.MoveDown' | 'ArrayItems.MoveUp' | 'ArrayItems.Index' | 'Editable' | 'Editable.Popover' | 'Editable.Dialog' | 'Editable.Drawer';
20
21
  declare type ILayoutComponent = 'FormFlex' | 'FormGrid' | 'FormGroup' | 'FormGroup.GroupPanel' | 'Search' | 'Search.SearchPanel' | 'FormTab' | 'FormTab.TabPane' | 'FormStep' | 'FormStep.StepPane' | 'FormCollapse' | 'FormCollapse.CollapsePanel' | 'FormButtonGroup' | 'FormDialog' | 'FormDrawer' | 'FormDialog.Footer' | 'FormDrawer.Footer';
21
- export interface ProFormRequestConfig extends CommonRequestConfig {
22
+ export interface ProFormCommonRequestConfig extends CommonRequestConfig {
22
23
  beforeRequest?: (field?: any, context?: any) => any;
23
24
  formatResult?: (res?: any, field?: any, context?: any) => any;
24
25
  onSuccess?: (res?: any, field?: any, context?: any) => any;
25
- onComplete?: (res?: any, field?: any, context?: any) => any;
26
+ }
27
+ export interface ProFormRequestConfig extends Omit<ProFormCommonRequestConfig, 'url'> {
28
+ url?: string;
29
+ customRequest?: (field?: any, context?: any) => Promise<any>;
26
30
  extraConfig?: AnyObject;
31
+ onComplete?: (res?: any, field?: any, context?: any) => any;
27
32
  }
28
33
  export interface ProFormSchemaItem {
29
34
  type?: string;
@@ -64,7 +69,7 @@ export interface ProFormProps extends IFormLayoutProps {
64
69
  };
65
70
  children?: React.ReactNode;
66
71
  initialValues?: AnyObject;
67
- initialRequest?: ProFormRequestConfig;
72
+ initialRequest?: ProFormCommonRequestConfig;
68
73
  previewTextPlaceholder?: ReactNode;
69
74
  validateFirst?: boolean;
70
75
  onChangeType?: 'form';
@@ -120,8 +125,10 @@ export interface QueryFilterProps extends ProFormProps {
120
125
  formRef?: React.MutableRefObject<any>;
121
126
  /** onChange事件的防抖时间 */
122
127
  filterDebounce?: number;
128
+ /** 绑定URL参数 */
129
+ bindUrl?: boolean | UrlStateOptions;
123
130
  /** 表单初始化(含异步默认值)后回调函数 */
124
- onInit?: (values: any) => boolean;
131
+ onInit?: (values: any) => void;
125
132
  /** 表单筛选回调函数 */
126
133
  onFilter?: (values: any) => void;
127
134
  /** 表单重置回调函数 */
@@ -37,4 +37,19 @@ declare const mapSchemaName: (obj: any) => any;
37
37
  * @returns 合并数组或合并其他值
38
38
  */
39
39
  declare const mergeArrayValue: (arr: any[], v?: any) => any[];
40
- export { mapSize, mapStatus, mapDataSource, mapMode, mergeArrayValue, getFieldName, mapSchemaName, };
40
+ /**
41
+ * 初始化请求配置为表达式
42
+ * @param config 请求配置
43
+ * @param suffix scope名称后缀
44
+ * @returns 表达式和scope上下文
45
+ */
46
+ declare const initializeRequestExpression: (config?: any, mode?: string | undefined, suffix?: string | undefined) => {
47
+ expression: string;
48
+ scope: {
49
+ [x: string]: object;
50
+ };
51
+ } | {
52
+ expression?: undefined;
53
+ scope?: undefined;
54
+ };
55
+ export { mapSize, mapStatus, mapDataSource, mapMode, mergeArrayValue, getFieldName, mapSchemaName, initializeRequestExpression, };
package/lib/form/utils.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.mergeArrayValue = exports.mapStatus = exports.mapSize = exports.mapSchemaName = exports.mapMode = exports.mapDataSource = exports.getFieldName = void 0;
6
+ exports.mergeArrayValue = exports.mapStatus = exports.mapSize = exports.mapSchemaName = exports.mapMode = exports.mapDataSource = exports.initializeRequestExpression = exports.getFieldName = void 0;
7
7
 
8
8
  var _core = require("@formily/core");
9
9
 
@@ -201,5 +201,26 @@ var mergeArrayValue = function mergeArrayValue(arr, v) {
201
201
 
202
202
  return [].concat(_toConsumableArray(arr), [v]);
203
203
  };
204
+ /**
205
+ * 初始化请求配置为表达式
206
+ * @param config 请求配置
207
+ * @param suffix scope名称后缀
208
+ * @returns 表达式和scope上下文
209
+ */
210
+
211
+
212
+ exports.mergeArrayValue = mergeArrayValue;
213
+
214
+ var initializeRequestExpression = function initializeRequestExpression(config, mode, suffix) {
215
+ if ((0, _utils.isPlainObj)(config)) {
216
+ var requestConfigName = "$requestConfig_".concat(suffix);
217
+ return {
218
+ expression: "{{".concat(mode, "($request,context,").concat(requestConfigName, ")}}"),
219
+ scope: _defineProperty({}, requestConfigName, config)
220
+ };
221
+ }
222
+
223
+ return {};
224
+ };
204
225
 
205
- exports.mergeArrayValue = mergeArrayValue;
226
+ exports.initializeRequestExpression = initializeRequestExpression;
@@ -0,0 +1,45 @@
1
+ // transition 切换主题优化,暂时先写到 pro 里,后面加到基础组件里
2
+
3
+ // table 行背景色
4
+ tr.next-table-row{
5
+ transition: color 0s;
6
+ }
7
+
8
+ // normal 按钮
9
+ button.next-btn.next-medium.next-btn-normal {
10
+ transition: color 0s;
11
+ }
12
+
13
+ // input 背景色
14
+ .next-input.next-medium {
15
+ transition: color 0s;
16
+ }
17
+
18
+ // radio 背景色
19
+ .next-radio-wrapper.checked .next-radio-inner:after {
20
+ transition: color 0s;
21
+ }
22
+
23
+ .next-radio-wrapper .next-radio-inner {
24
+ transition: color 0s;
25
+ }
26
+
27
+ // checkbox 背景色
28
+ .next-checkbox-wrapper .next-checkbox-inner {
29
+ transition: color 0s;
30
+ }
31
+
32
+ // 侧导背景色
33
+ .next-menu-item.next-nav-item {
34
+ transition: color 0s;
35
+ }
36
+
37
+ // 标签背景色
38
+ .next-tag {
39
+ transition: color 0s;
40
+ }
41
+
42
+ // 可关闭tag
43
+ .next-tag.next-tag.next-tag.next-tag-closable.next-tag-level-normal.next-tag-closable {
44
+ transition: color 0s;
45
+ }