ronds-metadata 1.2.46 → 1.2.48

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.
@@ -16,13 +16,13 @@ import _Input from "antd/es/input";
16
16
  /*
17
17
  * @Author: wangxian
18
18
  * @Date: 2021-09-18 14:15:04
19
- * @LastEditTime: 2023-05-11 08:26:41
19
+ * @LastEditTime: 2023-05-16 11:13:07
20
20
  */
21
21
  import React from 'react';
22
22
  import { UploadOutlined } from '@ant-design/icons';
23
23
  import { MetadataFormContext, MetadataRefContext } from '../interface';
24
24
  import { useGetExtraInfo } from '../hooks';
25
- import useObservable from '@/framework/rxjs-hooks/useObservable';
25
+ import useObservable from '../../../framework/rxjs-hooks/useObservable';
26
26
  var TextArea = _Input.TextArea;
27
27
  function Index(props) {
28
28
  var _extraInfo$addonAfter7;
@@ -46,17 +46,23 @@ function Index(props) {
46
46
  rules = _React$useState4[0],
47
47
  setRules = _React$useState4[1];
48
48
  useObservable(function (p) {
49
- if ((p === null || p === void 0 ? void 0 : p.type) === 'onValuesChange') {
50
- var _extraInfo$addonAfter;
51
- var evalString = '';
52
- for (var i = 0; i < name.length; i++) {
53
- evalString = "".concat(evalString, "[name[").concat(i, "]]");
54
- }
55
- var _value = eval("p?.payload?.allVals".concat(evalString));
56
- if (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$addonAfter = extraInfo.addonAfter) === null || _extraInfo$addonAfter === void 0 ? void 0 : _extraInfo$addonAfter.key) {
57
- setValueTitle(_value === null || _value === void 0 ? void 0 : _value.value);
58
- } else {
59
- setValueTitle(_value);
49
+ var _p$payload;
50
+ if (name && (!(extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.type) || (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.type) === 'textarea') && (p === null || p === void 0 ? void 0 : (_p$payload = p.payload) === null || _p$payload === void 0 ? void 0 : _p$payload.trigger) === 'firstLoad' && (p === null || p === void 0 ? void 0 : p.type) === 'onValuesChange') {
51
+ try {
52
+ var _extraInfo$addonAfter;
53
+ var evalString = '';
54
+ for (var i = 0; i < name.length; i++) {
55
+ evalString = "".concat(evalString, "[name[").concat(i, "]]");
56
+ }
57
+ var _value = eval("p?.payload?.allVals".concat(evalString));
58
+ if (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$addonAfter = extraInfo.addonAfter) === null || _extraInfo$addonAfter === void 0 ? void 0 : _extraInfo$addonAfter.key) {
59
+ setValueTitle(_value === null || _value === void 0 ? void 0 : _value.value);
60
+ } else {
61
+ setValueTitle(_value);
62
+ }
63
+ } catch (error) {
64
+ // 处理异常情况
65
+ console.error(error.message);
60
66
  }
61
67
  }
62
68
  }, [formContext.stream$, name, extraInfo]);
@@ -28,8 +28,8 @@ import _Tooltip from "antd/es/tooltip";
28
28
  import "antd/es/tag/style";
29
29
  import _Tag from "antd/es/tag";
30
30
  import _typeof from "@babel/runtime/helpers/esm/typeof";
31
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
32
31
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
32
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
33
33
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
34
34
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
35
35
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
@@ -37,7 +37,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
37
37
  /*
38
38
  * @Author:wangxian
39
39
  * @Date: 2021-09-18 14:15:04
40
- * @LastEditTime: 2023-04-28 10:25:33
40
+ * @LastEditTime: 2023-05-16 16:38:08
41
41
  */
42
42
  import React from 'react';
43
43
  import { MetadataFormContext, MetadataRefContext } from '../interface';
@@ -49,7 +49,7 @@ import { tr } from '../../../framework/locale';
49
49
  import useObservable from '../../../framework/rxjs-hooks/useObservable';
50
50
  import { assignReplace } from '../utils';
51
51
  function Index(props) {
52
- var _extraInfo$http8, _extraInfo$http9, _extraInfo$http10, _extraInfo$http11, _extraInfo$http12, _extraInfo$http13;
52
+ var _extraInfo$http9, _extraInfo$http10, _extraInfo$http11, _extraInfo$http12, _extraInfo$http13, _extraInfo$http14;
53
53
  var id = props.id,
54
54
  name = props.name,
55
55
  isRefForm = props.isRefForm,
@@ -73,15 +73,25 @@ function Index(props) {
73
73
  _React$useState4 = _slicedToArray(_React$useState3, 2),
74
74
  treeData = _React$useState4[0],
75
75
  setTreeData = _React$useState4[1];
76
- var _React$useState5 = React.useState(),
76
+ var _React$useState5 = React.useState(false),
77
77
  _React$useState6 = _slicedToArray(_React$useState5, 2),
78
- watchValue = _React$useState6[0],
79
- setWatchValue = _React$useState6[1];
80
- var watchValueRef = React.useRef();
81
- var _React$useState7 = React.useState([]),
78
+ treeselectOpen = _React$useState6[0],
79
+ setTreeselectOpen = _React$useState6[1];
80
+ var treeRef = React.useRef(null);
81
+ var _React$useState7 = React.useState(),
82
82
  _React$useState8 = _slicedToArray(_React$useState7, 2),
83
- mutiSelect = _React$useState8[0],
84
- setMutiSelect = _React$useState8[1];
83
+ watchValue = _React$useState8[0],
84
+ setWatchValue = _React$useState8[1];
85
+ var watchValueRef = React.useRef();
86
+ var _React$useState9 = React.useState([]),
87
+ _React$useState10 = _slicedToArray(_React$useState9, 2),
88
+ mutiSelect = _React$useState10[0],
89
+ setMutiSelect = _React$useState10[1];
90
+ var _React$useState11 = React.useState([]),
91
+ _React$useState12 = _slicedToArray(_React$useState11, 2),
92
+ expandedKeys = _React$useState12[0],
93
+ setExpandedKeys = _React$useState12[1];
94
+ var firstLoadTreeSelectRef = React.useRef(true);
85
95
  var pageRef = React.useRef(1);
86
96
  var totalRef = React.useRef();
87
97
  var onSelect = function onSelect(value) {
@@ -91,10 +101,10 @@ function Index(props) {
91
101
  });
92
102
  };
93
103
  useObservable(function (p) {
94
- var _extraInfo$http;
104
+ var _extraInfo$http, _extraInfo$http2, _p$payload3;
95
105
  // 判断是否有 watch的扩展属性
96
106
  var _watch = extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http = extraInfo.http) === null || _extraInfo$http === void 0 ? void 0 : _extraInfo$http.watch;
97
- if (_watch && (p === null || p === void 0 ? void 0 : p.type) === 'onValuesChange') {
107
+ if (name && _watch && (p === null || p === void 0 ? void 0 : p.type) === 'onValuesChange') {
98
108
  try {
99
109
  var _watchArr = _watch.split(',');
100
110
  if (_watchArr.length === 1) {
@@ -130,18 +140,18 @@ function Index(props) {
130
140
  var b = false;
131
141
  for (var _i = 0; _i < _watchArr.length; _i++) {
132
142
  var w = _watchArr[_i];
133
- var _evalString = '';
143
+ var _evalString2 = '';
134
144
  for (var _i2 = 0; _i2 < name.length; _i2++) {
135
145
  if (_i2 < name.length - 1) {
136
- _evalString = "".concat(_evalString, "[name[").concat(_i2, "]]");
146
+ _evalString2 = "".concat(_evalString2, "[name[").concat(_i2, "]]");
137
147
  }
138
148
  }
139
- var _value2 = eval("p?.payload?.allVals".concat(_evalString, "[w]"));
149
+ var _value2 = eval("p?.payload?.allVals".concat(_evalString2, "[w]"));
140
150
  if (_value2) {
141
151
  var _wRef2 = watchValueRef.current || {};
142
152
  _wRef2[w] = _value2;
143
153
  watchValueRef.current = _wRef2;
144
- b = eval("p?.payload?.val".concat(_evalString, "[w]"));
154
+ b = eval("p?.payload?.val".concat(_evalString2, "[w]"));
145
155
  }
146
156
  }
147
157
  if (b && !(p === null || p === void 0 ? void 0 : (_p$payload2 = p.payload) === null || _p$payload2 === void 0 ? void 0 : _p$payload2.trigger)) {
@@ -157,7 +167,18 @@ function Index(props) {
157
167
  console.warn('watch:' + error);
158
168
  }
159
169
  }
160
- }, [formContext.stream$, extraInfo]);
170
+ if (treeData.length > 0 && name && (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http2 = extraInfo.http) === null || _extraInfo$http2 === void 0 ? void 0 : _extraInfo$http2.isTreeSelect) && (p === null || p === void 0 ? void 0 : (_p$payload3 = p.payload) === null || _p$payload3 === void 0 ? void 0 : _p$payload3.trigger) === 'firstLoad' && (p === null || p === void 0 ? void 0 : p.type) === 'onValuesChange') {
171
+ var _evalString = '';
172
+ for (var _i3 = 0; _i3 < name.length; _i3++) {
173
+ _evalString = "".concat(_evalString, "[name[").concat(_i3, "]]");
174
+ }
175
+ var _treeSelectValue = eval("p?.payload?.allVals".concat(_evalString));
176
+ if (_treeSelectValue) {
177
+ var selectedKeys = Array.isArray(_treeSelectValue) ? _treeSelectValue : [_treeSelectValue];
178
+ setExpandedKeys(_toConsumableArray(selectedKeys));
179
+ }
180
+ }
181
+ }, [formContext.stream$, treeData, extraInfo, name]);
161
182
  var getEnumDataByUrl = React.useCallback( /*#__PURE__*/function () {
162
183
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(http, pid, page) {
163
184
  var server, _url, res, _res;
@@ -253,7 +274,7 @@ function Index(props) {
253
274
  return processSelectOptionsData();
254
275
  }, [initEnumValue, myEnum, id, extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.maxSelect]);
255
276
  var httpOptions = useAsyncMemo( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
256
- var _extraInfo$http2, _extraInfo$http3, _extraInfo$http4, res;
277
+ var _extraInfo$http3, _extraInfo$http4, _extraInfo$http5, res;
257
278
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
258
279
  while (1) switch (_context2.prev = _context2.next) {
259
280
  case 0:
@@ -262,13 +283,13 @@ function Index(props) {
262
283
  break;
263
284
  }
264
285
  _context2.next = 3;
265
- return getEnumDataByUrl(deepClone(extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.http), '', (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http2 = extraInfo.http) === null || _extraInfo$http2 === void 0 ? void 0 : _extraInfo$http2.isPagination) && pageRef.current);
286
+ return getEnumDataByUrl(deepClone(extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.http), '', (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http3 = extraInfo.http) === null || _extraInfo$http3 === void 0 ? void 0 : _extraInfo$http3.isPagination) && pageRef.current);
266
287
  case 3:
267
288
  res = _context2.sent;
268
- if (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http3 = extraInfo.http) === null || _extraInfo$http3 === void 0 ? void 0 : _extraInfo$http3.isCascader) {
289
+ if (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http4 = extraInfo.http) === null || _extraInfo$http4 === void 0 ? void 0 : _extraInfo$http4.isCascader) {
269
290
  setCascaderOption(_toConsumableArray(res));
270
291
  }
271
- if (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http4 = extraInfo.http) === null || _extraInfo$http4 === void 0 ? void 0 : _extraInfo$http4.isTreeSelect) {
292
+ if (extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http5 = extraInfo.http) === null || _extraInfo$http5 === void 0 ? void 0 : _extraInfo$http5.isTreeSelect) {
272
293
  setTreeData(_toConsumableArray(res));
273
294
  }
274
295
  return _context2.abrupt("return", res);
@@ -355,6 +376,23 @@ function Index(props) {
355
376
  return '...';
356
377
  }
357
378
  };
379
+ var onExpand = function onExpand(_expandedKeys) {
380
+ setExpandedKeys(_toConsumableArray(_expandedKeys));
381
+ };
382
+ var onDropdownVisibleChange = function onDropdownVisibleChange(_open) {
383
+ setTreeselectOpen(_open);
384
+ if (_open && firstLoadTreeSelectRef.current) {
385
+ setTimeout(function () {
386
+ var _treeRef$current;
387
+ (_treeRef$current = treeRef.current) === null || _treeRef$current === void 0 ? void 0 : _treeRef$current.scrollTo({
388
+ key: expandedKeys[0],
389
+ align: 'top',
390
+ offset: 40
391
+ });
392
+ firstLoadTreeSelectRef.current = false;
393
+ }, 100);
394
+ }
395
+ };
358
396
  var processSelectType = function processSelectType(isCascader, isTreeSelect, isPagination) {
359
397
  if (isCascader) {
360
398
  var _extraInfo$disabled;
@@ -369,6 +407,7 @@ function Index(props) {
369
407
  var _extraInfo$disabled2;
370
408
  return /*#__PURE__*/React.createElement(_TreeSelect, {
371
409
  showSearch: true,
410
+ ref: treeRef,
372
411
  filterTreeNode: function filterTreeNode(input, treeNode) {
373
412
  var _treeNode$label;
374
413
  return (treeNode === null || treeNode === void 0 ? void 0 : (_treeNode$label = treeNode.label) === null || _treeNode$label === void 0 ? void 0 : _treeNode$label.toString().indexOf(input)) >= 0;
@@ -386,6 +425,10 @@ function Index(props) {
386
425
  overflow: 'auto'
387
426
  },
388
427
  treeData: treeData,
428
+ onTreeExpand: onExpand,
429
+ open: treeselectOpen,
430
+ onDropdownVisibleChange: onDropdownVisibleChange,
431
+ treeExpandedKeys: expandedKeys,
389
432
  allowClear: true,
390
433
  disabled: (_extraInfo$disabled2 = extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.disabled) !== null && _extraInfo$disabled2 !== void 0 ? _extraInfo$disabled2 : disabled,
391
434
  placeholder: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.placeholder,
@@ -479,7 +522,7 @@ function Index(props) {
479
522
  }
480
523
  };
481
524
  if (isObj && isRefForm && field) {
482
- var _extraInfo$http5, _extraInfo$http6, _extraInfo$http7;
525
+ var _extraInfo$http6, _extraInfo$http7, _extraInfo$http8;
483
526
  return /*#__PURE__*/React.createElement(_Form.Item, _extends({}, field, {
484
527
  style: {
485
528
  flex: 1,
@@ -507,7 +550,7 @@ function Index(props) {
507
550
  }],
508
551
  help: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.help,
509
552
  tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
510
- }), processSelectType((_extraInfo$http5 = extraInfo.http) === null || _extraInfo$http5 === void 0 ? void 0 : _extraInfo$http5.isCascader, (_extraInfo$http6 = extraInfo.http) === null || _extraInfo$http6 === void 0 ? void 0 : _extraInfo$http6.isTreeSelect, (_extraInfo$http7 = extraInfo.http) === null || _extraInfo$http7 === void 0 ? void 0 : _extraInfo$http7.isPagination));
553
+ }), processSelectType((_extraInfo$http6 = extraInfo.http) === null || _extraInfo$http6 === void 0 ? void 0 : _extraInfo$http6.isCascader, (_extraInfo$http7 = extraInfo.http) === null || _extraInfo$http7 === void 0 ? void 0 : _extraInfo$http7.isTreeSelect, (_extraInfo$http8 = extraInfo.http) === null || _extraInfo$http8 === void 0 ? void 0 : _extraInfo$http8.isPagination));
511
554
  }
512
555
  return !field ? /*#__PURE__*/React.createElement(_Form.Item, {
513
556
  key: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.defaultValue,
@@ -537,7 +580,7 @@ function Index(props) {
537
580
  }],
538
581
  help: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.help,
539
582
  tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
540
- }, processSelectType((_extraInfo$http8 = extraInfo.http) === null || _extraInfo$http8 === void 0 ? void 0 : _extraInfo$http8.isCascader, (_extraInfo$http9 = extraInfo.http) === null || _extraInfo$http9 === void 0 ? void 0 : _extraInfo$http9.isTreeSelect, (_extraInfo$http10 = extraInfo.http) === null || _extraInfo$http10 === void 0 ? void 0 : _extraInfo$http10.isPagination)) : /*#__PURE__*/React.createElement(_Form.Item, _extends({}, field, {
583
+ }, processSelectType((_extraInfo$http9 = extraInfo.http) === null || _extraInfo$http9 === void 0 ? void 0 : _extraInfo$http9.isCascader, (_extraInfo$http10 = extraInfo.http) === null || _extraInfo$http10 === void 0 ? void 0 : _extraInfo$http10.isTreeSelect, (_extraInfo$http11 = extraInfo.http) === null || _extraInfo$http11 === void 0 ? void 0 : _extraInfo$http11.isPagination)) : /*#__PURE__*/React.createElement(_Form.Item, _extends({}, field, {
541
584
  style: {
542
585
  flex: 1,
543
586
  paddingRight: '10px'
@@ -548,6 +591,6 @@ function Index(props) {
548
591
  }],
549
592
  help: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.help,
550
593
  tooltip: extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.tooltip
551
- }), processSelectType((_extraInfo$http11 = extraInfo.http) === null || _extraInfo$http11 === void 0 ? void 0 : _extraInfo$http11.isCascader, (_extraInfo$http12 = extraInfo.http) === null || _extraInfo$http12 === void 0 ? void 0 : _extraInfo$http12.isTreeSelect, (_extraInfo$http13 = extraInfo.http) === null || _extraInfo$http13 === void 0 ? void 0 : _extraInfo$http13.isPagination));
594
+ }), processSelectType((_extraInfo$http12 = extraInfo.http) === null || _extraInfo$http12 === void 0 ? void 0 : _extraInfo$http12.isCascader, (_extraInfo$http13 = extraInfo.http) === null || _extraInfo$http13 === void 0 ? void 0 : _extraInfo$http13.isTreeSelect, (_extraInfo$http14 = extraInfo.http) === null || _extraInfo$http14 === void 0 ? void 0 : _extraInfo$http14.isPagination));
552
595
  }
553
596
  export default /*#__PURE__*/React.memo(Index);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "ronds-metadata",
4
- "version": "1.2.46",
4
+ "version": "1.2.48",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",