ztxkui 10.0.25 → 10.0.27
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/DemoCom/SelectDemo.d.ts +3 -0
- package/dist/DemoCom/SelectDemo.js +20 -0
- package/dist/DemoCom/TableDemo.js +32 -6
- package/dist/components/EnhanceSelect/index.d.ts +2 -1
- package/dist/components/EnhanceSelect/index.js +37 -25
- package/dist/components/Table/hooks/useColumns.d.ts +7 -0
- package/dist/components/Table/hooks/useColumns.js +26 -2
- package/dist/components/Table/index.d.ts +2 -0
- package/dist/components/Table/table-menu.d.ts +7 -0
- package/dist/components/Table/table-menu.js +10 -0
- package/dist/components/Table/table.d.ts +9 -0
- package/dist/components/Table/table.js +30 -4
- package/package.json +2 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Select } from 'antd';
|
|
3
|
+
var Option = Select.Option;
|
|
4
|
+
var CustomSelect = function () {
|
|
5
|
+
var _a = useState(false), isMenuVisible = _a[0], setIsMenuVisible = _a[1];
|
|
6
|
+
var handleContextMenu = function (event) {
|
|
7
|
+
console.log('handleContextMenu');
|
|
8
|
+
event.preventDefault(); // 阻止浏览器默认的右键菜单
|
|
9
|
+
setIsMenuVisible(true);
|
|
10
|
+
// 根据需要在这里展示自定义的右键菜单
|
|
11
|
+
};
|
|
12
|
+
var hideMenu = function () {
|
|
13
|
+
setIsMenuVisible(false);
|
|
14
|
+
};
|
|
15
|
+
return (React.createElement("div", { onContextMenuCapture: handleContextMenu },
|
|
16
|
+
React.createElement(Select, { style: { width: 200 }, onFocus: hideMenu, onBlur: hideMenu },
|
|
17
|
+
React.createElement(Option, { value: "jack" }, "Jack"),
|
|
18
|
+
React.createElement(Option, { value: "lucy" }, "Lucy"))));
|
|
19
|
+
};
|
|
20
|
+
export default CustomSelect;
|
|
@@ -52,6 +52,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
|
52
52
|
};
|
|
53
53
|
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
|
54
54
|
import Table from 'components/Table';
|
|
55
|
+
import SelectDemo from './SelectDemo';
|
|
55
56
|
import EnhanceSelect from 'components/EnhanceSelect';
|
|
56
57
|
import { OperationBtnGroup, Empty, Button, message, Container } from '../index';
|
|
57
58
|
import MaterialComp, {
|
|
@@ -63,6 +64,7 @@ import { DatePicker } from 'index';
|
|
|
63
64
|
import dayjs from 'dayjs';
|
|
64
65
|
import update from 'immutability-helper';
|
|
65
66
|
import FormDemo from './FormDemo';
|
|
67
|
+
import { useContextMenu } from 'react-contexify';
|
|
66
68
|
// 获取表格数据
|
|
67
69
|
function useGetTableRecords() {
|
|
68
70
|
// 表格数据
|
|
@@ -472,6 +474,8 @@ var list1 = [
|
|
|
472
474
|
* }
|
|
473
475
|
*/
|
|
474
476
|
var TableDemo = function () {
|
|
477
|
+
var menuId = 'xxxx';
|
|
478
|
+
var show = useContextMenu({ id: menuId }).show;
|
|
475
479
|
var _a = useGetTableRecords(), records = _a.records, setRecords = _a.setRecords;
|
|
476
480
|
var _b = useGetSelectList(), list = _b.list, loading = _b.loading, setLoading = _b.setLoading;
|
|
477
481
|
var _c = useState(false), btnLoading = _c[0], setBtnLoading = _c[1];
|
|
@@ -490,6 +494,7 @@ var TableDemo = function () {
|
|
|
490
494
|
}), tableConfig = _g[0], setTableConfig = _g[1];
|
|
491
495
|
// 刷新选择框
|
|
492
496
|
var _h = useState(false), refreshSel = _h[0], setRefreshSel = _h[1];
|
|
497
|
+
var _j = useState([]), keys = _j[0], setKeys = _j[1];
|
|
493
498
|
var refreshId = useRef(1);
|
|
494
499
|
useEffect(function () {
|
|
495
500
|
setTimeout(function () {
|
|
@@ -523,6 +528,7 @@ var TableDemo = function () {
|
|
|
523
528
|
dataIndex: 'materialId',
|
|
524
529
|
key: 'materialId',
|
|
525
530
|
validate: {},
|
|
531
|
+
isMenuShow: true,
|
|
526
532
|
shouldCellUpdate: function (record, preRecord) {
|
|
527
533
|
if (lengthChange) {
|
|
528
534
|
setLengthChange(false);
|
|
@@ -620,6 +626,7 @@ var TableDemo = function () {
|
|
|
620
626
|
return Promise.resolve();
|
|
621
627
|
},
|
|
622
628
|
},
|
|
629
|
+
isMenuShow: true,
|
|
623
630
|
shouldCellUpdate: function (record, preRecord) {
|
|
624
631
|
if (firstRender) {
|
|
625
632
|
setFirstRender(false);
|
|
@@ -691,6 +698,7 @@ var TableDemo = function () {
|
|
|
691
698
|
width: 220,
|
|
692
699
|
dataIndex: 'time',
|
|
693
700
|
key: 'time',
|
|
701
|
+
isMenuShow: true,
|
|
694
702
|
shouldCellUpdate: function (record, preRecord) {
|
|
695
703
|
if (lengthChange) {
|
|
696
704
|
setLengthChange(false);
|
|
@@ -792,6 +800,7 @@ var TableDemo = function () {
|
|
|
792
800
|
dataIndex: 'test6',
|
|
793
801
|
key: 'test6',
|
|
794
802
|
fixed: 'right',
|
|
803
|
+
isMenuShow: true,
|
|
795
804
|
},
|
|
796
805
|
{
|
|
797
806
|
title: '操作',
|
|
@@ -890,6 +899,7 @@ var TableDemo = function () {
|
|
|
890
899
|
var tableHandleRef = useRef();
|
|
891
900
|
return (React.createElement(Container, { isFlex: true, loading: false, style: { height: '100vh' } },
|
|
892
901
|
React.createElement(FormDemo, null),
|
|
902
|
+
React.createElement(SelectDemo, null),
|
|
893
903
|
React.createElement("div", null,
|
|
894
904
|
React.createElement(Button, { loading: btnLoading, onClick: function () {
|
|
895
905
|
console.log(111);
|
|
@@ -922,7 +932,10 @@ var TableDemo = function () {
|
|
|
922
932
|
clearAllCatchData();
|
|
923
933
|
setRefreshSel(true);
|
|
924
934
|
refreshId.current = refreshId.current + 1;
|
|
925
|
-
} }, "\u6E32\u67D3")
|
|
935
|
+
} }, "\u6E32\u67D3"),
|
|
936
|
+
React.createElement(Button, { onClick: function () {
|
|
937
|
+
setRecords(function (state) { return __spreadArray([], state); });
|
|
938
|
+
} }, "clearKeys")),
|
|
926
939
|
React.createElement(Table
|
|
927
940
|
// 如果需要保留本地偏好,那么这里需要预处理一下columns数据
|
|
928
941
|
// columns={getTableLayoutFullData(columns, tableLayout)}
|
|
@@ -931,7 +944,7 @@ var TableDemo = function () {
|
|
|
931
944
|
// 如果需要保留本地偏好,那么这里需要预处理一下columns数据
|
|
932
945
|
// columns={getTableLayoutFullData(columns, tableLayout)}
|
|
933
946
|
// initColumns={columns}
|
|
934
|
-
columns: columns, dataSource: records, rowKey: "id", tableHandleRef: tableHandleRef,
|
|
947
|
+
menuId: "menuid", columns: columns, dataSource: records, rowKey: "id", tableHandleRef: tableHandleRef,
|
|
935
948
|
// 配置表格列
|
|
936
949
|
// configInfo={tableConfig}
|
|
937
950
|
// 添加动态列配置
|
|
@@ -942,9 +955,11 @@ var TableDemo = function () {
|
|
|
942
955
|
// 新增删除行
|
|
943
956
|
onAddAndDelHandle: onAddAndDelHandle,
|
|
944
957
|
// 表格行拖拽
|
|
945
|
-
onMoveRow
|
|
958
|
+
// onMoveRow={onMoveRowHandle}
|
|
946
959
|
// 自动伸缩列
|
|
947
|
-
isResizableColumn: true, isFlex: true, scroll: { x: 1000 },
|
|
960
|
+
isResizableColumn: true, isFlex: true, scroll: { x: 1000 }, rowSelection: {
|
|
961
|
+
type: 'checkbox',
|
|
962
|
+
}, summaryFixed: true, summaryConfig: [
|
|
948
963
|
{
|
|
949
964
|
type: 'subtotal',
|
|
950
965
|
fields: [
|
|
@@ -982,8 +997,19 @@ var TableDemo = function () {
|
|
|
982
997
|
},
|
|
983
998
|
],
|
|
984
999
|
},
|
|
985
|
-
]
|
|
986
|
-
|
|
1000
|
+
], onMenuItemClick: function (type, _a) {
|
|
1001
|
+
var value = _a.value, key = _a.key;
|
|
1002
|
+
setRecords(function (state) {
|
|
1003
|
+
return state.map(function (item) {
|
|
1004
|
+
var _a;
|
|
1005
|
+
return __assign(__assign({}, item), (_a = {}, _a[key] = value, _a));
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
} }),
|
|
1009
|
+
React.createElement(Empty, null),
|
|
1010
|
+
React.createElement("div", { onContextMenuCapture: function (event) {
|
|
1011
|
+
show(event, { props: { key: 'value' } });
|
|
1012
|
+
} }, "menu\u6D4B\u8BD5")));
|
|
987
1013
|
};
|
|
988
1014
|
// function getStorage(key) {
|
|
989
1015
|
// try {
|
|
@@ -148,6 +148,7 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
|
|
|
148
148
|
isPaste?: boolean;
|
|
149
149
|
pasteRule?: string[];
|
|
150
150
|
dropdownRenderBtns?: any;
|
|
151
|
+
onContextMenuCapture?: (e: any) => void;
|
|
151
152
|
}
|
|
152
153
|
export declare function clearCatchData(url: string): void;
|
|
153
154
|
/**
|
|
@@ -165,6 +166,6 @@ export declare function clearCatchData(url: string): void;
|
|
|
165
166
|
* { code: 200, data: { records: [] } } || { status: 200, data: { code: 200, data: { records: [] } } }
|
|
166
167
|
* 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
|
|
167
168
|
*/
|
|
168
|
-
declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, timeout, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, onSearch, request, remoteSearch, remoteSearchKey, remoteSearchDataKey, isRemoteSearchDataKey, transformData, transformRenderData, joinKey, joinStr, lineFeedKey, lineFeedStr, mustHasParams, disabledValues, searchDeleteKeys, isHandAddItem, isPage, currentSize, isCopy, onBlur, onFocus, isClickRequest, handleRef, isPaste, pasteRule, dropdownRenderBtns, dropdownMatchSelectWidth, ...restProps }: IProps<VT>): JSX.Element;
|
|
169
|
+
declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, timeout, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, onSearch, request, remoteSearch, remoteSearchKey, remoteSearchDataKey, isRemoteSearchDataKey, transformData, transformRenderData, joinKey, joinStr, lineFeedKey, lineFeedStr, mustHasParams, disabledValues, searchDeleteKeys, isHandAddItem, isPage, currentSize, isCopy, onBlur, onFocus, isClickRequest, handleRef, isPaste, pasteRule, dropdownRenderBtns, dropdownMatchSelectWidth, onContextMenuCapture, ...restProps }: IProps<VT>): JSX.Element;
|
|
169
170
|
declare const _default: React.MemoExoticComponent<typeof EnhanceSelect>;
|
|
170
171
|
export default _default;
|
|
@@ -168,7 +168,7 @@ function clearNullData(arr, dataKey, titleKey) {
|
|
|
168
168
|
* 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
|
|
169
169
|
*/
|
|
170
170
|
function EnhanceSelect(_a) {
|
|
171
|
-
var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.timeout, timeout = _c === void 0 ? 60000 : _c, _d = _a.dataKey, dataKey = _d === void 0 ? 'id' : _d, componentKey = _a.componentKey, _e = _a.titleKey, titleKey = _e === void 0 ? 'name' : _e, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, onSearch = _a.onSearch, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, remoteSearchDataKey = _a.remoteSearchDataKey, _f = _a.isRemoteSearchDataKey, isRemoteSearchDataKey = _f === void 0 ? true : _f, transformData = _a.transformData, transformRenderData = _a.transformRenderData, joinKey = _a.joinKey, _g = _a.joinStr, joinStr = _g === void 0 ? '-' : _g, lineFeedKey = _a.lineFeedKey, _h = _a.lineFeedStr, lineFeedStr = _h === void 0 ? '-' : _h, mustHasParams = _a.mustHasParams, disabledValues = _a.disabledValues, searchDeleteKeys = _a.searchDeleteKeys, isHandAddItem = _a.isHandAddItem, isPage = _a.isPage, _j = _a.currentSize, currentSize = _j === void 0 ? 30 : _j, isCopy = _a.isCopy, onBlur = _a.onBlur, onFocus = _a.onFocus, isClickRequest = _a.isClickRequest, handleRef = _a.handleRef, isPaste = _a.isPaste, _k = _a.pasteRule, pasteRule = _k === void 0 ? [',', '-', '\r\n', '\r', '\n', ' '] : _k, dropdownRenderBtns = _a.dropdownRenderBtns, _l = _a.dropdownMatchSelectWidth, dropdownMatchSelectWidth = _l === void 0 ? 150 : _l, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "timeout", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "onSearch", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "transformRenderData", "joinKey", "joinStr", "lineFeedKey", "lineFeedStr", "mustHasParams", "disabledValues", "searchDeleteKeys", "isHandAddItem", "isPage", "currentSize", "isCopy", "onBlur", "onFocus", "isClickRequest", "handleRef", "isPaste", "pasteRule", "dropdownRenderBtns", "dropdownMatchSelectWidth"]);
|
|
171
|
+
var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.timeout, timeout = _c === void 0 ? 60000 : _c, _d = _a.dataKey, dataKey = _d === void 0 ? 'id' : _d, componentKey = _a.componentKey, _e = _a.titleKey, titleKey = _e === void 0 ? 'name' : _e, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, onSearch = _a.onSearch, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, remoteSearchDataKey = _a.remoteSearchDataKey, _f = _a.isRemoteSearchDataKey, isRemoteSearchDataKey = _f === void 0 ? true : _f, transformData = _a.transformData, transformRenderData = _a.transformRenderData, joinKey = _a.joinKey, _g = _a.joinStr, joinStr = _g === void 0 ? '-' : _g, lineFeedKey = _a.lineFeedKey, _h = _a.lineFeedStr, lineFeedStr = _h === void 0 ? '-' : _h, mustHasParams = _a.mustHasParams, disabledValues = _a.disabledValues, searchDeleteKeys = _a.searchDeleteKeys, isHandAddItem = _a.isHandAddItem, isPage = _a.isPage, _j = _a.currentSize, currentSize = _j === void 0 ? 30 : _j, isCopy = _a.isCopy, onBlur = _a.onBlur, onFocus = _a.onFocus, isClickRequest = _a.isClickRequest, handleRef = _a.handleRef, isPaste = _a.isPaste, _k = _a.pasteRule, pasteRule = _k === void 0 ? [',', '-', '\r\n', '\r', '\n', ' '] : _k, dropdownRenderBtns = _a.dropdownRenderBtns, _l = _a.dropdownMatchSelectWidth, dropdownMatchSelectWidth = _l === void 0 ? 150 : _l, onContextMenuCapture = _a.onContextMenuCapture, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "timeout", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "onSearch", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "transformRenderData", "joinKey", "joinStr", "lineFeedKey", "lineFeedStr", "mustHasParams", "disabledValues", "searchDeleteKeys", "isHandAddItem", "isPage", "currentSize", "isCopy", "onBlur", "onFocus", "isClickRequest", "handleRef", "isPaste", "pasteRule", "dropdownRenderBtns", "dropdownMatchSelectWidth", "onContextMenuCapture"]);
|
|
172
172
|
// TODO: 注释动态设置open逻辑 start
|
|
173
173
|
// const currentClick = useRef<boolean>(true);
|
|
174
174
|
// TODO: 注释动态设置open逻辑 end
|
|
@@ -958,6 +958,7 @@ function EnhanceSelect(_a) {
|
|
|
958
958
|
onFocus && onFocus(e);
|
|
959
959
|
};
|
|
960
960
|
var onBlurHandle = function (e) {
|
|
961
|
+
setIsOpen(false);
|
|
961
962
|
onBlur && onBlur(e);
|
|
962
963
|
};
|
|
963
964
|
// 清空数据时
|
|
@@ -971,6 +972,9 @@ function EnhanceSelect(_a) {
|
|
|
971
972
|
var text = textContent(obj.children);
|
|
972
973
|
copyValue(text);
|
|
973
974
|
}
|
|
975
|
+
if (!restProps.mode) {
|
|
976
|
+
setIsOpen(false);
|
|
977
|
+
}
|
|
974
978
|
};
|
|
975
979
|
// 点击时
|
|
976
980
|
var onClickHandle = function (e) {
|
|
@@ -1087,29 +1091,37 @@ function EnhanceSelect(_a) {
|
|
|
1087
1091
|
}
|
|
1088
1092
|
}
|
|
1089
1093
|
};
|
|
1090
|
-
return (React.createElement(
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
React.createElement(
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1094
|
+
return (React.createElement("div", { onContextMenuCapture: function (e) {
|
|
1095
|
+
setIsOpen(false);
|
|
1096
|
+
e.preventDefault();
|
|
1097
|
+
e.stopPropagation();
|
|
1098
|
+
onContextMenuCapture && onContextMenuCapture(e);
|
|
1099
|
+
} },
|
|
1100
|
+
React.createElement(Select, __assign({ defaultValue: showAll ? '' : undefined, allowClear: true, showSearch: true, filterOption: remoteSearch ? false : filterOptionHandle, onSearch: remoteSearch ? onSearchHandle : onSearchHandleInner, onChange: onChangeHandle, optionLabelProp: "title", loading: loading, onFocus: onFocusHandle, onBlur: onBlurHandle, onClear: onClearHandle, onSelect: onSelectHandle, onClick: onClickHandle, onMouseDown: onMouseDownHandle,
|
|
1101
|
+
// getPopupContainer={(trigger) => trigger || document.body}
|
|
1102
|
+
open: isOpen,
|
|
1103
|
+
// onDropdownVisibleChange={(visible) => setIsOpen(visible)}
|
|
1104
|
+
onPopupScroll: onPopupScrollHandle, dropdownRender: url && !remoteSearch && isCatch
|
|
1105
|
+
? function (menu) { return (React.createElement(React.Fragment, null,
|
|
1106
|
+
menu,
|
|
1107
|
+
React.createElement(Divider, { style: { marginTop: 0, marginBottom: '4px' } }),
|
|
1108
|
+
React.createElement("div", { style: {
|
|
1109
|
+
display: 'flex',
|
|
1110
|
+
alignItems: 'center',
|
|
1111
|
+
flexDirection: 'row',
|
|
1112
|
+
justifyContent: 'space-between',
|
|
1113
|
+
padding: '0 6px',
|
|
1114
|
+
} },
|
|
1115
|
+
React.createElement("span", null),
|
|
1116
|
+
dropdownRenderBtns && dropdownRenderBtns(),
|
|
1117
|
+
React.createElement(Button, { onClick: function (e) {
|
|
1118
|
+
e.preventDefault();
|
|
1119
|
+
sendRequestNoCatch();
|
|
1120
|
+
} }, "\u5237\u65B0\u6570\u636E")))); }
|
|
1121
|
+
: undefined }, restProps, { value: newValue,
|
|
1122
|
+
// 这里需要注释掉,因为修改了一部分逻辑
|
|
1123
|
+
disabled: remoteSearch || isClickRequest
|
|
1124
|
+
? restProps.disabled
|
|
1125
|
+
: loading || restProps.disabled, ref: selectRef, dropdownMatchSelectWidth: dropdownMatchSelectWidth }), renderSelectOption())));
|
|
1114
1126
|
}
|
|
1115
1127
|
export default memo(EnhanceSelect);
|
|
@@ -41,6 +41,13 @@ interface IProps<RecordType> {
|
|
|
41
41
|
customOrder?: any;
|
|
42
42
|
setCustomOrder?: any;
|
|
43
43
|
isSort?: boolean;
|
|
44
|
+
menuShow?: any;
|
|
45
|
+
getMenuInfoByCell: ({ record, index, value, key }: {
|
|
46
|
+
record: any;
|
|
47
|
+
index: any;
|
|
48
|
+
value: any;
|
|
49
|
+
key: any;
|
|
50
|
+
}) => void;
|
|
44
51
|
}
|
|
45
52
|
export declare const getTableLayoutFullData: (columns: any, tableLayout: any) => any;
|
|
46
53
|
export declare const LOCALSTORAGE_KEY = "ztui_dynamic_table_key";
|
|
@@ -214,7 +214,7 @@ function getNewColumns(basicConfig, editableConfig, dynamicConfig, otherConfig)
|
|
|
214
214
|
var columns = basicConfig.columns, newColumnsRef = basicConfig.newColumnsRef, showColumnDynamic = basicConfig.showColumnDynamic, showColumnDynamicKey = basicConfig.showColumnDynamicKey, configInfo = basicConfig.configInfo, currentDataSource = basicConfig.currentDataSource, preDataSource = basicConfig.preDataSource, rowKey = basicConfig.rowKey, dataSourceRef = basicConfig.dataSourceRef, expandableChildrenColumnName = basicConfig.expandableChildrenColumnName, upDateColumnsRef = basicConfig.upDateColumnsRef, setUpDateColumnsRef = basicConfig.setUpDateColumnsRef, isUpDateColumnsRef = basicConfig.isUpDateColumnsRef, setIsUpDateColumnsRef = basicConfig.setIsUpDateColumnsRef;
|
|
215
215
|
var onEditableSave = editableConfig.onEditableSave, onTableChange = editableConfig.onTableChange, currentPage = editableConfig.currentPage;
|
|
216
216
|
var ColumnDynamicCom = dynamicConfig.ColumnDynamicCom, DelAllCom = dynamicConfig.DelAllCom, onAddAndDelHandleMemo = dynamicConfig.onAddAndDelHandleMemo, onAddAndDelHandle = dynamicConfig.onAddAndDelHandle, hideAddIcon = dynamicConfig.hideAddIcon, addIconText = dynamicConfig.addIconText, hideDelIcon = dynamicConfig.hideDelIcon, delIconText = dynamicConfig.delIconText;
|
|
217
|
-
var copyByKey = otherConfig.copyByKey, myCatchColumns = otherConfig.myCatchColumns, customSortHandle = otherConfig.customSortHandle, customOrder = otherConfig.customOrder, setCustomOrder = otherConfig.setCustomOrder, isSort = otherConfig.isSort;
|
|
217
|
+
var copyByKey = otherConfig.copyByKey, myCatchColumns = otherConfig.myCatchColumns, customSortHandle = otherConfig.customSortHandle, customOrder = otherConfig.customOrder, setCustomOrder = otherConfig.setCustomOrder, isSort = otherConfig.isSort, menuShow = otherConfig.menuShow, getMenuInfoByCell = otherConfig.getMenuInfoByCell;
|
|
218
218
|
var tableLayout = showColumnDynamicKey
|
|
219
219
|
? getStorage(showColumnDynamicKey)
|
|
220
220
|
: myCatchColumns;
|
|
@@ -347,6 +347,26 @@ function getNewColumns(basicConfig, editableConfig, dynamicConfig, otherConfig)
|
|
|
347
347
|
textAlign: _column.align,
|
|
348
348
|
} }, "\u590D\u5236\u6574\u5217")));
|
|
349
349
|
}
|
|
350
|
+
// 右键菜单
|
|
351
|
+
if (_column.isMenuShow && _column.key) {
|
|
352
|
+
var _onCell_1 = _column.onCell;
|
|
353
|
+
_column = __assign(__assign({}, _column), { onCell: function (record, index) {
|
|
354
|
+
var others = _onCell_1 ? _onCell_1(record, index) : {};
|
|
355
|
+
return __assign(__assign({}, others), { onContextMenuCapture: function (event) {
|
|
356
|
+
if (_column.isMenuShow) {
|
|
357
|
+
getMenuInfoByCell({
|
|
358
|
+
record: record,
|
|
359
|
+
index: index,
|
|
360
|
+
value: _column.key ? record[_column.key] : undefined,
|
|
361
|
+
key: _column.key,
|
|
362
|
+
});
|
|
363
|
+
menuShow(event, {
|
|
364
|
+
key: 'value',
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
} });
|
|
368
|
+
} });
|
|
369
|
+
}
|
|
350
370
|
// 如果配置了固定列的 不做处理
|
|
351
371
|
// if (!col.fixed) {
|
|
352
372
|
_dynamicColumns.push(__assign({}, col));
|
|
@@ -451,7 +471,7 @@ function getNewColumns(basicConfig, editableConfig, dynamicConfig, otherConfig)
|
|
|
451
471
|
};
|
|
452
472
|
}
|
|
453
473
|
function useColumns(props) {
|
|
454
|
-
var columns = props.columns, hiddenColumnDynamicIcon = props.hiddenColumnDynamicIcon, showColumnDynamic = props.showColumnDynamic, showColumnDynamicKey = props.showColumnDynamicKey, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, showDelAllBtn = props.showDelAllBtn, delAllChange = props.delAllChange, addIconText = props.addIconText, hideDelIcon = props.hideDelIcon, delIconText = props.delIconText, showDynamicHandle = props.showDynamicHandle, onEditableSave = props.onEditableSave, configInfo = props.configInfo, copyByKey = props.copyByKey, onTableChange = props.onTableChange, currentPage = props.currentPage, currentDataSource = props.currentDataSource, preDataSource = props.preDataSource, rowKey = props.rowKey, dataSourceRef = props.dataSourceRef, expandableChildrenColumnName = props.expandableChildrenColumnName, customSortHandle = props.customSortHandle, customOrder = props.customOrder, setCustomOrder = props.setCustomOrder, isSort = props.isSort;
|
|
474
|
+
var columns = props.columns, hiddenColumnDynamicIcon = props.hiddenColumnDynamicIcon, showColumnDynamic = props.showColumnDynamic, showColumnDynamicKey = props.showColumnDynamicKey, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, showDelAllBtn = props.showDelAllBtn, delAllChange = props.delAllChange, addIconText = props.addIconText, hideDelIcon = props.hideDelIcon, delIconText = props.delIconText, showDynamicHandle = props.showDynamicHandle, onEditableSave = props.onEditableSave, configInfo = props.configInfo, copyByKey = props.copyByKey, onTableChange = props.onTableChange, currentPage = props.currentPage, currentDataSource = props.currentDataSource, preDataSource = props.preDataSource, rowKey = props.rowKey, dataSourceRef = props.dataSourceRef, expandableChildrenColumnName = props.expandableChildrenColumnName, customSortHandle = props.customSortHandle, customOrder = props.customOrder, setCustomOrder = props.setCustomOrder, isSort = props.isSort, menuShow = props.menuShow, getMenuInfoByCell = props.getMenuInfoByCell;
|
|
455
475
|
var newColumnsRef = useRef();
|
|
456
476
|
var _a = useAsyncSetValue(columns), upDateColumnsRef = _a[0], setUpDateColumnsRef = _a[1];
|
|
457
477
|
var _b = useAsyncSetValue(false), isUpDateColumnsRef = _b[0], setIsUpDateColumnsRef = _b[1];
|
|
@@ -511,6 +531,8 @@ function useColumns(props) {
|
|
|
511
531
|
customOrder: customOrder,
|
|
512
532
|
setCustomOrder: setCustomOrder,
|
|
513
533
|
isSort: isSort,
|
|
534
|
+
menuShow: menuShow,
|
|
535
|
+
getMenuInfoByCell: getMenuInfoByCell,
|
|
514
536
|
});
|
|
515
537
|
}, [
|
|
516
538
|
showColumnDynamic,
|
|
@@ -541,6 +563,8 @@ function useColumns(props) {
|
|
|
541
563
|
isUpDateColumnsRef,
|
|
542
564
|
setIsUpDateColumnsRef,
|
|
543
565
|
isSort,
|
|
566
|
+
menuShow,
|
|
567
|
+
getMenuInfoByCell,
|
|
544
568
|
]);
|
|
545
569
|
var _c = useState(false), refreshColumns = _c[0], setRefreshColumns = _c[1];
|
|
546
570
|
var _d = useState([]), myCatchColumns = _d[0], setMyCatchColumns = _d[1];
|
|
@@ -45,6 +45,8 @@ export interface IColumnType<RecordType> extends ColumnType<RecordType> {
|
|
|
45
45
|
precision?: number;
|
|
46
46
|
/**是否加上千分符 */
|
|
47
47
|
thousand?: boolean;
|
|
48
|
+
/**是否右键显示菜单 */
|
|
49
|
+
isMenuShow?: boolean;
|
|
48
50
|
}
|
|
49
51
|
export interface IColumnGroupType<RecordType> extends Omit<IColumnType<RecordType>, ''> {
|
|
50
52
|
children: ColumnsType<RecordType>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Menu, Item } from 'react-contexify';
|
|
2
|
+
import 'react-contexify/dist/ReactContexify.min.css';
|
|
3
|
+
var TableMenu = function (_a) {
|
|
4
|
+
var menuId = _a.menuId, onMenuItemClick = _a.onMenuItemClick;
|
|
5
|
+
return (React.createElement(Menu, { id: menuId },
|
|
6
|
+
React.createElement(Item, { id: "copyAll", onClick: function () {
|
|
7
|
+
onMenuItemClick('copyAll');
|
|
8
|
+
} }, "\u5E94\u7528\u6240\u6709\u884C")));
|
|
9
|
+
};
|
|
10
|
+
export default TableMenu;
|
|
@@ -65,6 +65,15 @@ export interface IProps<RecordType> extends Omit<TableProps<RecordType>, 'column
|
|
|
65
65
|
virtualTableKey?: string;
|
|
66
66
|
/** 是否需要排序 内部会有一个排序功能。自定义的 这个在某些条件下不会开启。但是还需要别的条件也不开启 */
|
|
67
67
|
isSort?: boolean;
|
|
68
|
+
/** 鼠标右键显示菜单id */
|
|
69
|
+
menuId?: string;
|
|
70
|
+
/**右键菜单点击 */
|
|
71
|
+
onMenuItemClick?: (type: 'coyAll', props: {
|
|
72
|
+
record: any;
|
|
73
|
+
index: number;
|
|
74
|
+
value: any;
|
|
75
|
+
key: string;
|
|
76
|
+
}) => void;
|
|
68
77
|
}
|
|
69
78
|
/**
|
|
70
79
|
* TodoList
|
|
@@ -64,6 +64,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
|
64
64
|
import React, { useCallback, memo, useState, useEffect, useRef, useMemo, useImperativeHandle, } from 'react';
|
|
65
65
|
import { unstable_batchedUpdates } from 'react-dom';
|
|
66
66
|
import { Table as AntTable } from 'antd';
|
|
67
|
+
import { useContextMenu } from 'react-contexify';
|
|
67
68
|
import { message } from '../../index';
|
|
68
69
|
import { ERROR_TD_CLASSNAME } from './';
|
|
69
70
|
import TableDynamic from './table-dynamic';
|
|
@@ -71,6 +72,7 @@ import TableDynamic from './table-dynamic';
|
|
|
71
72
|
import TableEnhanceRow from './table-enhance-row';
|
|
72
73
|
import TableEnhanceCell from './table-enhance-cell';
|
|
73
74
|
import TableResizableTitle from './table-resizable-title';
|
|
75
|
+
import TableMenu from './table-menu';
|
|
74
76
|
import useColumns, { setDynamicKey, getStorage, } from './hooks/useColumns';
|
|
75
77
|
import getSummaryData from './utils/getSummaryData';
|
|
76
78
|
import { domFind } from './utils/dom';
|
|
@@ -116,7 +118,7 @@ export function usePrevious(value) {
|
|
|
116
118
|
function Table(props) {
|
|
117
119
|
var _this = this;
|
|
118
120
|
var _a, _b;
|
|
119
|
-
var className = props.className, scroll = props.scroll, _c = props.pagination, pagination = _c === void 0 ? false : _c, _d = props.bordered, bordered = _d === void 0 ? true : _d, _columns = props.columns, initColumns = props.initColumns, dataSource = props.dataSource, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, addIconText = props.addIconText, hideDelIcon = props.hideDelIcon, showDelAllBtn = props.showDelAllBtn, delAllChange = props.delAllChange, delIconText = props.delIconText, hiddenColumnDynamicIcon = props.hiddenColumnDynamicIcon, showColumnDynamic = props.showColumnDynamic, showColumnDynamicKey = props.showColumnDynamicKey, summaryConfig = props.summaryConfig, summaryFixed = props.summaryFixed, summary = props.summary, onMoveRow = props.onMoveRow, onEditableSave = props.onEditableSave, onDynamicChange = props.onDynamicChange, _e = props.isResizableColumn, isResizableColumn = _e === void 0 ? true : _e, configInfo = props.configInfo, tableHandleRef = props.tableHandleRef, tableName = props.tableName, isFlex = props.isFlex, onTableChange = props.onTableChange, rowSelection = props.rowSelection, showInnerPagination = props.showInnerPagination, defaultInnerPageSize = props.defaultInnerPageSize, virtualTableKey = props.virtualTableKey, _f = props.isSort, isSort = _f === void 0 ? true : _f, isColumnDynamicAutoRefresh = props.isColumnDynamicAutoRefresh, restProps = __rest(props, ["className", "scroll", "pagination", "bordered", "columns", "initColumns", "dataSource", "onAddAndDelHandle", "hideAddIcon", "addIconText", "hideDelIcon", "showDelAllBtn", "delAllChange", "delIconText", "hiddenColumnDynamicIcon", "showColumnDynamic", "showColumnDynamicKey", "summaryConfig", "summaryFixed", "summary", "onMoveRow", "onEditableSave", "onDynamicChange", "isResizableColumn", "configInfo", "tableHandleRef", "tableName", "isFlex", "onTableChange", "rowSelection", "showInnerPagination", "defaultInnerPageSize", "virtualTableKey", "isSort", "isColumnDynamicAutoRefresh"]);
|
|
121
|
+
var className = props.className, scroll = props.scroll, _c = props.pagination, pagination = _c === void 0 ? false : _c, _d = props.bordered, bordered = _d === void 0 ? true : _d, _columns = props.columns, initColumns = props.initColumns, dataSource = props.dataSource, onAddAndDelHandle = props.onAddAndDelHandle, hideAddIcon = props.hideAddIcon, addIconText = props.addIconText, hideDelIcon = props.hideDelIcon, showDelAllBtn = props.showDelAllBtn, delAllChange = props.delAllChange, delIconText = props.delIconText, hiddenColumnDynamicIcon = props.hiddenColumnDynamicIcon, showColumnDynamic = props.showColumnDynamic, showColumnDynamicKey = props.showColumnDynamicKey, summaryConfig = props.summaryConfig, summaryFixed = props.summaryFixed, summary = props.summary, onMoveRow = props.onMoveRow, onEditableSave = props.onEditableSave, onDynamicChange = props.onDynamicChange, _e = props.isResizableColumn, isResizableColumn = _e === void 0 ? true : _e, configInfo = props.configInfo, tableHandleRef = props.tableHandleRef, tableName = props.tableName, isFlex = props.isFlex, onTableChange = props.onTableChange, rowSelection = props.rowSelection, showInnerPagination = props.showInnerPagination, defaultInnerPageSize = props.defaultInnerPageSize, virtualTableKey = props.virtualTableKey, _f = props.isSort, isSort = _f === void 0 ? true : _f, isColumnDynamicAutoRefresh = props.isColumnDynamicAutoRefresh, menuId = props.menuId, onMenuItemClick = props.onMenuItemClick, restProps = __rest(props, ["className", "scroll", "pagination", "bordered", "columns", "initColumns", "dataSource", "onAddAndDelHandle", "hideAddIcon", "addIconText", "hideDelIcon", "showDelAllBtn", "delAllChange", "delIconText", "hiddenColumnDynamicIcon", "showColumnDynamic", "showColumnDynamicKey", "summaryConfig", "summaryFixed", "summary", "onMoveRow", "onEditableSave", "onDynamicChange", "isResizableColumn", "configInfo", "tableHandleRef", "tableName", "isFlex", "onTableChange", "rowSelection", "showInnerPagination", "defaultInnerPageSize", "virtualTableKey", "isSort", "isColumnDynamicAutoRefresh", "menuId", "onMenuItemClick"]);
|
|
120
122
|
var classes = classNames('zt-table', className, {
|
|
121
123
|
'zt-table--flex': isFlex,
|
|
122
124
|
});
|
|
@@ -126,6 +128,8 @@ function Table(props) {
|
|
|
126
128
|
var dataSourceRef = useRef();
|
|
127
129
|
var preDataSource = usePrevious(dataSource);
|
|
128
130
|
var _h = useState(), sortDataSource = _h[0], setSortDataSource = _h[1];
|
|
131
|
+
// 菜单右键选中record信息
|
|
132
|
+
var menuRecords = useRef();
|
|
129
133
|
// 内部分页相关配置
|
|
130
134
|
var _j = useInnerPagination(showInnerPagination, defaultInnerPageSize), paginationConfig = _j.paginationConfig, currentPage = _j.currentPage, setCurrent = _j.setCurrent, pageSize = _j.pageSize;
|
|
131
135
|
var rowSelectionDataSource = useRef({});
|
|
@@ -282,6 +286,16 @@ function Table(props) {
|
|
|
282
286
|
}
|
|
283
287
|
}
|
|
284
288
|
}, [expandableDataSource]);
|
|
289
|
+
/**
|
|
290
|
+
* @description 鼠标右键显示
|
|
291
|
+
*/
|
|
292
|
+
var menuShow = useContextMenu({ id: menuId }).show;
|
|
293
|
+
/**
|
|
294
|
+
* @description 表格onCell右键选中信息
|
|
295
|
+
*/
|
|
296
|
+
var getMenuInfoByCell = useCallback(function (value) {
|
|
297
|
+
menuRecords.current = value;
|
|
298
|
+
}, []);
|
|
285
299
|
/**
|
|
286
300
|
* @description 根据配置生成一个新的columns
|
|
287
301
|
* 以及一个需要动态列配置的columns
|
|
@@ -313,6 +327,8 @@ function Table(props) {
|
|
|
313
327
|
customOrder: customOrder,
|
|
314
328
|
setCustomOrder: setCustomOrder,
|
|
315
329
|
isSort: isSort,
|
|
330
|
+
menuShow: menuShow,
|
|
331
|
+
getMenuInfoByCell: getMenuInfoByCell,
|
|
316
332
|
}), newColumns = _l.newColumns, dynamicColumns = _l.dynamicColumns, refreshColumnsHandle = _l.refreshColumnsHandle;
|
|
317
333
|
useEffect(function () {
|
|
318
334
|
if (isColumnDynamicAutoRefresh && showColumnDynamicKey && dynamicColumns) {
|
|
@@ -602,13 +618,13 @@ function Table(props) {
|
|
|
602
618
|
// 表格合计
|
|
603
619
|
var onSummaryHandle = useCallback(function (pageData) {
|
|
604
620
|
var _a;
|
|
605
|
-
var _b = rowSelectionDataSource.current || {}, isChange = _b.isChange, selectedRowKeys = _b.selectedRowKeys
|
|
621
|
+
var _b = rowSelectionDataSource.current || {}, isChange = _b.isChange, selectedRowKeys = _b.selectedRowKeys;
|
|
606
622
|
var rowKey = restProps.rowKey;
|
|
607
623
|
var resultDataSoure = typeof rowKey === 'string' && Array.isArray(selectedRowKeys)
|
|
608
624
|
? pageData.filter(function (item) {
|
|
609
625
|
return selectedRowKeys.find(function (key) { return item[rowKey] === key; });
|
|
610
626
|
})
|
|
611
|
-
:
|
|
627
|
+
: pageData;
|
|
612
628
|
var summaryData = getSummaryData(summaryConfig, isChange && Array.isArray(resultDataSoure) && resultDataSoure.length > 0
|
|
613
629
|
? resultDataSoure
|
|
614
630
|
: pageData, newColumns, {
|
|
@@ -649,6 +665,10 @@ function Table(props) {
|
|
|
649
665
|
summaryFixed,
|
|
650
666
|
virtualTableKey,
|
|
651
667
|
]);
|
|
668
|
+
if (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) {
|
|
669
|
+
rowSelectionDataSource.current.selectedRowKeys =
|
|
670
|
+
rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys;
|
|
671
|
+
}
|
|
652
672
|
// 多选
|
|
653
673
|
var rowSelectionObj = useMemo(function () { return (__assign(__assign({}, rowSelection), { onChange: function (selectedRowKeys, selectedRows) {
|
|
654
674
|
rowSelectionDataSource.current = {
|
|
@@ -706,6 +726,11 @@ function Table(props) {
|
|
|
706
726
|
tableResizableTitle,
|
|
707
727
|
vComponents,
|
|
708
728
|
]);
|
|
729
|
+
var handleMenuItemClick = function (type) {
|
|
730
|
+
if (menuRecords.current) {
|
|
731
|
+
onMenuItemClick && onMenuItemClick(type, menuRecords.current);
|
|
732
|
+
}
|
|
733
|
+
};
|
|
709
734
|
return (React.createElement("div", { style: isFlex
|
|
710
735
|
? { position: 'relative', overflow: 'hidden', flex: 1 }
|
|
711
736
|
: { position: 'relative', overflow: 'hidden' }, ref: tableRef },
|
|
@@ -715,7 +740,8 @@ function Table(props) {
|
|
|
715
740
|
? pagination
|
|
716
741
|
: paginationConfig
|
|
717
742
|
: pagination, scroll: myScroll, columns: mergeColumns, dataSource: sortDataSource ? sortDataSource : expandableDataSource, components: tableComponents, onRow: onMoveRow ? onRowHandle : undefined, summary: summaryConfig ? onSummaryHandle : summary, rowSelection: rowSelection ? rowSelectionObj : rowSelection }, restProps)),
|
|
718
|
-
showColumnDynamic && dynamicVisible && (React.createElement(TableDynamic, { visible: dynamicVisible, onClose: hideDynamicHandle, onSave: saveDynamicHandle, onReset: resetDynamicHandle, columns: dynamicColumns })))
|
|
743
|
+
showColumnDynamic && dynamicVisible && (React.createElement(TableDynamic, { visible: dynamicVisible, onClose: hideDynamicHandle, onSave: saveDynamicHandle, onReset: resetDynamicHandle, columns: dynamicColumns }))),
|
|
744
|
+
React.createElement(TableMenu, { menuId: menuId, onMenuItemClick: handleMenuItemClick })));
|
|
719
745
|
}
|
|
720
746
|
// export default memo(Table, (prevProps, nextProps) => {
|
|
721
747
|
// return shallowEqual(prevProps, nextProps);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ztxkui",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.27",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "React components library",
|
|
6
6
|
"author": "zt-front-end",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"number-precision": "^1.5.0",
|
|
22
22
|
"pinyin-pro": "^3.14.0",
|
|
23
23
|
"rc-resize-observer": "^1.3.1",
|
|
24
|
+
"react-contexify": "5.0.0",
|
|
24
25
|
"react-dnd": "^14.0.2",
|
|
25
26
|
"react-dnd-html5-backend": "^14.0.0",
|
|
26
27
|
"react-draggable": "^4.4.5",
|