ztxkui 4.2.23-521 → 4.2.23-522
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.
|
@@ -61,7 +61,7 @@ import i18next from 'ztxkutils/dist/i18next';
|
|
|
61
61
|
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
62
62
|
import { data2, data3 } from './data';
|
|
63
63
|
import ProEditTable from 'components/ProTable';
|
|
64
|
-
import { Button, message, EnhanceSelect, InputNumber, Modal, } from '../../index.build';
|
|
64
|
+
import { Button, message, EnhanceSelect, InputNumber, Modal, Input, } from '../../index.build';
|
|
65
65
|
import { InputNumber as AntInputNumber } from 'antd';
|
|
66
66
|
import { toThousand, exactRound } from 'ztxkutils/dist/tools';
|
|
67
67
|
var number_precision = 0;
|
|
@@ -86,11 +86,19 @@ function useColumns(tableHandleRef) {
|
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
title: i18next.t('测试列1'),
|
|
89
|
-
|
|
89
|
+
width: 100,
|
|
90
90
|
dataIndex: 'test1',
|
|
91
91
|
key: 'test1',
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
render: function (text, record, index) {
|
|
93
|
+
return (React.createElement(Input, { value: text, onPaste: function (e) {
|
|
94
|
+
var _a;
|
|
95
|
+
(_a = tableHandleRef.current) === null || _a === void 0 ? void 0 : _a.onPasteHandle(e, {
|
|
96
|
+
index: index,
|
|
97
|
+
dataIndex: 'test1',
|
|
98
|
+
record: record,
|
|
99
|
+
});
|
|
100
|
+
} }));
|
|
101
|
+
},
|
|
94
102
|
},
|
|
95
103
|
{
|
|
96
104
|
title: i18next.t('测试列2'),
|
|
@@ -78,6 +78,8 @@ function ProEditTable(props) {
|
|
|
78
78
|
onEditableSaveHandle: onEditableSaveHandle,
|
|
79
79
|
scrollTo: innerTableHandleRef.current.scrollTo,
|
|
80
80
|
setCustomSortHandle: innerTableHandleRef.current.setCustomSortHandle,
|
|
81
|
+
setTableScroll: innerTableHandleRef.current.setTableScroll,
|
|
82
|
+
onPasteHandle: innerTableHandleRef.current.onPasteHandle,
|
|
81
83
|
}); });
|
|
82
84
|
return (React.createElement(Table, __assign({ rowKey: rowKey, dataSource: dataSource, columns: tableColumns, hideAddIcon: !showAddIcon, hideDelIcon: !showDelIcon, onAddAndDelHandle: needAddAndDel ? onAddAndDelHandle : undefined, onMoveRow: isMove ? onMoveRowHandle : undefined, onEditableSave: isEdit ? onEditableSaveHandle : undefined, tableHandleRef: innerTableHandleRef, onTableChange: isPaste ? onBatchPasteHandle : undefined, rowSelection: isChoice ? rowSelection : undefined, onChange: onNativeChange }, restProps)));
|
|
83
85
|
}
|
|
@@ -31,6 +31,10 @@ export interface IEditableConfig {
|
|
|
31
31
|
precisionHandle?: (record: any) => number;
|
|
32
32
|
[props: string]: any;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* 数据转换 将粘贴过来的数据格式化处理
|
|
36
|
+
*/
|
|
37
|
+
export declare function transformData(data: string, config: any): any;
|
|
34
38
|
interface IEditableCellProps {
|
|
35
39
|
title: React.ReactNode;
|
|
36
40
|
index?: number;
|
|
@@ -68,7 +68,7 @@ import { INNER_PARENT_ROW_KEY_NO, INNER_PARENT_ROW_KEY } from './constants';
|
|
|
68
68
|
/**
|
|
69
69
|
* 数据转换 将粘贴过来的数据格式化处理
|
|
70
70
|
*/
|
|
71
|
-
function transformData(data, config) {
|
|
71
|
+
export function transformData(data, config) {
|
|
72
72
|
var newData = data;
|
|
73
73
|
if (!config) {
|
|
74
74
|
return newData;
|
|
@@ -70,7 +70,7 @@ import { ERROR_TD_CLASSNAME } from './';
|
|
|
70
70
|
import TableDynamic from './table-dynamic';
|
|
71
71
|
// import TableSummary from './table-summary';
|
|
72
72
|
import TableEnhanceRow from './table-enhance-row';
|
|
73
|
-
import TableEnhanceCell from './table-enhance-cell';
|
|
73
|
+
import TableEnhanceCell, { transformData } from './table-enhance-cell';
|
|
74
74
|
import TableResizableTitle from './table-resizable-title';
|
|
75
75
|
import useColumns, { setDynamicKey, getStorage, } from './hooks/useColumns';
|
|
76
76
|
import useSelectSubtotal from './hooks/useSelectSubtotal';
|
|
@@ -936,121 +936,183 @@ function Table(props) {
|
|
|
936
936
|
/**
|
|
937
937
|
* 表格暴露方法给外部使用
|
|
938
938
|
*/
|
|
939
|
-
useImperativeHandle(tableHandleRef, function () {
|
|
940
|
-
|
|
941
|
-
validate: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
942
|
-
return __generator(this, function (_a) {
|
|
943
|
-
switch (_a.label) {
|
|
944
|
-
case 0:
|
|
945
|
-
clearErrorClass();
|
|
946
|
-
return [4 /*yield*/, tableValidate(dataSource, mergeColumns, {
|
|
947
|
-
getCurrentTable: getCurrentTable,
|
|
948
|
-
rowSelection: props.rowSelection,
|
|
949
|
-
expandable: props.expandable,
|
|
950
|
-
tableName: tableName,
|
|
951
|
-
showInnerPagination: showInnerPagination,
|
|
952
|
-
setCurrent: setCurrent,
|
|
953
|
-
pageSize: pageSize,
|
|
954
|
-
virtualTableKey: virtualTableKey,
|
|
955
|
-
rowKey: props.rowKey,
|
|
956
|
-
scrollTo: scrollTo,
|
|
957
|
-
})];
|
|
958
|
-
case 1:
|
|
959
|
-
_a.sent();
|
|
960
|
-
return [2 /*return*/];
|
|
961
|
-
}
|
|
962
|
-
});
|
|
963
|
-
}); },
|
|
964
|
-
/**自定义错误提示数据 */
|
|
965
|
-
customizeDataValidate: function (isDataItemValidate) { return __awaiter(_this, void 0, void 0, function () {
|
|
966
|
-
return __generator(this, function (_a) {
|
|
967
|
-
switch (_a.label) {
|
|
968
|
-
case 0:
|
|
969
|
-
clearErrorClass();
|
|
970
|
-
return [4 /*yield*/, tableValidate(dataSource, mergeColumns, {
|
|
971
|
-
getCurrentTable: getCurrentTable,
|
|
972
|
-
rowSelection: props.rowSelection,
|
|
973
|
-
expandable: props.expandable,
|
|
974
|
-
tableName: tableName,
|
|
975
|
-
showInnerPagination: showInnerPagination,
|
|
976
|
-
setCurrent: setCurrent,
|
|
977
|
-
pageSize: pageSize,
|
|
978
|
-
virtualTableKey: virtualTableKey,
|
|
979
|
-
rowKey: props.rowKey,
|
|
980
|
-
scrollTo: scrollTo,
|
|
981
|
-
}, isDataItemValidate)];
|
|
982
|
-
case 1:
|
|
983
|
-
_a.sent();
|
|
984
|
-
return [2 /*return*/];
|
|
985
|
-
}
|
|
986
|
-
});
|
|
987
|
-
}); },
|
|
988
|
-
/** 获取当前表格 */
|
|
989
|
-
getCurrentTable: function () {
|
|
990
|
-
return getCurrentTable();
|
|
991
|
-
},
|
|
992
|
-
/** 移除错误样式 */
|
|
993
|
-
clearErrorClass: clearErrorClass,
|
|
994
|
-
/** 暴露内部分页提供给外部的一些方法 */
|
|
995
|
-
getCurrentPage: function () {
|
|
996
|
-
return currentPage.current;
|
|
997
|
-
},
|
|
998
|
-
/** 对于自定义render 可以通过这个方法 得到真正更改的行数据 */
|
|
999
|
-
getRealyIndex: function (index) {
|
|
939
|
+
useImperativeHandle(tableHandleRef, function () {
|
|
940
|
+
var getRealyIndex = function (index) {
|
|
1000
941
|
if (currentPage.current && showInnerPagination) {
|
|
1001
942
|
return ((currentPage.current.page - 1) * currentPage.current.pageSize + index);
|
|
1002
943
|
}
|
|
1003
944
|
return index;
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
945
|
+
};
|
|
946
|
+
return {
|
|
947
|
+
/** 错误提示 */
|
|
948
|
+
validate: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
949
|
+
return __generator(this, function (_a) {
|
|
950
|
+
switch (_a.label) {
|
|
951
|
+
case 0:
|
|
952
|
+
clearErrorClass();
|
|
953
|
+
return [4 /*yield*/, tableValidate(dataSource, mergeColumns, {
|
|
954
|
+
getCurrentTable: getCurrentTable,
|
|
955
|
+
rowSelection: props.rowSelection,
|
|
956
|
+
expandable: props.expandable,
|
|
957
|
+
tableName: tableName,
|
|
958
|
+
showInnerPagination: showInnerPagination,
|
|
959
|
+
setCurrent: setCurrent,
|
|
960
|
+
pageSize: pageSize,
|
|
961
|
+
virtualTableKey: virtualTableKey,
|
|
962
|
+
rowKey: props.rowKey,
|
|
963
|
+
scrollTo: scrollTo,
|
|
964
|
+
})];
|
|
965
|
+
case 1:
|
|
966
|
+
_a.sent();
|
|
967
|
+
return [2 /*return*/];
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
}); },
|
|
971
|
+
/**自定义错误提示数据 */
|
|
972
|
+
customizeDataValidate: function (isDataItemValidate) { return __awaiter(_this, void 0, void 0, function () {
|
|
973
|
+
return __generator(this, function (_a) {
|
|
974
|
+
switch (_a.label) {
|
|
975
|
+
case 0:
|
|
976
|
+
clearErrorClass();
|
|
977
|
+
return [4 /*yield*/, tableValidate(dataSource, mergeColumns, {
|
|
978
|
+
getCurrentTable: getCurrentTable,
|
|
979
|
+
rowSelection: props.rowSelection,
|
|
980
|
+
expandable: props.expandable,
|
|
981
|
+
tableName: tableName,
|
|
982
|
+
showInnerPagination: showInnerPagination,
|
|
983
|
+
setCurrent: setCurrent,
|
|
984
|
+
pageSize: pageSize,
|
|
985
|
+
virtualTableKey: virtualTableKey,
|
|
986
|
+
rowKey: props.rowKey,
|
|
987
|
+
scrollTo: scrollTo,
|
|
988
|
+
}, isDataItemValidate)];
|
|
989
|
+
case 1:
|
|
990
|
+
_a.sent();
|
|
991
|
+
return [2 /*return*/];
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
}); },
|
|
995
|
+
/** 获取当前表格 */
|
|
996
|
+
getCurrentTable: function () {
|
|
997
|
+
return getCurrentTable();
|
|
998
|
+
},
|
|
999
|
+
/** 移除错误样式 */
|
|
1000
|
+
clearErrorClass: clearErrorClass,
|
|
1001
|
+
/** 暴露内部分页提供给外部的一些方法 */
|
|
1002
|
+
getCurrentPage: function () {
|
|
1003
|
+
return currentPage.current;
|
|
1004
|
+
},
|
|
1005
|
+
/** 对于自定义render 可以通过这个方法 得到真正更改的行数据 */
|
|
1006
|
+
getRealyIndex: getRealyIndex,
|
|
1007
|
+
/** 获取自定义列配置当前配置 */
|
|
1008
|
+
getColumns: function () {
|
|
1009
|
+
var columns = [];
|
|
1010
|
+
mergeColumns.forEach(function (column) {
|
|
1011
|
+
if (column.dataIndex) {
|
|
1012
|
+
columns.push({
|
|
1013
|
+
dataIndex: column.dataIndex || column.key,
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
return columns;
|
|
1018
|
+
},
|
|
1019
|
+
/** 虚拟滚动 滚动到顶部方法 */
|
|
1020
|
+
scrollTo: function (obj) {
|
|
1021
|
+
scrollTo(__assign({ vid: virtualTableKey }, obj));
|
|
1022
|
+
},
|
|
1023
|
+
/** 获取动态列配置信息 */
|
|
1024
|
+
getStorage: function () {
|
|
1025
|
+
var _a;
|
|
1026
|
+
return (getStorage(showColumnDynamicKey) ||
|
|
1027
|
+
((_a = newColumns === null || newColumns === void 0 ? void 0 : newColumns.map) === null || _a === void 0 ? void 0 : _a.call(newColumns, function (item) { return ({
|
|
1028
|
+
dataIndex: item.dataIndex,
|
|
1029
|
+
key: item.key,
|
|
1030
|
+
hideColumn: item.hideColumn,
|
|
1031
|
+
width: item.width,
|
|
1032
|
+
}); })));
|
|
1033
|
+
},
|
|
1034
|
+
/** 手动清空排序条件 */
|
|
1035
|
+
customSortClearHandle: function () {
|
|
1036
|
+
setSortDataSource(null);
|
|
1037
|
+
setCustomOrder(null);
|
|
1038
|
+
},
|
|
1039
|
+
/** 手动设置排序条件 */
|
|
1040
|
+
setCustomSortHandle: function (customSort) {
|
|
1041
|
+
setCustomOrder(customSort);
|
|
1042
|
+
},
|
|
1043
|
+
/** 获取过滤后的数据 */
|
|
1044
|
+
getFilterRecords: function () {
|
|
1045
|
+
var currentDataSource = currentDataSourceRef.current;
|
|
1046
|
+
if (Array.isArray(currentDataSource)) {
|
|
1047
|
+
// 复制整列逻辑加上过滤、排序后的逻辑
|
|
1048
|
+
var filterResultDataSource = getFilterRecords(currentDataSource, filterSearchValuesRef.current);
|
|
1049
|
+
return filterResultDataSource;
|
|
1013
1050
|
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1051
|
+
return currentDataSource;
|
|
1052
|
+
},
|
|
1053
|
+
removeScrollPosition: removeScrollPosition,
|
|
1054
|
+
setTableScroll: setTableScroll,
|
|
1055
|
+
onPasteHandle: function (e, _a) {
|
|
1056
|
+
var index = _a.index, dataIndex = _a.dataIndex, record = _a.record;
|
|
1057
|
+
var text = e.clipboardData.getData('text/plain');
|
|
1058
|
+
// 首先判断是否有换行符
|
|
1059
|
+
if (text) {
|
|
1060
|
+
var innerIndex = getRealyIndex(index);
|
|
1061
|
+
// 兼容多种换行模式
|
|
1062
|
+
var textList = [];
|
|
1063
|
+
if (text.indexOf('\r\n') !== -1) {
|
|
1064
|
+
textList = text.split('\r\n');
|
|
1065
|
+
}
|
|
1066
|
+
else if (text.indexOf('\r') !== -1) {
|
|
1067
|
+
textList = text.split('\r');
|
|
1068
|
+
}
|
|
1069
|
+
else if (text.indexOf('\n') !== -1) {
|
|
1070
|
+
textList = text.split('\n');
|
|
1071
|
+
}
|
|
1072
|
+
if (textList.length > 0) {
|
|
1073
|
+
var currentColumnIndex_1 = newColumns.findIndex(function (column) { return (column === null || column === void 0 ? void 0 : column.dataIndex) === dataIndex; });
|
|
1074
|
+
// 去掉最后的空字符
|
|
1075
|
+
if (textList[textList.length - 1] === '') {
|
|
1076
|
+
textList.pop();
|
|
1077
|
+
}
|
|
1078
|
+
if (textList.length === 1 && textList[0].indexOf('\t') === -1) {
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
e.preventDefault();
|
|
1082
|
+
// 说明有换行
|
|
1083
|
+
var resultTextList = textList.map(function (textItem) {
|
|
1084
|
+
var resultItemList = textItem.split('\t');
|
|
1085
|
+
var result = {};
|
|
1086
|
+
resultItemList.forEach(function (resultItem, index) {
|
|
1087
|
+
var _a;
|
|
1088
|
+
var config = null;
|
|
1089
|
+
try {
|
|
1090
|
+
config = newColumns[currentColumnIndex_1 + index];
|
|
1091
|
+
}
|
|
1092
|
+
catch (err) {
|
|
1093
|
+
console.error("table paste error", err);
|
|
1094
|
+
}
|
|
1095
|
+
if (resultItem === '' || resultItem == null) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
if (index === 0) {
|
|
1099
|
+
result[dataIndex] = transformData(resultItem, config);
|
|
1100
|
+
}
|
|
1101
|
+
else {
|
|
1102
|
+
var key = (_a = newColumns[currentColumnIndex_1 + index]) === null || _a === void 0 ? void 0 : _a.dataIndex;
|
|
1103
|
+
if (typeof key === 'string') {
|
|
1104
|
+
result[key] = transformData(resultItem, config);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
return result;
|
|
1109
|
+
});
|
|
1110
|
+
onTableChange && onTableChange(resultTextList, innerIndex, record);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
},
|
|
1114
|
+
};
|
|
1115
|
+
});
|
|
1054
1116
|
var tableResizableTitle = useMemo(function () {
|
|
1055
1117
|
return {
|
|
1056
1118
|
header: {
|