ztxkui 4.2.23-553 → 4.2.23-554
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/dist/UI/Table/EditTable.js +29 -1
- package/dist/components/Input/AntInputModal.d.ts +8 -0
- package/dist/components/Input/AntInputModal.js +79 -0
- package/dist/components/Input/hooks/index.d.ts +2 -0
- package/dist/components/Input/hooks/index.js +1 -0
- package/dist/components/Input/hooks/useInputModal.d.ts +53 -0
- package/dist/components/Input/hooks/useInputModal.js +105 -0
- package/dist/components/Input/input.js +29 -10
- package/dist/components/Table/table-enhance-cell.d.ts +6 -0
- package/dist/components/Table/table-enhance-cell.js +55 -5
- package/package.json +1 -1
|
@@ -90,7 +90,35 @@ function useColumns(tableHandleRef) {
|
|
|
90
90
|
dataIndex: 'test1',
|
|
91
91
|
key: 'test1',
|
|
92
92
|
render: function (text, record, index) {
|
|
93
|
-
return (React.createElement(Input, { value: text,
|
|
93
|
+
return (React.createElement(Input, { value: text, onChange: function (e) {
|
|
94
|
+
var _a;
|
|
95
|
+
var newRecord = {
|
|
96
|
+
test1: e.target.value,
|
|
97
|
+
};
|
|
98
|
+
(_a = tableHandleRef.current) === null || _a === void 0 ? void 0 : _a.onEditableSaveHandle(newRecord, index);
|
|
99
|
+
}, onPaste: function (e) {
|
|
100
|
+
var _a;
|
|
101
|
+
(_a = tableHandleRef.current) === null || _a === void 0 ? void 0 : _a.onPasteHandle(e, {
|
|
102
|
+
index: index,
|
|
103
|
+
dataIndex: 'test1',
|
|
104
|
+
record: record,
|
|
105
|
+
});
|
|
106
|
+
} }));
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
title: i18next.t('测试列11122'),
|
|
111
|
+
width: 100,
|
|
112
|
+
dataIndex: 'test111122',
|
|
113
|
+
key: 'test111122',
|
|
114
|
+
render: function (text, record, index) {
|
|
115
|
+
return (React.createElement(Input.TextArea, { value: text, onChange: function (e) {
|
|
116
|
+
var _a;
|
|
117
|
+
var newRecord = {
|
|
118
|
+
test111122: e.target.value,
|
|
119
|
+
};
|
|
120
|
+
(_a = tableHandleRef.current) === null || _a === void 0 ? void 0 : _a.onEditableSaveHandle(newRecord, index);
|
|
121
|
+
}, onPaste: function (e) {
|
|
94
122
|
var _a;
|
|
95
123
|
(_a = tableHandleRef.current) === null || _a === void 0 ? void 0 : _a.onPasteHandle(e, {
|
|
96
124
|
index: index,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { InputProps } from 'antd';
|
|
3
|
+
interface InputModalProps extends Omit<InputProps, 'onChange' | 'onBlur'> {
|
|
4
|
+
onChange?: InputProps['onChange'];
|
|
5
|
+
onBlur?: InputProps['onBlur'];
|
|
6
|
+
}
|
|
7
|
+
declare const InputModal: React.FC<InputModalProps>;
|
|
8
|
+
export default InputModal;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 这里重构一份的原因是 因为Table组件里面的编辑列使用的是 AntInput的组件
|
|
25
|
+
* 担心会有问题,这里用Antd的Input组件来代替
|
|
26
|
+
*/
|
|
27
|
+
import i18next from 'ztxkutils/dist/i18next';
|
|
28
|
+
import React from 'react';
|
|
29
|
+
import { Modal, Button } from '../../index.build';
|
|
30
|
+
import { Input } from 'antd';
|
|
31
|
+
var InputModal = function (_a) {
|
|
32
|
+
var onDoubleClick = _a.onDoubleClick, onChange = _a.onChange, onBlur = _a.onBlur, props = __rest(_a, ["onDoubleClick", "onChange", "onBlur"]);
|
|
33
|
+
var isDoubleClick = React.useRef(false);
|
|
34
|
+
var _b = React.useState(false), visible = _b[0], setVisible = _b[1];
|
|
35
|
+
var _c = React.useState(''), modalValue = _c[0], setModalValue = _c[1];
|
|
36
|
+
var isModalDisabled = React.useMemo(function () {
|
|
37
|
+
return props.disabled || props.readOnly;
|
|
38
|
+
}, [props.disabled, props.readOnly]);
|
|
39
|
+
var handleDoubleClick = function (e) {
|
|
40
|
+
if (onDoubleClick) {
|
|
41
|
+
onDoubleClick(e);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
isDoubleClick.current = true;
|
|
45
|
+
setVisible(true);
|
|
46
|
+
setModalValue(props.value);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var close = function () {
|
|
50
|
+
setVisible(false);
|
|
51
|
+
isDoubleClick.current = false;
|
|
52
|
+
};
|
|
53
|
+
var handleSure = function () {
|
|
54
|
+
// 模拟结构
|
|
55
|
+
var e = {
|
|
56
|
+
target: {
|
|
57
|
+
value: modalValue,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
onChange && onChange(e);
|
|
61
|
+
onBlur && onBlur(e);
|
|
62
|
+
close();
|
|
63
|
+
};
|
|
64
|
+
var handleClear = function () {
|
|
65
|
+
setModalValue('');
|
|
66
|
+
};
|
|
67
|
+
var handleBlur = function (e) {
|
|
68
|
+
if (isDoubleClick.current)
|
|
69
|
+
return;
|
|
70
|
+
onBlur && onBlur(e.target.value);
|
|
71
|
+
};
|
|
72
|
+
return (React.createElement(React.Fragment, null,
|
|
73
|
+
React.createElement(Input, __assign({}, props, { onBlur: handleBlur, onDoubleClick: handleDoubleClick, onChange: function (e) { return onChange && onChange(e); } })),
|
|
74
|
+
React.createElement(Modal, { title: isModalDisabled ? i18next.t('内容') : i18next.t('请输入内容'), visible: visible, loading: false, destroyOnClose: true, onCancel: close, footer: isModalDisabled ? undefined : (React.createElement(React.Fragment, null,
|
|
75
|
+
React.createElement(Button, { onClick: handleClear }, i18next.t('清空内容')),
|
|
76
|
+
React.createElement(Button, { type: "primary", onClick: handleSure }, i18next.t('确认')))) },
|
|
77
|
+
React.createElement(Input.TextArea, { value: modalValue, readOnly: isModalDisabled, autoFocus: true, autoSize: { minRows: 10, maxRows: 50 }, onChange: function (e) { return setModalValue(e.target.value); } }))));
|
|
78
|
+
};
|
|
79
|
+
export default InputModal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as useInputModal } from './useInputModal';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface UseInputModalOptions {
|
|
3
|
+
/** 确认时的回调 */
|
|
4
|
+
onConfirm?: (value: string, event?: {
|
|
5
|
+
target: {
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
}) => void;
|
|
9
|
+
/** 取消时的回调 */
|
|
10
|
+
onCancel?: () => void;
|
|
11
|
+
/** 是否禁用(只读模式) */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Modal 标题 */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** TextArea 最小行数 */
|
|
16
|
+
minRows?: number;
|
|
17
|
+
/** TextArea 最大行数 */
|
|
18
|
+
maxRows?: number;
|
|
19
|
+
/** 是否使用事件模式(antd 风格,回调参数为 { target: { value } }) */
|
|
20
|
+
eventMode?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface UseInputModalReturn {
|
|
23
|
+
/** 是否显示 Modal */
|
|
24
|
+
visible: boolean;
|
|
25
|
+
/** 当前 Modal 中的值 */
|
|
26
|
+
modalValue: string;
|
|
27
|
+
/** 是否为双击触发的打开(用于防止 onBlur 重复触发) */
|
|
28
|
+
isDoubleClick: React.MutableRefObject<boolean>;
|
|
29
|
+
/** 打开 Modal */
|
|
30
|
+
open: (initialValue?: string) => void;
|
|
31
|
+
/** 关闭 Modal */
|
|
32
|
+
close: () => void;
|
|
33
|
+
/** 设置 Modal 值 */
|
|
34
|
+
setModalValue: React.Dispatch<React.SetStateAction<string>>;
|
|
35
|
+
/** 清空 Modal 值 */
|
|
36
|
+
clearValue: () => void;
|
|
37
|
+
/** 确认操作 */
|
|
38
|
+
confirm: () => void;
|
|
39
|
+
/** 处理双击事件 */
|
|
40
|
+
handleDoubleClick: (e: React.MouseEvent, currentValue?: string) => void;
|
|
41
|
+
/** 处理失焦事件(自动跳过双击触发的情况) */
|
|
42
|
+
handleBlur: (e: React.FocusEvent | any, originalHandler?: (value: string | any) => void) => void;
|
|
43
|
+
/** 渲染 Modal 组件 */
|
|
44
|
+
renderModal: () => React.ReactNode;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 输入弹窗 Hook
|
|
48
|
+
* @description 封装双击输入框弹出 Modal 编辑的功能
|
|
49
|
+
* @param options 配置选项
|
|
50
|
+
* @returns Modal 状态和操作方法
|
|
51
|
+
*/
|
|
52
|
+
declare function useInputModal(options?: UseInputModalOptions): UseInputModalReturn;
|
|
53
|
+
export default useInputModal;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import i18next from 'ztxkutils/dist/i18next';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Modal, Button, Input } from '../../../index.build';
|
|
4
|
+
/**
|
|
5
|
+
* 输入弹窗 Hook
|
|
6
|
+
* @description 封装双击输入框弹出 Modal 编辑的功能
|
|
7
|
+
* @param options 配置选项
|
|
8
|
+
* @returns Modal 状态和操作方法
|
|
9
|
+
*/
|
|
10
|
+
function useInputModal(options) {
|
|
11
|
+
if (options === void 0) { options = {}; }
|
|
12
|
+
var onConfirm = options.onConfirm, onCancel = options.onCancel, _a = options.disabled, disabled = _a === void 0 ? false : _a, title = options.title, _b = options.minRows, minRows = _b === void 0 ? 10 : _b, _c = options.maxRows, maxRows = _c === void 0 ? 50 : _c, _d = options.eventMode, eventMode = _d === void 0 ? false : _d;
|
|
13
|
+
var _e = React.useState(false), visible = _e[0], setVisible = _e[1];
|
|
14
|
+
var _f = React.useState(''), modalValue = _f[0], setModalValue = _f[1];
|
|
15
|
+
var isDoubleClick = React.useRef(false);
|
|
16
|
+
var open = React.useCallback(function (initialValue) {
|
|
17
|
+
setModalValue(initialValue !== null && initialValue !== void 0 ? initialValue : '');
|
|
18
|
+
isDoubleClick.current = true;
|
|
19
|
+
setVisible(true);
|
|
20
|
+
}, []);
|
|
21
|
+
var close = React.useCallback(function () {
|
|
22
|
+
setVisible(false);
|
|
23
|
+
isDoubleClick.current = false;
|
|
24
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
25
|
+
}, [onCancel]);
|
|
26
|
+
var clearValue = React.useCallback(function () {
|
|
27
|
+
setModalValue('');
|
|
28
|
+
}, []);
|
|
29
|
+
var confirm = React.useCallback(function () {
|
|
30
|
+
if (eventMode) {
|
|
31
|
+
// 事件模式:模拟 antd 的 event 对象
|
|
32
|
+
var event_1 = {
|
|
33
|
+
target: {
|
|
34
|
+
value: modalValue,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(modalValue, event_1);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// 值模式:直接传递值
|
|
41
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(modalValue);
|
|
42
|
+
}
|
|
43
|
+
setVisible(false);
|
|
44
|
+
}, [modalValue, onConfirm, eventMode]);
|
|
45
|
+
/**
|
|
46
|
+
* 处理双击事件
|
|
47
|
+
* @param e 鼠标事件
|
|
48
|
+
* @param currentValue 当前输入框的值
|
|
49
|
+
* @param originalHandler 原始的双击处理函数(如果存在则调用,否则打开 Modal)
|
|
50
|
+
*/
|
|
51
|
+
var handleDoubleClick = React.useCallback(function (e, currentValue) {
|
|
52
|
+
open(currentValue);
|
|
53
|
+
}, [open]);
|
|
54
|
+
/**
|
|
55
|
+
* 处理失焦事件
|
|
56
|
+
* @description 自动跳过双击触发的情况,避免 Modal 打开时触发失焦
|
|
57
|
+
* @param e 事件对象
|
|
58
|
+
* @param originalHandler 原始的失焦处理函数
|
|
59
|
+
*/
|
|
60
|
+
var handleBlur = React.useCallback(function (e, originalHandler) {
|
|
61
|
+
var _a;
|
|
62
|
+
// 如果是双击触发的打开,跳过 onBlur
|
|
63
|
+
if (isDoubleClick.current)
|
|
64
|
+
return;
|
|
65
|
+
if (originalHandler) {
|
|
66
|
+
// 根据事件模式决定传递的参数格式
|
|
67
|
+
if (eventMode) {
|
|
68
|
+
originalHandler(e);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
originalHandler((_a = e.target) === null || _a === void 0 ? void 0 : _a.value);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}, [eventMode]);
|
|
75
|
+
var renderModal = React.useCallback(function () {
|
|
76
|
+
return (React.createElement(Modal, { title: title !== null && title !== void 0 ? title : (disabled ? i18next.t('内容') : i18next.t('请输入内容')), visible: visible, loading: false, destroyOnClose: true, onCancel: close, footer: disabled ? undefined : (React.createElement(React.Fragment, null,
|
|
77
|
+
React.createElement(Button, { onClick: clearValue }, i18next.t('清空内容')),
|
|
78
|
+
React.createElement(Button, { type: "primary", onClick: confirm }, i18next.t('确认')))) },
|
|
79
|
+
React.createElement(Input.TextArea, { value: modalValue, readOnly: disabled, autoFocus: true, autoSize: { minRows: minRows, maxRows: maxRows }, onChange: function (e) { return setModalValue(e.target.value); } })));
|
|
80
|
+
}, [
|
|
81
|
+
visible,
|
|
82
|
+
modalValue,
|
|
83
|
+
disabled,
|
|
84
|
+
title,
|
|
85
|
+
minRows,
|
|
86
|
+
maxRows,
|
|
87
|
+
close,
|
|
88
|
+
clearValue,
|
|
89
|
+
confirm,
|
|
90
|
+
]);
|
|
91
|
+
return {
|
|
92
|
+
visible: visible,
|
|
93
|
+
modalValue: modalValue,
|
|
94
|
+
isDoubleClick: isDoubleClick,
|
|
95
|
+
open: open,
|
|
96
|
+
close: close,
|
|
97
|
+
setModalValue: setModalValue,
|
|
98
|
+
clearValue: clearValue,
|
|
99
|
+
confirm: confirm,
|
|
100
|
+
handleDoubleClick: handleDoubleClick,
|
|
101
|
+
handleBlur: handleBlur,
|
|
102
|
+
renderModal: renderModal,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export default useInputModal;
|
|
@@ -29,8 +29,12 @@ import useLastest from '../utils/useLastest';
|
|
|
29
29
|
import InputQuill from './InputQuill';
|
|
30
30
|
import InputQuillRead from './InputQuillRead';
|
|
31
31
|
import InputModal from './InputModal';
|
|
32
|
+
import AntInputModal from './AntInputModal';
|
|
33
|
+
import { useTableContext } from '../Table/table-context';
|
|
34
|
+
import { useInputModal } from './hooks';
|
|
32
35
|
function Input(props) {
|
|
33
|
-
var doubleClickReadOnly = props.doubleClickReadOnly, onDoubleClick = props.onDoubleClick, onBlur = props.onBlur, isAsrInput = props.isAsrInput, asrCloseTime = props.asrCloseTime, _a = props.allowSpace, allowSpace = _a === void 0 ? false : _a, restProps = __rest(props, ["doubleClickReadOnly", "onDoubleClick", "onBlur", "isAsrInput", "asrCloseTime", "allowSpace"]);
|
|
36
|
+
var doubleClickReadOnly = props.doubleClickReadOnly, onDoubleClick = props.onDoubleClick, onBlur = props.onBlur, isAsrInput = props.isAsrInput, asrCloseTime = props.asrCloseTime, _a = props.allowSpace, allowSpace = _a === void 0 ? false : _a, isInputModal = props.isInputModal, restProps = __rest(props, ["doubleClickReadOnly", "onDoubleClick", "onBlur", "isAsrInput", "asrCloseTime", "allowSpace", "isInputModal"]);
|
|
37
|
+
var inTable = useTableContext().inTable;
|
|
34
38
|
var _b = useState(!!doubleClickReadOnly), readOnly = _b[0], setReadOnly = _b[1];
|
|
35
39
|
var onBlurHandle = function (e) {
|
|
36
40
|
if (doubleClickReadOnly) {
|
|
@@ -41,12 +45,6 @@ function Input(props) {
|
|
|
41
45
|
onBlur && onBlur(e);
|
|
42
46
|
props.onChange && props.onChange(e);
|
|
43
47
|
};
|
|
44
|
-
var onDoubleClickHandle = function (e) {
|
|
45
|
-
if (doubleClickReadOnly) {
|
|
46
|
-
setReadOnly(false);
|
|
47
|
-
}
|
|
48
|
-
onDoubleClick && onDoubleClick(e);
|
|
49
|
-
};
|
|
50
48
|
// 阻止在input设置allowClear后,在input外部鼠标点击,然后移入input框中松开鼠标时候,input框会聚焦
|
|
51
49
|
var onMouseUpHandle = function (e) {
|
|
52
50
|
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
@@ -60,9 +58,29 @@ function Input(props) {
|
|
|
60
58
|
// 受控模式
|
|
61
59
|
onChangeLastest.current && onChangeLastest.current(e);
|
|
62
60
|
}, [onChangeLastest]);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
var showInputModal = isInputModal || inTable;
|
|
62
|
+
var inputModal = useInputModal({
|
|
63
|
+
disabled: props.disabled || props.readOnly,
|
|
64
|
+
eventMode: true,
|
|
65
|
+
onConfirm: function (value, event) {
|
|
66
|
+
// 受控模式
|
|
67
|
+
onChangeLastest.current && onChangeLastest.current(event);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
var onDoubleClickHandle = function (e) {
|
|
71
|
+
if (doubleClickReadOnly) {
|
|
72
|
+
setReadOnly(false);
|
|
73
|
+
}
|
|
74
|
+
if (showInputModal) {
|
|
75
|
+
inputModal.handleDoubleClick(e, props.value);
|
|
76
|
+
}
|
|
77
|
+
onDoubleClick && onDoubleClick(e);
|
|
78
|
+
};
|
|
79
|
+
return (React.createElement(React.Fragment, null,
|
|
80
|
+
isAsrInput && !props.readOnly && !props.disabled ? (React.createElement("div", { className: "asr-input", style: { display: 'inline-block' } },
|
|
81
|
+
React.createElement(Asr, { recordTextCallback: recordTextCallback, timeout: asrCloseTime, className: "asr-input--btn" }),
|
|
82
|
+
React.createElement(AntInput, __assign({ onMouseUp: onMouseUpHandle, onBlur: onBlurHandle, onDoubleClick: onDoubleClickHandle, readOnly: readOnly }, restProps)))) : (React.createElement(AntInput, __assign({ onMouseUp: onMouseUpHandle, onBlur: onBlurHandle, onDoubleClick: onDoubleClickHandle, readOnly: readOnly }, restProps))),
|
|
83
|
+
showInputModal && inputModal.renderModal()));
|
|
66
84
|
}
|
|
67
85
|
var TextArea = React.forwardRef(function (props, ref) {
|
|
68
86
|
var _a = props.handleSize, handleSize = _a === void 0 ? true : _a, _b = props.autoSize, autoSize = _b === void 0 ? true : _b, className = props.className, isAsrInput = props.isAsrInput, asrCloseTime = props.asrCloseTime, resetProps = __rest(props, ["handleSize", "autoSize", "className", "isAsrInput", "asrCloseTime"]);
|
|
@@ -125,4 +143,5 @@ Input.Password = AntInput.Password;
|
|
|
125
143
|
Input.Quill = InputQuill;
|
|
126
144
|
Input.QuillRead = InputQuillRead;
|
|
127
145
|
Input.Modal = InputModal;
|
|
146
|
+
Input.AntInputModal = AntInputModal;
|
|
128
147
|
export default Input;
|
|
@@ -31,6 +31,12 @@ export interface IEditableConfig {
|
|
|
31
31
|
precisionHandle?: (record: any) => number;
|
|
32
32
|
[props: string]: any;
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* 将带有千分符、货币符号、百分号的字符串转换成数字
|
|
36
|
+
* @param value 待转换的字符串,如 "14,855.00"、"$1,234.56"、"50%"
|
|
37
|
+
* @returns 转换后的数字,转换失败返回 NaN
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseStringToNumber(value: string): number;
|
|
34
40
|
/**
|
|
35
41
|
* 数据转换 将粘贴过来的数据格式化处理
|
|
36
42
|
*/
|
|
@@ -65,11 +65,59 @@ import { ERROR_TD_CLASSNAME } from './index';
|
|
|
65
65
|
import { getInnerIndex } from './hooks/useInnerPagination';
|
|
66
66
|
import { exactRound } from 'ztxkutils/dist/tools';
|
|
67
67
|
import { INNER_PARENT_ROW_KEY_NO, INNER_PARENT_ROW_KEY } from './constants';
|
|
68
|
+
/**
|
|
69
|
+
* 将带有千分符、货币符号、百分号的字符串转换成数字
|
|
70
|
+
* @param value 待转换的字符串,如 "14,855.00"、"$1,234.56"、"50%"
|
|
71
|
+
* @returns 转换后的数字,转换失败返回 NaN
|
|
72
|
+
*/
|
|
73
|
+
export function parseStringToNumber(value) {
|
|
74
|
+
if (typeof value !== 'string') {
|
|
75
|
+
return NaN;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
// 去除首尾空格
|
|
79
|
+
var str = value.trim();
|
|
80
|
+
// 如果是空字符串,返回 NaN
|
|
81
|
+
if (!str) {
|
|
82
|
+
return NaN;
|
|
83
|
+
}
|
|
84
|
+
// 记录是否为百分比
|
|
85
|
+
var isPercent = false;
|
|
86
|
+
if (str.endsWith('%')) {
|
|
87
|
+
isPercent = true;
|
|
88
|
+
str = str.slice(0, -1).trim();
|
|
89
|
+
}
|
|
90
|
+
// 移除千分符(逗号)和货币符号
|
|
91
|
+
// 千分符的逗号只出现在数字之间,小数点前的逗号
|
|
92
|
+
str = str.replace(/,/g, '');
|
|
93
|
+
// 移除常见货币符号
|
|
94
|
+
str = str.replace(/^[¥$€£¥]+\s*/g, '');
|
|
95
|
+
// 移除可能存在的空格
|
|
96
|
+
str = str.trim();
|
|
97
|
+
// 尝试转换为数字
|
|
98
|
+
var num = parseFloat(str);
|
|
99
|
+
if (isNaN(num)) {
|
|
100
|
+
return NaN;
|
|
101
|
+
}
|
|
102
|
+
// 如果是百分比,需要除以 100
|
|
103
|
+
return isPercent ? num / 100 : num;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error(i18next.t('数字转换失败'), error);
|
|
107
|
+
return NaN;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
68
110
|
/**
|
|
69
111
|
* 数据转换 将粘贴过来的数据格式化处理
|
|
70
112
|
*/
|
|
71
113
|
export function transformData(data, config) {
|
|
72
114
|
var newData = data;
|
|
115
|
+
// 如果newData能转换成数字,就转换成数字
|
|
116
|
+
// 如果newData不能转换成数字,不做处理
|
|
117
|
+
var parsedNumber = parseStringToNumber(newData);
|
|
118
|
+
if (!isNaN(parsedNumber)) {
|
|
119
|
+
newData = parsedNumber;
|
|
120
|
+
}
|
|
73
121
|
if (!config) {
|
|
74
122
|
return newData;
|
|
75
123
|
}
|
|
@@ -296,7 +344,7 @@ var TableEnhanceCell = function (_a) {
|
|
|
296
344
|
return null;
|
|
297
345
|
}
|
|
298
346
|
if (!editableConfig) {
|
|
299
|
-
return (React.createElement(
|
|
347
|
+
return (React.createElement(ZtInput.AntInputModal, { autoComplete: "new-password", maxLength: 50, onPressEnter: save, onBlur: save, allowClear: true, onPaste: onPasteHandle, value: val, onMouseUp: function (e) {
|
|
300
348
|
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
301
349
|
},
|
|
302
350
|
// draggable
|
|
@@ -306,11 +354,12 @@ var TableEnhanceCell = function (_a) {
|
|
|
306
354
|
// e?.nativeEvent?.stopImmediatePropagation?.();
|
|
307
355
|
// }}
|
|
308
356
|
onChange: function (e) {
|
|
357
|
+
var _a, _b;
|
|
309
358
|
setVal(e.target.value);
|
|
310
359
|
removeErrorClass();
|
|
311
360
|
valueRef.current[dataIndex] = e.target.value;
|
|
312
361
|
if (!e.target.value) {
|
|
313
|
-
e.target.focus();
|
|
362
|
+
(_b = (_a = e.target).focus) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
314
363
|
}
|
|
315
364
|
} }));
|
|
316
365
|
}
|
|
@@ -453,7 +502,7 @@ var TableEnhanceCell = function (_a) {
|
|
|
453
502
|
} })));
|
|
454
503
|
}
|
|
455
504
|
else {
|
|
456
|
-
return (React.createElement(
|
|
505
|
+
return (React.createElement(ZtInput.AntInputModal, __assign({ autoComplete: "new-password", maxLength: 50 }, editableProps, { disabled: disabledResult, onPressEnter: save, onBlur: save, allowClear: true, onPaste: onPasteHandle, value: val, onMouseUp: function (e) {
|
|
457
506
|
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
458
507
|
},
|
|
459
508
|
// draggable
|
|
@@ -463,11 +512,12 @@ var TableEnhanceCell = function (_a) {
|
|
|
463
512
|
// e?.nativeEvent?.stopImmediatePropagation?.();
|
|
464
513
|
// }}
|
|
465
514
|
onChange: function (e) {
|
|
515
|
+
var _a, _b;
|
|
466
516
|
setVal(e.target.value);
|
|
467
517
|
valueRef.current[dataIndex] = e.target.value;
|
|
468
518
|
removeErrorClass();
|
|
469
|
-
if (!e.target.value) {
|
|
470
|
-
e.target.focus();
|
|
519
|
+
if (!e.target.value && e.target.focus) {
|
|
520
|
+
(_b = (_a = e.target).focus) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
471
521
|
}
|
|
472
522
|
} })));
|
|
473
523
|
}
|