@lingxiteam/ebe-utils 0.3.27 → 0.3.28

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,6 +1,6 @@
1
1
  import { DatePicker, Input, InputNumber, Select, Radio, Switch, Form } from 'antd';
2
2
  import moment, { Moment } from 'moment';
3
- import React, { useCallback, useMemo, useState } from 'react';
3
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
4
4
  import ComSelect from '../../SuperSelect/ComSelect';
5
5
  import ModalSelect from '../../ModalSelect';
6
6
  import { initMomentLocale, getRegExp } from '../../utils/common';
@@ -55,6 +55,7 @@ const EditComponent: React.FC<MyEditComponent> = (props) => {
55
55
  engineApis,
56
56
  onChange,
57
57
  onBlur,
58
+ form,
58
59
  } = props;
59
60
  const { dataIndex } = c;
60
61
  const {
@@ -75,6 +76,7 @@ const EditComponent: React.FC<MyEditComponent> = (props) => {
75
76
  const [tempInputValue, updateTempInputValue] = useState<string | undefined>();
76
77
 
77
78
  const { getLocale } = useLocale(engineApis || {});
79
+ const fieldName = getFormItemFieldName({ compId, currentRowKey, rowData, rowId, dataIndex });
78
80
 
79
81
  const limitRangeTime: {
80
82
  startTime: Moment;
@@ -212,6 +214,21 @@ const EditComponent: React.FC<MyEditComponent> = (props) => {
212
214
  return res?.length > 0 ? res : null;
213
215
  }, [initialValueType, isNaNValue, rules, validateDateCustomExpress]);
214
216
 
217
+ const needFormItem = useMemo(() => supportEditComponents.includes(edittype) && validateRules,
218
+ [supportEditComponents, edittype,
219
+ validateRules]);
220
+
221
+ useEffect(() => {
222
+ if (needFormItem && fieldName) {
223
+ const currentValue = tempInputValue ?? initialValue;
224
+ const formValue = form.getFieldValue(fieldName);
225
+ if (formValue !== currentValue) {
226
+ // 值不一样时需要通过表单赋值更新成由外部传入的新值
227
+ form.setFieldValue(fieldName, currentValue);
228
+ }
229
+ }
230
+ }, [needFormItem, fieldName, tempInputValue, initialValue]);
231
+
215
232
  const getDisabledDate = useCallback((current: Moment) => {
216
233
  // custom 自定义规则通过form表单进行校验
217
234
  if (!limitRange || limitRange === 'no' || limitRange === 'custom') {
@@ -498,8 +515,7 @@ const EditComponent: React.FC<MyEditComponent> = (props) => {
498
515
  }
499
516
  };
500
517
 
501
- if (supportEditComponents.includes(edittype) && validateRules) {
502
- const fieldName = getFormItemFieldName({ compId, currentRowKey, rowData, rowId, dataIndex });
518
+ if (needFormItem) {
503
519
  return (
504
520
  <Form.Item
505
521
  style={{ height: 'auto' }}
@@ -507,7 +523,7 @@ const EditComponent: React.FC<MyEditComponent> = (props) => {
507
523
  // TODO: 设置的 filedName 目前实际没作用,只是为了防止formitem错误告警
508
524
  name={fieldName}
509
525
  initialValue={initialValue}
510
- rules={validateRules}
526
+ rules={validateRules as any}
511
527
  >
512
528
  {renderComponent(true)}
513
529
  </Form.Item>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/ebe-utils",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -19,7 +19,7 @@
19
19
  "@babel/types": "^7.12.12",
20
20
  "cac": "^6.7.14",
21
21
  "fs-extra": "9.x",
22
- "@lingxiteam/ebe": "0.3.27"
22
+ "@lingxiteam/ebe": "0.3.28"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"