@hw-component/table 0.0.7-beta-v8 → 0.0.7-beta-v9
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/.eslintcache +1 -1
- package/es/HTableBody/Options/Content.d.ts +2 -0
- package/es/HTableBody/Options/Content.js +83 -0
- package/es/HTableBody/Options/Title.d.ts +2 -0
- package/es/HTableBody/Options/Title.js +71 -0
- package/es/HTableBody/Options/index.d.ts +3 -0
- package/es/HTableBody/Options/index.js +124 -0
- package/es/HTableBody/Options/utils.d.ts +5 -0
- package/es/HTableBody/Options/utils.js +31 -0
- package/es/HTableBody/hooks.d.ts +9 -1149
- package/es/HTableBody/hooks.js +39 -9
- package/es/HTableBody/index.d.ts +2 -2
- package/es/HTableBody/index.js +27 -14
- package/es/HTableHeader/hooks.js +6 -3
- package/es/hooks/useHTable.d.ts +1 -0
- package/es/hooks/useHTable.js +2 -1
- package/es/index.css +43 -0
- package/es/modal.d.ts +6 -1
- package/lib/HTableBody/Options/Content.d.ts +2 -0
- package/lib/HTableBody/Options/Content.js +84 -0
- package/lib/HTableBody/Options/Title.d.ts +2 -0
- package/lib/HTableBody/Options/Title.js +72 -0
- package/lib/HTableBody/Options/index.d.ts +3 -0
- package/lib/HTableBody/Options/index.js +127 -0
- package/lib/HTableBody/Options/utils.d.ts +5 -0
- package/lib/HTableBody/Options/utils.js +32 -0
- package/lib/HTableBody/hooks.d.ts +9 -1149
- package/lib/HTableBody/hooks.js +38 -7
- package/lib/HTableBody/index.d.ts +2 -2
- package/lib/HTableBody/index.js +28 -15
- package/lib/HTableHeader/hooks.js +6 -3
- package/lib/hooks/useHTable.d.ts +1 -0
- package/lib/hooks/useHTable.js +2 -1
- package/lib/index.css +43 -0
- package/lib/modal.d.ts +6 -1
- package/package.json +1 -1
- package/src/components/HTableBody/Options/Content.tsx +58 -0
- package/src/components/HTableBody/Options/Title.tsx +48 -0
- package/src/components/HTableBody/Options/index.tsx +108 -0
- package/src/components/HTableBody/Options/modal.d.ts +14 -0
- package/src/components/HTableBody/Options/utils.ts +22 -0
- package/src/components/HTableBody/hooks.tsx +34 -8
- package/src/components/HTableBody/index.tsx +22 -17
- package/src/components/HTableHeader/hooks.tsx +3 -0
- package/src/components/hooks/useHTable.tsx +1 -0
- package/src/components/index.less +41 -0
- package/src/components/modal.ts +8 -1
- package/src/pages/Table/index.tsx +18 -25
package/lib/HTableBody/hooks.js
CHANGED
|
@@ -8,10 +8,10 @@ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js/
|
|
|
8
8
|
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js/object/define-properties');
|
|
9
9
|
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js/object/define-property');
|
|
10
10
|
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
11
|
-
var
|
|
11
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
12
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
|
|
12
13
|
var _spliceInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/splice');
|
|
13
14
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
14
|
-
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/filter');
|
|
15
15
|
var _indexOfInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/index-of');
|
|
16
16
|
var jsxRuntime = require('react/jsx-runtime');
|
|
17
17
|
var React = require('react');
|
|
@@ -31,8 +31,9 @@ var rowSelectionCol = function rowSelectionCol(rowSelection) {
|
|
|
31
31
|
onChange: onChange,
|
|
32
32
|
getCheckboxProps: getCheckboxProps
|
|
33
33
|
}),
|
|
34
|
-
dataIndex: "rowSelectionTitle",
|
|
35
34
|
width: 32,
|
|
35
|
+
rowSelectionTitle: true,
|
|
36
|
+
fixed: "left",
|
|
36
37
|
render: function render(dom, data) {
|
|
37
38
|
return jsxRuntime.jsx(RowSelection.RowSelectionBox, {
|
|
38
39
|
data: data,
|
|
@@ -46,23 +47,39 @@ var useCols = function useCols(_ref2) {
|
|
|
46
47
|
var configData = _ref2.configData,
|
|
47
48
|
rowSelection = _ref2.rowSelection,
|
|
48
49
|
table = _ref2.table;
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
var _useState = React.useState([]),
|
|
51
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
52
|
+
cols = _useState2[0],
|
|
53
|
+
setCols = _useState2[1];
|
|
54
|
+
var changeConfigData = function changeConfigData(data) {
|
|
55
|
+
var colsArray = _filterInstanceProperty(data).call(data, function (item) {
|
|
56
|
+
return !item.hideInTable;
|
|
57
|
+
});
|
|
51
58
|
if (rowSelection !== false) {
|
|
52
59
|
_spliceInstanceProperty(colsArray).call(colsArray, 0, 0, rowSelectionCol(rowSelection));
|
|
53
60
|
}
|
|
54
61
|
return _mapInstanceProperty(colsArray).call(colsArray, function (item) {
|
|
55
62
|
var _render = item.render;
|
|
56
63
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
57
|
-
render: function render(dom,
|
|
64
|
+
render: function render(dom, itemData, index) {
|
|
58
65
|
if (!_render) {
|
|
59
66
|
return dom;
|
|
60
67
|
}
|
|
61
|
-
return _render(dom,
|
|
68
|
+
return _render(dom, itemData, index, table);
|
|
62
69
|
}
|
|
63
70
|
});
|
|
64
71
|
});
|
|
72
|
+
};
|
|
73
|
+
React.useEffect(function () {
|
|
74
|
+
setCols(changeConfigData(configData));
|
|
65
75
|
}, [configData, table, rowSelection]);
|
|
76
|
+
var changeCols = function changeCols(cuCols) {
|
|
77
|
+
setCols(cuCols);
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
cols: cols,
|
|
81
|
+
changeCols: changeCols
|
|
82
|
+
};
|
|
66
83
|
};
|
|
67
84
|
var useSynchronousKeys = function useSynchronousKeys(_ref3) {
|
|
68
85
|
var selectedRowKeys = _ref3.selectedRowKeys,
|
|
@@ -80,7 +97,21 @@ var useSynchronousKeys = function useSynchronousKeys(_ref3) {
|
|
|
80
97
|
}
|
|
81
98
|
}, [selectedRowKeys, records, rowKey]);
|
|
82
99
|
};
|
|
100
|
+
var useSize = function useSize(size) {
|
|
101
|
+
var _useState3 = React.useState(size),
|
|
102
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
103
|
+
cuSize = _useState4[0],
|
|
104
|
+
setCuSize = _useState4[1];
|
|
105
|
+
React.useEffect(function () {
|
|
106
|
+
setCuSize(size);
|
|
107
|
+
}, [size]);
|
|
108
|
+
return {
|
|
109
|
+
cuSize: cuSize,
|
|
110
|
+
setCuSize: setCuSize
|
|
111
|
+
};
|
|
112
|
+
};
|
|
83
113
|
|
|
84
114
|
exports.useCols = useCols;
|
|
115
|
+
exports.useSize = useSize;
|
|
85
116
|
exports.useSynchronousKeys = useSynchronousKeys;
|
|
86
117
|
// powered by h
|
|
@@ -4,7 +4,7 @@ import React from "react";
|
|
|
4
4
|
import type { HTableInstance } from "../modal";
|
|
5
5
|
import type { HRowSelection } from "../modal";
|
|
6
6
|
import type { AffixProps } from "antd/lib/affix";
|
|
7
|
-
interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource" | "rowSelection"> {
|
|
7
|
+
export interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource" | "rowSelection"> {
|
|
8
8
|
configData?: ConfigDataModal;
|
|
9
9
|
onPageChange?: (params: ParamsModal) => void;
|
|
10
10
|
emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
|
|
@@ -16,5 +16,5 @@ interface HTableBodyProps extends Omit<ProTableProps<any, any>, "dataSource" | "
|
|
|
16
16
|
affixProps?: AffixProps | false;
|
|
17
17
|
goTop?: boolean;
|
|
18
18
|
}
|
|
19
|
-
declare const _default: ({ configData, pagination, onPageChange, rowSelection, rowKey, emptyRender, errorRender, tableStyle, paginationStyle, headerTitle, options, actionRender, affixProps, goTop, ...props }: HTableBodyProps) => JSX.Element;
|
|
19
|
+
declare const _default: ({ configData, pagination, onPageChange, rowSelection, rowKey, emptyRender, errorRender, tableStyle, paginationStyle, headerTitle, options, actionRender, affixProps, goTop, size, ...props }: HTableBodyProps) => JSX.Element;
|
|
20
20
|
export default _default;
|
package/lib/HTableBody/index.js
CHANGED
|
@@ -20,11 +20,12 @@ var context = require('../context.js');
|
|
|
20
20
|
var React = require('react');
|
|
21
21
|
var antd = require('antd');
|
|
22
22
|
var TableConfig = require('../TableConfig.js');
|
|
23
|
-
var index$
|
|
23
|
+
var index$2 = require('../HTablePagination/index.js');
|
|
24
24
|
var index = require('../hooks/index.js');
|
|
25
25
|
var AlertMsg = require('./AlertMsg.js');
|
|
26
|
+
var index$1 = require('./Options/index.js');
|
|
26
27
|
|
|
27
|
-
var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle", "paginationStyle", "headerTitle", "options", "actionRender", "affixProps", "goTop"];
|
|
28
|
+
var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle", "paginationStyle", "headerTitle", "options", "actionRender", "affixProps", "goTop", "size"];
|
|
28
29
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
29
30
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
30
31
|
var defaultRender = function defaultRender() {
|
|
@@ -51,11 +52,13 @@ var Body = (function (_ref) {
|
|
|
51
52
|
tableStyle = _ref.tableStyle,
|
|
52
53
|
paginationStyle = _ref.paginationStyle,
|
|
53
54
|
headerTitle = _ref.headerTitle,
|
|
54
|
-
options = _ref.options,
|
|
55
|
+
_ref$options = _ref.options,
|
|
56
|
+
options = _ref$options === void 0 ? {} : _ref$options,
|
|
55
57
|
actionRender = _ref.actionRender,
|
|
56
58
|
affixProps = _ref.affixProps,
|
|
57
59
|
_ref$goTop = _ref.goTop,
|
|
58
60
|
goTop = _ref$goTop === void 0 ? true : _ref$goTop,
|
|
61
|
+
size = _ref.size,
|
|
59
62
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
60
63
|
var selectedRowKeys = rowSelection.selectedRowKeys;
|
|
61
64
|
var _useHTableContext = context.useHTableContext(),
|
|
@@ -75,14 +78,18 @@ var Body = (function (_ref) {
|
|
|
75
78
|
tableEmptyRender = _useHTableConfigConte2 === void 0 ? defaultRender : _useHTableConfigConte2,
|
|
76
79
|
_useHTableConfigConte3 = _useHTableConfigConte.errorRender,
|
|
77
80
|
tableErrorRender = _useHTableConfigConte3 === void 0 ? defaultRender : _useHTableConfigConte3;
|
|
81
|
+
var _useSize = hooks.useSize(size),
|
|
82
|
+
cuSize = _useSize.cuSize,
|
|
83
|
+
setCuSize = _useSize.setCuSize;
|
|
78
84
|
var bodyConfigData = configData || contextConfigData;
|
|
79
85
|
var _ref2 = data || {},
|
|
80
86
|
records = _ref2.records;
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
var _useCols = hooks.useCols({
|
|
88
|
+
configData: bodyConfigData,
|
|
89
|
+
table: tableInstance
|
|
90
|
+
}),
|
|
91
|
+
cols = _useCols.cols,
|
|
92
|
+
changeCols = _useCols.changeCols;
|
|
86
93
|
hooks.useSynchronousKeys({
|
|
87
94
|
selectedRowKeys: selectedRowKeys,
|
|
88
95
|
records: records,
|
|
@@ -112,7 +119,16 @@ var Body = (function (_ref) {
|
|
|
112
119
|
}),
|
|
113
120
|
type: "info"
|
|
114
121
|
})
|
|
115
|
-
}), jsxRuntime.
|
|
122
|
+
}), options && jsxRuntime.jsx(index$1.default, _objectSpread(_objectSpread({
|
|
123
|
+
reload: function reload() {
|
|
124
|
+
tableInstance.table.reloadWithParams();
|
|
125
|
+
}
|
|
126
|
+
}, options), {}, {
|
|
127
|
+
size: cuSize,
|
|
128
|
+
columns: cols,
|
|
129
|
+
setSizeChange: setCuSize,
|
|
130
|
+
onChange: changeCols
|
|
131
|
+
})), jsxRuntime.jsxs(antd.ConfigProvider, {
|
|
116
132
|
renderEmpty: function renderEmpty() {
|
|
117
133
|
if (error) {
|
|
118
134
|
return tableErrorRender === null || tableErrorRender === void 0 ? void 0 : tableErrorRender(tableInstance, error);
|
|
@@ -121,12 +137,9 @@ var Body = (function (_ref) {
|
|
|
121
137
|
},
|
|
122
138
|
children: [jsxRuntime.jsx(ProTable, _objectSpread(_objectSpread({}, props), {}, {
|
|
123
139
|
columns: cols,
|
|
140
|
+
size: cuSize,
|
|
124
141
|
search: false,
|
|
125
|
-
options:
|
|
126
|
-
reload: function reload() {
|
|
127
|
-
tableInstance.table.reloadWithParams();
|
|
128
|
-
}
|
|
129
|
-
},
|
|
142
|
+
options: false,
|
|
130
143
|
tableStyle: {
|
|
131
144
|
paddingBottom: 0
|
|
132
145
|
},
|
|
@@ -135,7 +148,7 @@ var Body = (function (_ref) {
|
|
|
135
148
|
rowKey: rowKey,
|
|
136
149
|
dataSource: records,
|
|
137
150
|
pagination: false
|
|
138
|
-
})), pagination !== false && jsxRuntime.jsx(index$
|
|
151
|
+
})), pagination !== false && jsxRuntime.jsx(index$2.default, _objectSpread({
|
|
139
152
|
onPageChange: onPageChange,
|
|
140
153
|
paginationStyle: paginationStyle,
|
|
141
154
|
affixProps: affixProps,
|
|
@@ -24,7 +24,7 @@ var index = require('../hooks/index.js');
|
|
|
24
24
|
var defaultSubComponent = require('./defaultSubComponent.js');
|
|
25
25
|
var context = require('../context.js');
|
|
26
26
|
|
|
27
|
-
var _excluded = ["colon", "searchType", "title", "name", "dataIndex", "itemProps", "searchRender"];
|
|
27
|
+
var _excluded = ["colon", "searchType", "title", "name", "dataIndex", "itemProps", "searchRender", "childrenDataIndex", "showSearch", "hideInTable"];
|
|
28
28
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
29
29
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context4 = ownKeys(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
30
30
|
var sizeObj = {
|
|
@@ -93,8 +93,11 @@ var formConfigDataItemProvider = function formConfigDataItemProvider(_ref) {
|
|
|
93
93
|
dataIndex = _ref.dataIndex,
|
|
94
94
|
_ref$itemProps = _ref.itemProps,
|
|
95
95
|
itemProps = _ref$itemProps === void 0 ? {} : _ref$itemProps,
|
|
96
|
-
searchRender = _ref.searchRender
|
|
97
|
-
|
|
96
|
+
searchRender = _ref.searchRender;
|
|
97
|
+
_ref.childrenDataIndex;
|
|
98
|
+
_ref.showSearch;
|
|
99
|
+
_ref.hideInTable;
|
|
100
|
+
var props = _objectWithoutProperties(_ref, _excluded);
|
|
98
101
|
var _itemProps$allowClear = itemProps.allowClear,
|
|
99
102
|
allowClear = _itemProps$allowClear === void 0 ? true : _itemProps$allowClear;
|
|
100
103
|
return _objectSpread(_objectSpread({}, props), {}, {
|
package/lib/hooks/useHTable.d.ts
CHANGED
package/lib/hooks/useHTable.js
CHANGED
package/lib/index.css
CHANGED
|
@@ -41,3 +41,46 @@
|
|
|
41
41
|
.ant-hw-table-header .ant-hw-table-header-item-hide {
|
|
42
42
|
display: none;
|
|
43
43
|
}
|
|
44
|
+
.ant-hw-table-body-option {
|
|
45
|
+
padding: 0px 24px 16px 24px;
|
|
46
|
+
}
|
|
47
|
+
.ant-hw-table-body-option-icon {
|
|
48
|
+
font-size: 16px;
|
|
49
|
+
}
|
|
50
|
+
.ant-hw-table-body-option-setting-content {
|
|
51
|
+
width: 198px;
|
|
52
|
+
margin: -10px -16px;
|
|
53
|
+
}
|
|
54
|
+
.ant-hw-table-body-option-setting-title {
|
|
55
|
+
width: 198px;
|
|
56
|
+
margin: 0px -16px;
|
|
57
|
+
padding: 6px 8px;
|
|
58
|
+
}
|
|
59
|
+
.ant-hw-table-body-option-setting-content-title {
|
|
60
|
+
display: -webkit-box;
|
|
61
|
+
display: -webkit-flex;
|
|
62
|
+
display: -ms-flexbox;
|
|
63
|
+
display: flex;
|
|
64
|
+
}
|
|
65
|
+
.ant-hw-table-body-option-tree .ant-tree-treenode {
|
|
66
|
+
width: 100%;
|
|
67
|
+
padding-left: 24px !important;
|
|
68
|
+
}
|
|
69
|
+
.ant-hw-table-body-option-tree .ant-tree-node-content-wrapper {
|
|
70
|
+
-webkit-box-flex: 1;
|
|
71
|
+
-webkit-flex: 1;
|
|
72
|
+
-ms-flex: 1;
|
|
73
|
+
flex: 1;
|
|
74
|
+
}
|
|
75
|
+
.ant-hw-table-body-option-tree .ant-tree-switcher {
|
|
76
|
+
width: 0px;
|
|
77
|
+
}
|
|
78
|
+
.ant-hw-table-body-option-tree .ant-tree-treenode-draggable {
|
|
79
|
+
padding-left: 0px !important;
|
|
80
|
+
}
|
|
81
|
+
.ant-hw-table-pointer {
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
}
|
|
84
|
+
.ant-hw-table-pointer:hover {
|
|
85
|
+
color: #1890ff;
|
|
86
|
+
}
|
package/lib/modal.d.ts
CHANGED
|
@@ -26,8 +26,12 @@ interface HColumns extends Omit<ProColumns, "render"> {
|
|
|
26
26
|
showSearch?: boolean;
|
|
27
27
|
searchType?: HItemProps["type"];
|
|
28
28
|
searchRender?: HItemProps["render"];
|
|
29
|
+
rowSelectionTitle?: boolean;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
interface BcItemModal {
|
|
32
|
+
childrenDataIndex?: string[];
|
|
33
|
+
}
|
|
34
|
+
export type ConfigItemModal = Omit<HItemProps, "render" | "type"> & HColumns & BcItemModal;
|
|
31
35
|
export type ConfigDataModal = ConfigItemModal[];
|
|
32
36
|
export type ActionRenderFn = (selectedRowKeys: RowObj, tableInstance: HTableInstance) => React.ReactNode;
|
|
33
37
|
export type FooterBtnRenderFn = (dom: React.ReactNode, total: string, selectedRowKeys: RowObj, setAllCheck: (row: RowObj) => void) => React.ReactNode;
|
|
@@ -69,6 +73,7 @@ export interface TableInstance {
|
|
|
69
73
|
dispatch: (key: string, params: any) => void;
|
|
70
74
|
reloadWithParams: (params?: ParamsModal) => Promise<any>;
|
|
71
75
|
getParams: () => any;
|
|
76
|
+
settingKeys: string[];
|
|
72
77
|
}
|
|
73
78
|
export interface HTableInstance {
|
|
74
79
|
form: HFormInstance;
|
package/package.json
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useClassName } from "../../hooks";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import type { ConfigDataModal } from "../../modal";
|
|
4
|
+
import { Tree } from "antd";
|
|
5
|
+
import type { ItemProps } from "./modal";
|
|
6
|
+
|
|
7
|
+
export const ColsSettingContent = ({
|
|
8
|
+
columns,
|
|
9
|
+
onChange,
|
|
10
|
+
checkKeys,
|
|
11
|
+
}: ItemProps) => {
|
|
12
|
+
const content = useClassName("hw-table-body-option-setting-content");
|
|
13
|
+
const titleClass = useClassName("hw-table-body-option-setting-content-title");
|
|
14
|
+
const treeClass = useClassName("hw-table-body-option-tree");
|
|
15
|
+
const contentTreeData = useMemo(() => {
|
|
16
|
+
const treeData: ConfigDataModal = [];
|
|
17
|
+
columns.forEach(({ dataIndex, title }) => {
|
|
18
|
+
if (dataIndex) {
|
|
19
|
+
treeData.push({
|
|
20
|
+
title: <div className={titleClass}>{title}</div>,
|
|
21
|
+
key: dataIndex.toString(),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return treeData;
|
|
26
|
+
}, [columns]);
|
|
27
|
+
const change = (key: string[]) => {
|
|
28
|
+
const newCols = [...columns];
|
|
29
|
+
newCols.forEach(({ dataIndex }, index) => {
|
|
30
|
+
if (!dataIndex) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const strDataIndex = dataIndex.toString();
|
|
34
|
+
const item = newCols[index];
|
|
35
|
+
newCols[index] = {
|
|
36
|
+
...item,
|
|
37
|
+
hideInTable: key.indexOf(strDataIndex) == -1,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
onChange(newCols);
|
|
41
|
+
};
|
|
42
|
+
return (
|
|
43
|
+
<div className={content}>
|
|
44
|
+
<div style={{ paddingTop: 6, paddingBottom: 6 }}>
|
|
45
|
+
<Tree
|
|
46
|
+
checkable
|
|
47
|
+
className={treeClass}
|
|
48
|
+
checkedKeys={checkKeys}
|
|
49
|
+
onCheck={(key)=>{
|
|
50
|
+
change((key as string[]))
|
|
51
|
+
}}
|
|
52
|
+
height={268}
|
|
53
|
+
treeData={contentTreeData}
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useClassName } from "../../hooks";
|
|
2
|
+
import { Checkbox, Row, Space, Typography } from "antd";
|
|
3
|
+
import type { ItemProps } from "./modal";
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
const { Link } = Typography;
|
|
6
|
+
export const Title = ({ columns, onChange, checkKeys }: ItemProps) => {
|
|
7
|
+
const title = useClassName("hw-table-body-option-setting-title");
|
|
8
|
+
const relLen = useMemo(() => {
|
|
9
|
+
const relArray = columns.filter(({ dataIndex }) => {
|
|
10
|
+
return !!dataIndex;
|
|
11
|
+
});
|
|
12
|
+
return relArray.length;
|
|
13
|
+
}, [columns]);
|
|
14
|
+
const allChange = (hideInTable: boolean) => {
|
|
15
|
+
const newCols = [...columns];
|
|
16
|
+
columns.forEach((item, index) => {
|
|
17
|
+
const { dataIndex } = item;
|
|
18
|
+
if (!dataIndex) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
newCols[index] = {
|
|
23
|
+
...item,
|
|
24
|
+
hideInTable,
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
onChange(newCols);
|
|
28
|
+
};
|
|
29
|
+
const reset = () => {
|
|
30
|
+
allChange(false);
|
|
31
|
+
};
|
|
32
|
+
const indeterminate = relLen !== checkKeys.length && checkKeys.length > 0;
|
|
33
|
+
return (
|
|
34
|
+
<Row className={title} justify={"space-between"}>
|
|
35
|
+
<Space size={4}>
|
|
36
|
+
<Checkbox
|
|
37
|
+
checked={relLen === checkKeys.length}
|
|
38
|
+
indeterminate={indeterminate}
|
|
39
|
+
onChange={(e) => {
|
|
40
|
+
allChange(!e.target.checked);
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
<span>列展示</span>
|
|
44
|
+
</Space>
|
|
45
|
+
<Link onClick={reset}>重置</Link>
|
|
46
|
+
</Row>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useClassName } from "../../hooks";
|
|
2
|
+
import { Row, Space, Tooltip, Dropdown, Menu, Popover } from "antd";
|
|
3
|
+
import {
|
|
4
|
+
ReloadOutlined,
|
|
5
|
+
ColumnHeightOutlined,
|
|
6
|
+
SettingOutlined,
|
|
7
|
+
} from "@ant-design/icons";
|
|
8
|
+
import type { SizeType } from "antd/lib/config-provider/SizeContext";
|
|
9
|
+
import { useEffect, useRef, useState } from "react";
|
|
10
|
+
import { ColsSettingContent } from "./Content";
|
|
11
|
+
import { Title } from "./Title";
|
|
12
|
+
import type { IProps } from "./modal";
|
|
13
|
+
import { useHTableContext } from "../../context";
|
|
14
|
+
import {defaultKeys} from "@/components/HTableBody/Options/utils";
|
|
15
|
+
export default ({
|
|
16
|
+
reload,
|
|
17
|
+
size = "middle",
|
|
18
|
+
density = true,
|
|
19
|
+
setSizeChange,
|
|
20
|
+
columns,
|
|
21
|
+
onChange,
|
|
22
|
+
}: IProps) => {
|
|
23
|
+
const className = useClassName("hw-table-body-option");
|
|
24
|
+
const pointer = useClassName([
|
|
25
|
+
"hw-table-pointer",
|
|
26
|
+
"hw-table-body-option-icon",
|
|
27
|
+
]);
|
|
28
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
29
|
+
const [keys, setKeys] = useState<string[]>([]);
|
|
30
|
+
const { tableInstance } = useHTableContext();
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const { keys: changeKeys, allKeys } = defaultKeys(columns);
|
|
33
|
+
tableInstance.table.settingKeys = allKeys;
|
|
34
|
+
setKeys(changeKeys);
|
|
35
|
+
}, [columns]);//同步改变
|
|
36
|
+
const SizeItem = () => {
|
|
37
|
+
const MenuComponent=(Menu as any);
|
|
38
|
+
const MenuItem=(Menu.Item as any);
|
|
39
|
+
return (
|
|
40
|
+
<MenuComponent
|
|
41
|
+
selectedKeys={[size]}
|
|
42
|
+
onClick={({ key }) => {
|
|
43
|
+
setSizeChange(key as SizeType);
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<MenuItem key="large">
|
|
47
|
+
<div style={{ width: 68 }}>默认</div>
|
|
48
|
+
</MenuItem>
|
|
49
|
+
<MenuItem key="middle">
|
|
50
|
+
<div>中等</div>
|
|
51
|
+
</MenuItem>
|
|
52
|
+
<MenuItem key="small">
|
|
53
|
+
<div>紧凑</div>
|
|
54
|
+
</MenuItem>
|
|
55
|
+
</MenuComponent>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
return (
|
|
59
|
+
<Row justify={"end"} className={className} ref={ref}>
|
|
60
|
+
<Space size={20}>
|
|
61
|
+
{reload && (
|
|
62
|
+
<Tooltip title="刷新">
|
|
63
|
+
<ReloadOutlined
|
|
64
|
+
className={pointer}
|
|
65
|
+
width={24}
|
|
66
|
+
onClick={(e) => {
|
|
67
|
+
if (typeof reload === "function") {
|
|
68
|
+
reload(e);
|
|
69
|
+
}
|
|
70
|
+
}}
|
|
71
|
+
/>
|
|
72
|
+
</Tooltip>
|
|
73
|
+
)}
|
|
74
|
+
{density && (
|
|
75
|
+
<Tooltip title="密度">
|
|
76
|
+
<Dropdown
|
|
77
|
+
overlay={SizeItem}
|
|
78
|
+
placement="bottom"
|
|
79
|
+
arrow
|
|
80
|
+
trigger={["click"]}
|
|
81
|
+
>
|
|
82
|
+
<ColumnHeightOutlined className={pointer} width={24} />
|
|
83
|
+
</Dropdown>
|
|
84
|
+
</Tooltip>
|
|
85
|
+
)}
|
|
86
|
+
<Tooltip title="列设置">
|
|
87
|
+
<Popover
|
|
88
|
+
content={
|
|
89
|
+
<ColsSettingContent
|
|
90
|
+
columns={columns}
|
|
91
|
+
checkKeys={keys}
|
|
92
|
+
onChange={onChange}
|
|
93
|
+
/>
|
|
94
|
+
}
|
|
95
|
+
title={
|
|
96
|
+
<Title columns={columns} checkKeys={keys} onChange={onChange} />
|
|
97
|
+
}
|
|
98
|
+
placement="bottomLeft"
|
|
99
|
+
getPopupContainer={() => ref.current||document.body}
|
|
100
|
+
trigger="click"
|
|
101
|
+
>
|
|
102
|
+
<SettingOutlined className={pointer} width={24} />
|
|
103
|
+
</Popover>
|
|
104
|
+
</Tooltip>
|
|
105
|
+
</Space>
|
|
106
|
+
</Row>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
|
|
2
|
+
import type { SizeType } from "antd/lib/config-provider/SizeContext";
|
|
3
|
+
import type { ConfigDataModal } from "../../modal";
|
|
4
|
+
|
|
5
|
+
export interface IProps extends OptionConfig {
|
|
6
|
+
size?: SizeType;
|
|
7
|
+
setSizeChange: (size: SizeType) => void;
|
|
8
|
+
columns: ConfigDataModal;
|
|
9
|
+
onChange: (cols: ConfigDataModal) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ItemProps extends Omit<IProps, "setSizeChange"> {
|
|
13
|
+
checkKeys: string[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {ConfigDataModal} from "../../modal";
|
|
2
|
+
|
|
3
|
+
export const defaultKeys = (cols: ConfigDataModal) => {
|
|
4
|
+
const keys: string[] = [];
|
|
5
|
+
const allKeys: string[] = [];
|
|
6
|
+
cols.forEach((value) => {
|
|
7
|
+
const { dataIndex, hideInTable, childrenDataIndex } = value;
|
|
8
|
+
if (hideInTable || !dataIndex) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
keys.push(dataIndex.toString());
|
|
12
|
+
if (childrenDataIndex) {
|
|
13
|
+
allKeys.push(...childrenDataIndex);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
allKeys.push(dataIndex.toString());
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
keys,
|
|
20
|
+
allKeys,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { HTableInstance, HTableProps } from "../modal";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { useEffect, useMemo } from "react";
|
|
2
|
+
import React, { useEffect, useState } from "react";
|
|
4
3
|
import { useHTableContext } from "../context";
|
|
5
4
|
import type { GetRowKey } from "rc-table/lib/interface";
|
|
6
5
|
import { RowSelectionBox, RowSelectionTitle } from "./RowSelection";
|
|
7
6
|
import type { HRowSelection } from "../modal";
|
|
7
|
+
import type { ConfigDataModal } from "../modal";
|
|
8
|
+
import type { SizeType } from "antd/lib/config-provider/SizeContext";
|
|
8
9
|
const rowSelectionCol = (rowSelection?: HRowSelection) => {
|
|
9
10
|
const { allPageCheck, onChange, getCheckboxProps } = rowSelection || {};
|
|
10
11
|
return {
|
|
@@ -15,8 +16,9 @@ const rowSelectionCol = (rowSelection?: HRowSelection) => {
|
|
|
15
16
|
getCheckboxProps={getCheckboxProps}
|
|
16
17
|
/>
|
|
17
18
|
),
|
|
18
|
-
dataIndex: "rowSelectionTitle",
|
|
19
19
|
width: 32,
|
|
20
|
+
rowSelectionTitle: true,
|
|
21
|
+
fixed: "left",
|
|
20
22
|
render: (dom, data) => {
|
|
21
23
|
return (
|
|
22
24
|
<RowSelectionBox
|
|
@@ -29,24 +31,37 @@ const rowSelectionCol = (rowSelection?: HRowSelection) => {
|
|
|
29
31
|
};
|
|
30
32
|
};
|
|
31
33
|
export const useCols = ({ configData, rowSelection, table }: HTableProps) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
const [cols, setCols] = useState<ConfigDataModal>([]);
|
|
35
|
+
const changeConfigData = (data: ConfigDataModal) => {
|
|
36
|
+
const colsArray = data.filter((item) => {
|
|
37
|
+
return !item.hideInTable;
|
|
38
|
+
});
|
|
34
39
|
if (rowSelection !== false) {
|
|
35
|
-
colsArray.splice(0, 0, rowSelectionCol(rowSelection));
|
|
40
|
+
colsArray.splice(0, 0, (rowSelectionCol(rowSelection) as any));
|
|
36
41
|
}
|
|
37
42
|
return colsArray.map((item) => {
|
|
38
43
|
const { render } = item;
|
|
39
44
|
return {
|
|
40
45
|
...item,
|
|
41
|
-
render: (dom: React.ReactNode,
|
|
46
|
+
render: (dom: React.ReactNode, itemData: any, index: number) => {
|
|
42
47
|
if (!render) {
|
|
43
48
|
return dom;
|
|
44
49
|
}
|
|
45
|
-
return render(dom,
|
|
50
|
+
return render(dom, itemData, index, table as HTableInstance);
|
|
46
51
|
},
|
|
47
52
|
};
|
|
48
53
|
});
|
|
54
|
+
};
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
setCols(changeConfigData(configData));
|
|
49
57
|
}, [configData, table, rowSelection]);
|
|
58
|
+
const changeCols = (cuCols: ConfigDataModal) => {
|
|
59
|
+
setCols(cuCols);
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
cols,
|
|
63
|
+
changeCols,
|
|
64
|
+
};
|
|
50
65
|
};
|
|
51
66
|
interface FilterKeysModal {
|
|
52
67
|
selectedRowKeys?: React.Key[];
|
|
@@ -70,3 +85,14 @@ export const useSynchronousKeys = ({
|
|
|
70
85
|
}
|
|
71
86
|
}, [selectedRowKeys, records, rowKey]);
|
|
72
87
|
};
|
|
88
|
+
|
|
89
|
+
export const useSize = (size: SizeType) => {
|
|
90
|
+
const [cuSize, setCuSize] = useState(size);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
setCuSize(size);
|
|
93
|
+
}, [size]);
|
|
94
|
+
return {
|
|
95
|
+
cuSize,
|
|
96
|
+
setCuSize,
|
|
97
|
+
};
|
|
98
|
+
};
|