@lingxiteam/ebe-utils 0.1.5 → 0.1.8
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.
- package/es/constants.js +1 -1
- package/lib/pcpublic/src/components/pcfactory/src/Table/EditComponent/index.tsx +11 -3
- package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useCMDActions.ts +9 -0
- package/lib/pcpublic/src/components/pcfactory/src/Table/hooks/useRowEdit.ts +19 -0
- package/lib/pcpublic/src/components/pcfactory/src/Table/index.tsx +2 -0
- package/lib/pcpublic/src/components/pcfactory/src/Table/utils/index.ts +16 -0
- package/lib/pcpublic/src/hooks/useCompatConfig.ts +80 -0
- package/lib/public/src/utils/version.ts +81 -0
- package/package.json +2 -2
package/es/constants.js
CHANGED
|
@@ -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
|
-
|
|
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
|
// 取消编辑的时候,如果当前行是刚刚新增的空白行,则过滤当前行
|
|
@@ -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}`;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { version } from '@/utils/version';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
interface CompatConfigParams {
|
|
5
|
+
createdEditorVersion: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useCompatConfig = (params: CompatConfigParams) => {
|
|
9
|
+
const { createdEditorVersion } = params;
|
|
10
|
+
|
|
11
|
+
const lessThanV331 = useMemo(() => {
|
|
12
|
+
const versionStr = version.getMainVersion(createdEditorVersion);
|
|
13
|
+
if (versionStr) {
|
|
14
|
+
return version.isLessThan(versionStr, '3.3.1');
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}, [createdEditorVersion]);
|
|
18
|
+
|
|
19
|
+
const lessThanV381 = useMemo(() => {
|
|
20
|
+
const versionStr = version.getMainVersion(createdEditorVersion);
|
|
21
|
+
if (versionStr) {
|
|
22
|
+
return version.isLessThan(versionStr, '3.8.1');
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}, [createdEditorVersion]);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
isFormCompat: lessThanV331,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 是否开启联动规则
|
|
32
|
+
*/
|
|
33
|
+
openLinkageRule: true,
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 表单重置到默认值
|
|
37
|
+
*/
|
|
38
|
+
resetFormToDefaultValue: !lessThanV381,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 指令兼容
|
|
42
|
+
*/
|
|
43
|
+
cmd: {
|
|
44
|
+
/**
|
|
45
|
+
* 小于3.8.1 自定义代码块里面更改数据源后,触发页面绑定数据的刷新,大于等于3.8.1不刷新
|
|
46
|
+
*/
|
|
47
|
+
customActionCodeNotUpdateData: !lessThanV381,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 指令作用域只生效在同层级,3.8.1之后生效
|
|
51
|
+
*/
|
|
52
|
+
peerScope: !lessThanV381,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 阻止onClick冒泡的指令
|
|
56
|
+
*/
|
|
57
|
+
stopPropagation: !lessThanV331 ? ['onClick'] : undefined,
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 调用任意页面自定义事件兼容(3.3.1 之后 使用engineRelation 去调用任意页面事件,否则都使用lcdapi去调用)
|
|
61
|
+
*/
|
|
62
|
+
compatCallCustomPageFunc: lessThanV331,
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* pc设置表单值动作是否需要触发表单值变化回掉(3.3.1之前 不论绑定数据源还是不绑定数据源都触发)
|
|
66
|
+
*/
|
|
67
|
+
setFieldsValueToOnValuesChange: lessThanV331,
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 3.3.1后业务组件和页面容器动作控制隐藏,通过dsiplay none
|
|
71
|
+
*/
|
|
72
|
+
boFramePageViewVisibleDisplayNone: !lessThanV331,
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 3.8.1 后表格所有动作只操作内部数据,不上报到数据源
|
|
76
|
+
*/
|
|
77
|
+
tableUpdateInnerDataSource: !lessThanV381,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 2个数组位数对齐
|
|
3
|
+
* @param list1
|
|
4
|
+
* @param list2
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
const repairArr = (list1: number[], list2: number[]) => {
|
|
8
|
+
if (list1.length === list2.length) {
|
|
9
|
+
return [list1, list2];
|
|
10
|
+
}
|
|
11
|
+
if (list1.length > list2.length) {
|
|
12
|
+
list2.push(...new Array(list1.length - list2.length).fill(0));
|
|
13
|
+
return [list1, list2];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
list1.push(...new Array(list2.length - list1.length).fill(0));
|
|
17
|
+
return [list1, list2];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 分割"." 获取number数组
|
|
22
|
+
* @param version
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
const splitVersionNumber = (version: string) => {
|
|
26
|
+
return version
|
|
27
|
+
.split('.')
|
|
28
|
+
.map((v) => parseInt(v.replace(/[^\d]/g, ''), 10) || 0);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const version = {
|
|
32
|
+
/**
|
|
33
|
+
* version1 是否小于 version2
|
|
34
|
+
* @param version1
|
|
35
|
+
* @param version2
|
|
36
|
+
*/
|
|
37
|
+
isLessThan(version1: string, version2: string) {
|
|
38
|
+
if (
|
|
39
|
+
!version1 ||
|
|
40
|
+
!version2 ||
|
|
41
|
+
typeof version1 !== 'string' ||
|
|
42
|
+
typeof version2 !== 'string'
|
|
43
|
+
) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let splitVerArr1 = splitVersionNumber(version1);
|
|
48
|
+
let splitVerArr2 = splitVersionNumber(version2);
|
|
49
|
+
|
|
50
|
+
[splitVerArr1, splitVerArr2] = repairArr(splitVerArr1, splitVerArr2);
|
|
51
|
+
|
|
52
|
+
for (let index = 0; index < splitVerArr1.length; index += 1) {
|
|
53
|
+
const ver1 = splitVerArr1[index];
|
|
54
|
+
const ver2 = splitVerArr2[index];
|
|
55
|
+
// 如果版本号中同位版本一致则继续比较下一位,否则返回比较结果
|
|
56
|
+
if (ver1 !== ver2) {
|
|
57
|
+
return ver1 < ver2;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 获取主版本号
|
|
65
|
+
* @param str 版本号
|
|
66
|
+
*/
|
|
67
|
+
getMainVersion(str?: string): string {
|
|
68
|
+
if (!str) {
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
let versions: string[] = [];
|
|
72
|
+
if (typeof str === 'string') {
|
|
73
|
+
versions = str.split('.');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (versions.length !== 4) {
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
return versions.slice(0, 3).join('.');
|
|
80
|
+
},
|
|
81
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingxiteam/ebe-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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.
|
|
22
|
+
"@lingxiteam/ebe": "0.1.8"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|