@lingxiteam/ebe-utils 0.3.27 → 0.3.29

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>
@@ -6,7 +6,6 @@ import { cloneDeep, isPlainObject } from 'lodash';
6
6
  import { useEffect, useRef, useState } from 'react';
7
7
 
8
8
  export interface UpdateDataSourceOptions {
9
-
10
9
  /**
11
10
  * 数据源名称
12
11
  */
@@ -52,7 +51,6 @@ export interface DataSourceOptions {
52
51
 
53
52
  export interface BaseDataSourceType {
54
53
  _others_: {
55
-
56
54
  /**
57
55
  * 用户信息
58
56
  */
@@ -165,6 +163,16 @@ const useBaseDataSource = <T extends BaseDataSourceType>(options: DataSourceOpti
165
163
  [name]: params,
166
164
  });
167
165
 
166
+ const getParams = (params: any) => {
167
+ if (params?.serviceRequest) {
168
+ return params?.serviceRequest;
169
+ } else if (params?.parameters) {
170
+ return params?.parameters;
171
+ } else if (params?.params) {
172
+ return params?.params;
173
+ }
174
+ return params;
175
+ };
168
176
  /**
169
177
  * 刷新对象数据源
170
178
  */
@@ -174,15 +182,15 @@ const useBaseDataSource = <T extends BaseDataSourceType>(options: DataSourceOpti
174
182
  ...options,
175
183
  attrs: params,
176
184
  })
177
- .then(res => {
185
+ .then((res) => {
178
186
  setData({
179
187
  [name]: res,
180
- [`${name}Filter`]: params,
188
+ [`${name}Filter`]: getParams(params),
181
189
  });
182
190
  const snapShot = cloneDeep(res);
183
191
  setDataSnapshot({
184
192
  [name]: snapShot,
185
- [`${name}Filter`]: params,
193
+ [`${name}Filter`]: getParams(params),
186
194
  });
187
195
  return res;
188
196
  })
@@ -195,18 +203,18 @@ const useBaseDataSource = <T extends BaseDataSourceType>(options: DataSourceOpti
195
203
  /**
196
204
  * 刷新服务数据源
197
205
  */
198
- const reloadServiceDataSource = (name: string, service: any, params: any) => {
206
+ const reloadServiceDataSource = (name: string, url: any, params: any) => {
199
207
  setLoading(true);
200
- return fetchQueryService(service, params)
201
- .then(res => {
208
+ return fetchQueryService(url, params)
209
+ .then((res) => {
202
210
  setData({
203
211
  [name]: res,
204
- [`${name}Filter`]: params,
212
+ [`${name}Filter`]: getParams(params),
205
213
  });
206
214
  const snapShot = cloneDeep(res);
207
215
  setDataSnapshot({
208
216
  [name]: snapShot,
209
- [`${name}Filter`]: params,
217
+ [`${name}Filter`]: getParams(params),
210
218
  });
211
219
  return res;
212
220
  })
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.29",
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.29"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"