@lingxiteam/ebe-utils 0.1.5 → 0.1.6

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,6 +16,7 @@ import { getRegExp, initMomentLocale } from '../../utils/common';
16
16
  import { useLocale } from '../../utils/hooks/useLocale';
17
17
  import { ExpressionRenderingParams } from '../../utils/PropsType';
18
18
  import { EDIT_COMPONENT_STOP_PROPAGATION_CLS } from '../constant';
19
+ import { getFormItemFieldName } from '../utils';
19
20
 
20
21
  export interface MyEditComponent {
21
22
  inlineVChange: (date: any, _label: any) => void;
@@ -531,9 +532,16 @@ const EditComponent: React.FC<MyEditComponent> = (props) => {
531
532
  };
532
533
 
533
534
  if (supportEditComponents.includes(edittype) && validateRules) {
534
- const fieldName = `${compId}_${currentRowKey}_${
535
- rowData[currentRowKey] || rowId
536
- }_${dataIndex}`;
535
+ // const fieldName = `${compId}_${currentRowKey}_${
536
+ // rowData[currentRowKey] || rowId
537
+ // }_${dataIndex}`;
538
+ const fieldName = getFormItemFieldName({
539
+ compId,
540
+ currentRowKey,
541
+ rowData,
542
+ rowId,
543
+ dataIndex,
544
+ });
537
545
  return (
538
546
  <Form.Item
539
547
  style={{ height: 'auto' }}
@@ -20,6 +20,7 @@ interface UseCommonCMDAction {
20
20
  setOuterDataSource: Function;
21
21
  onRowSelected: Function;
22
22
  engineApis?: EngineApisType;
23
+ form?: any;
23
24
  }
24
25
 
25
26
  interface UseCMDActionPropsType extends UseCommonCMDAction {
@@ -94,6 +95,10 @@ const useCMDAction = (props: UseCMDActionPropsType) => {
94
95
  * 加载表格数据(加载完之后,表格就脱离了数据源的控制了)
95
96
  */
96
97
  setTableData: (data: { dataSource: any[]; total: any; current: any }) => {
98
+ // 重置表格,避免下次加载后编辑组件还保留原始值
99
+ if (typeof form?.resetFields === 'function') {
100
+ form.resetFields();
101
+ }
97
102
  if (tableUpdateInnerDataSource) {
98
103
  setInnerDataSource(data?.dataSource || []);
99
104
  } else {
@@ -291,6 +296,7 @@ const useCommonCMDAction = (props: UseCommonCMDAction) => {
291
296
  setInnerDataSource,
292
297
  setOuterDataSource,
293
298
  engineApis,
299
+ form,
294
300
  } = props;
295
301
 
296
302
  const [loading, setLoading] = useState(false);
@@ -341,6 +347,9 @@ const useCommonCMDAction = (props: UseCommonCMDAction) => {
341
347
  }
342
348
  },
343
349
  clearData: () => {
350
+ if (typeof form?.resetFields === 'function') {
351
+ form.resetFields();
352
+ }
344
353
  setInnerDataSource([]);
345
354
  if (!tableUpdateInnerDataSource) {
346
355
  // 3.8.1前,清空表格数据后,会脱离数据源控制
@@ -3,6 +3,7 @@ import { EDIT_COMPONENT_STOP_PROPAGATION_CLS } from '../constant';
3
3
  import {
4
4
  deleteTempRowProperties,
5
5
  EMPTY_ROW_TEMP_KEY_ATTR,
6
+ getFormItemFieldName,
6
7
  LATEST_EMPTY_ROW_FLAG_ATTR,
7
8
  } from '../utils';
8
9
 
@@ -28,6 +29,8 @@ const useRowEdit = (props: any) => {
28
29
  onBeforeInlineEdit,
29
30
  onBeforeInlineSave,
30
31
  engineApis,
32
+ compId,
33
+ form,
31
34
  } = props;
32
35
 
33
36
  const [nowInlineEditKey, setNowInlineEditKey] = useState<string | null>();
@@ -103,6 +106,22 @@ const useRowEdit = (props: any) => {
103
106
  };
104
107
 
105
108
  const onRowCancelClick = (row: any) => {
109
+ // 取消时重置为原始数据
110
+ if (typeof form?.setFieldsValue === 'function') {
111
+ const originRow: Record<string, any> = {};
112
+ Object.keys(row).forEach((key) => {
113
+ // 表单项名称
114
+ const fieldName = getFormItemFieldName({
115
+ compId,
116
+ currentRowKey,
117
+ rowData: row,
118
+ rowId: row[currentRowKey],
119
+ dataIndex: key,
120
+ });
121
+ originRow[fieldName] = row[key];
122
+ });
123
+ form.setFieldsValue(originRow);
124
+ }
106
125
  setNowEditingData(null);
107
126
  setNowInlineEditKey(null);
108
127
  // 取消编辑的时候,如果当前行是刚刚新增的空白行,则过滤当前行
@@ -210,6 +210,8 @@ const MyTable = React.forwardRef<any, MyTableProps>((props, ref) => {
210
210
  selectedRows,
211
211
  onRowSelected,
212
212
  engineApis,
213
+ compId,
214
+ form,
213
215
  });
214
216
 
215
217
  const { rowSpanColMap, rowSpanMap, rowClassMap } = useRowMerge({
@@ -492,3 +492,19 @@ export const getFullCheckedKeySet = <T extends {}>(params: {
492
492
  }, [] as (string | number)[]),
493
493
  );
494
494
  };
495
+
496
+ // 获取编辑组件表单项字段编码
497
+ export const getFormItemFieldName = ({
498
+ compId,
499
+ currentRowKey,
500
+ rowData,
501
+ rowId,
502
+ dataIndex,
503
+ }: {
504
+ compId: string;
505
+ currentRowKey: string;
506
+ rowData: any;
507
+ rowId?: string | number;
508
+ dataIndex: string | string[];
509
+ }) =>
510
+ `${compId}_${currentRowKey}_${rowData[currentRowKey] || rowId}_${dataIndex}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxiteam/ebe-utils",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
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.1.5"
22
+ "@lingxiteam/ebe": "0.1.6"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"