@hw-component/table 1.1.6 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.eslintcache +1 -1
  2. package/es/HTableBody/Options/Content.d.ts +1 -1
  3. package/es/HTableBody/Options/Content.js +11 -25
  4. package/es/HTableBody/Options/Title.d.ts +1 -1
  5. package/es/HTableBody/Options/Title.js +25 -32
  6. package/es/HTableBody/Options/hooks.d.ts +2 -0
  7. package/es/HTableBody/Options/hooks.js +32 -0
  8. package/es/HTableBody/Options/index.d.ts +1 -1
  9. package/es/HTableBody/Options/index.js +14 -27
  10. package/es/HTableBody/Options/utils.d.ts +2 -7
  11. package/es/HTableBody/Options/utils.js +2 -57
  12. package/es/HTableBody/hooks.d.ts +13 -1
  13. package/es/HTableBody/hooks.js +52 -8
  14. package/es/HTableBody/index.d.ts +1 -1
  15. package/es/HTableBody/index.js +20 -6
  16. package/es/HTableBody/utils.d.ts +7 -0
  17. package/es/HTableBody/utils.js +99 -0
  18. package/es/hooks/useHTable.js +3 -1
  19. package/es/index.css +3 -0
  20. package/es/modal.d.ts +5 -4
  21. package/lib/HTableBody/Options/Content.d.ts +1 -1
  22. package/lib/HTableBody/Options/Content.js +11 -25
  23. package/lib/HTableBody/Options/Title.d.ts +1 -1
  24. package/lib/HTableBody/Options/Title.js +25 -32
  25. package/lib/HTableBody/Options/hooks.d.ts +2 -0
  26. package/lib/HTableBody/Options/hooks.js +33 -0
  27. package/lib/HTableBody/Options/index.d.ts +1 -1
  28. package/lib/HTableBody/Options/index.js +13 -26
  29. package/lib/HTableBody/Options/utils.d.ts +2 -7
  30. package/lib/HTableBody/Options/utils.js +1 -57
  31. package/lib/HTableBody/hooks.d.ts +13 -1
  32. package/lib/HTableBody/hooks.js +51 -6
  33. package/lib/HTableBody/index.d.ts +1 -1
  34. package/lib/HTableBody/index.js +19 -5
  35. package/lib/HTableBody/utils.d.ts +7 -0
  36. package/lib/HTableBody/utils.js +101 -0
  37. package/lib/hooks/useHTable.js +3 -1
  38. package/lib/index.css +3 -0
  39. package/lib/modal.d.ts +5 -4
  40. package/package.json +1 -1
  41. package/src/components/HTableBody/Options/Content.tsx +14 -18
  42. package/src/components/HTableBody/Options/Title.tsx +23 -22
  43. package/src/components/HTableBody/Options/hooks.ts +21 -0
  44. package/src/components/HTableBody/Options/index.tsx +8 -16
  45. package/src/components/HTableBody/Options/modal.d.ts +8 -2
  46. package/src/components/HTableBody/Options/utils.ts +2 -55
  47. package/src/components/HTableBody/hooks.tsx +47 -6
  48. package/src/components/HTableBody/index.tsx +13 -5
  49. package/src/components/HTableBody/utils.ts +91 -0
  50. package/src/components/Table.tsx +1 -0
  51. package/src/components/hooks/useHTable.tsx +3 -1
  52. package/src/components/index.less +3 -0
  53. package/src/components/modal.ts +5 -4
  54. package/src/pages/Table/index.tsx +10 -6
  55. package/src/pages/TableCustomize/index.tsx +12 -3
@@ -25,7 +25,8 @@ var AlertMsg = require('./AlertMsg.js');
25
25
  var index = require('./Options/index.js');
26
26
  var index$2 = require('./HeaderTitle/index.js');
27
27
 
28
- var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle", "paginationStyle", "headerTitle", "options", "actionRender", "affixProps", "goTop", "size", "optionsRender", "paginationActionRender", "localSorter"];
28
+ var _excluded = ["configData", "pagination", "onPageChange", "rowSelection", "rowKey", "emptyRender", "errorRender", "tableStyle", "paginationStyle", "headerTitle", "options", "actionRender", "affixProps", "goTop", "size", "optionsRender", "paginationActionRender", "localSorter", "columnsState"],
29
+ _excluded2 = ["value", "onChange", "reset"];
29
30
  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; }
30
31
  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; }
31
32
  var defaultRender = function defaultRender() {
@@ -61,6 +62,7 @@ var Body = (function (_ref) {
61
62
  optionsRender = _ref.optionsRender,
62
63
  paginationActionRender = _ref.paginationActionRender,
63
64
  localSorter = _ref.localSorter,
65
+ columnsState = _ref.columnsState,
64
66
  props = _objectWithoutProperties(_ref, _excluded);
65
67
  var _ref2 = rowSelection || {},
66
68
  selectedRowKeys = _ref2.selectedRowKeys,
@@ -93,8 +95,15 @@ var Body = (function (_ref) {
93
95
  table: tableInstance,
94
96
  rowSelection: rowSelection
95
97
  }),
96
- cols = _useCols.cols,
97
- changeCols = _useCols.changeCols;
98
+ cols = _useCols.cols;
99
+ var _useColumnsStateType = hooks.useColumnsStateType({
100
+ columnsState: columnsState,
101
+ columns: cols
102
+ }),
103
+ value = _useColumnsStateType.value,
104
+ onChange = _useColumnsStateType.onChange,
105
+ reset = _useColumnsStateType.reset,
106
+ selfColStatus = _objectWithoutProperties(_useColumnsStateType, _excluded2);
98
107
  hooks.useSynchronousKeys({
99
108
  selectedRowKeys: selectedRowKeys,
100
109
  records: records,
@@ -108,7 +117,9 @@ var Body = (function (_ref) {
108
117
  size: cuSize,
109
118
  columns: cols,
110
119
  setSizeChange: setCuSize,
111
- onChange: changeCols
120
+ colStatusValue: value || {},
121
+ onChange: onChange,
122
+ reset: reset
112
123
  }));
113
124
  var _selectedRowData$keys = _keysInstanceProperty(selectedRowData),
114
125
  keys = _selectedRowData$keys === void 0 ? [] : _selectedRowData$keys,
@@ -139,6 +150,9 @@ var Body = (function (_ref) {
139
150
  return tableEmptyRender === null || tableEmptyRender === void 0 ? void 0 : tableEmptyRender(tableInstance);
140
151
  },
141
152
  children: [jsxRuntime.jsx(ProTable, _objectSpread(_objectSpread({}, props), {}, {
153
+ columnsState: _objectSpread(_objectSpread({}, selfColStatus), {}, {
154
+ value: value
155
+ }),
142
156
  columns: cols,
143
157
  size: cuSize,
144
158
  search: false,
@@ -156,10 +170,10 @@ var Body = (function (_ref) {
156
170
  asc: asc
157
171
  });
158
172
  },
159
- options: false,
160
173
  tableStyle: {
161
174
  paddingBottom: 0
162
175
  },
176
+ options: false,
163
177
  rowSelection: false,
164
178
  loading: loading,
165
179
  rowKey: rowKey,
@@ -0,0 +1,7 @@
1
+ import { ColumnsStateType } from "@ant-design/pro-table/es/typing";
2
+ import { ConfigDataModal } from "@/components/modal";
3
+ export declare const mkChangeValue: (columnsState?: ColumnsStateType) => any;
4
+ export declare const outColSetting: (columns: ConfigDataModal, columnsState?: ColumnsStateType) => {
5
+ checkCols: ConfigDataModal;
6
+ keys: string[];
7
+ };
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
4
+ var _typeof = require('@babel/runtime-corejs3/helpers/typeof');
5
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/for-each');
6
+ var _keysInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/keys');
7
+ require('core-js/modules/es.object.keys.js');
8
+ require('core-js/modules/es.object.to-string.js');
9
+ require('core-js/modules/es.regexp.to-string.js');
10
+ var utils = require('./Options/utils.js');
11
+
12
+ var strToJson = function strToJson(str) {
13
+ if (!str) {
14
+ return {};
15
+ }
16
+ try {
17
+ var result = JSON.parse(str);
18
+ if (_typeof(result) === "object") {
19
+ return result;
20
+ }
21
+ return {};
22
+ } catch (e) {
23
+ return {};
24
+ }
25
+ };
26
+ var mkChangeValue = function mkChangeValue(columnsState) {
27
+ var _ref = columnsState || {},
28
+ persistenceType = _ref.persistenceType,
29
+ persistenceKey = _ref.persistenceKey,
30
+ value = _ref.value;
31
+ _ref.defaultValue;
32
+ _ref.onChange;
33
+ if (value) {
34
+ return value;
35
+ }
36
+ if (!persistenceKey) {
37
+ return {};
38
+ }
39
+ var cuPersistenceType = persistenceType || "localStorage";
40
+ var saveValStr = window[cuPersistenceType].getItem(persistenceKey);
41
+ return strToJson(saveValStr);
42
+ };
43
+ var childDataIndexProvider = function childDataIndexProvider(data, title) {
44
+ var keys = [];
45
+ var cols = [];
46
+ _forEachInstanceProperty(data).call(data, function (value) {
47
+ if (typeof value === "string") {
48
+ keys.push(value);
49
+ cols.push(utils.getItemValue({
50
+ title: title,
51
+ dataIndex: value
52
+ }));
53
+ return;
54
+ }
55
+ keys.push(value.dataIndex);
56
+ cols.push(utils.getItemValue(value));
57
+ });
58
+ return {
59
+ keys: keys,
60
+ cols: cols
61
+ };
62
+ };
63
+ var outColSetting = function outColSetting(columns) {
64
+ var columnsState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
65
+ var keys = [];
66
+ var checkCols = [];
67
+ _forEachInstanceProperty(columns).call(columns, function (value) {
68
+ var dataIndex = value.dataIndex,
69
+ titleStr = value.titleStr,
70
+ title = value.title,
71
+ hideInTable = value.hideInTable,
72
+ childrenDataIndex = value.childrenDataIndex;
73
+ if (hideInTable || !dataIndex) {
74
+ return;
75
+ }
76
+ var _ref2 = columnsState[dataIndex.toString()] || {},
77
+ _ref2$show = _ref2.show,
78
+ show = _ref2$show === void 0 ? true : _ref2$show;
79
+ if (!show) {
80
+ return;
81
+ }
82
+ if (childrenDataIndex) {
83
+ var _childDataIndexProvid = childDataIndexProvider(childrenDataIndex, titleStr || title),
84
+ childKeys = _keysInstanceProperty(_childDataIndexProvid),
85
+ childCols = _childDataIndexProvid.cols;
86
+ keys.push.apply(keys, _toConsumableArray(childKeys));
87
+ checkCols.push.apply(checkCols, _toConsumableArray(childCols));
88
+ return;
89
+ }
90
+ keys.push(dataIndex.toString());
91
+ checkCols.push(utils.getItemValue(value));
92
+ });
93
+ return {
94
+ checkCols: checkCols,
95
+ keys: keys
96
+ };
97
+ };
98
+
99
+ exports.mkChangeValue = mkChangeValue;
100
+ exports.outColSetting = outColSetting;
101
+ // powered by h
@@ -21,12 +21,14 @@ var useHTable = (function () {
21
21
  getParams: function getParams() {
22
22
  return {};
23
23
  },
24
- settingKeys: {},
25
24
  getSelectedRowData: function getSelectedRowData() {
26
25
  return {};
27
26
  },
28
27
  getTableSourceData: function getTableSourceData() {
29
28
  return [];
29
+ },
30
+ getColSettingKeys: function getColSettingKeys() {
31
+ return {};
30
32
  }
31
33
  };
32
34
  }, []);
package/lib/index.css CHANGED
@@ -10,6 +10,9 @@
10
10
  border-bottom-left-radius: 4px;
11
11
  border-bottom-right-radius: 4px;
12
12
  }
13
+ .ant-hw-table-body .ant-hw-table-pagination .ant-select {
14
+ width: auto;
15
+ }
13
16
  .ant-hw-table-body .ant-pro-card-body {
14
17
  padding-bottom: 0px;
15
18
  }
package/lib/modal.d.ts CHANGED
@@ -76,18 +76,19 @@ export interface HTableProps extends Omit<ProTableProps<any, any>, "request" | "
76
76
  labelWidth?: number;
77
77
  hideLabel?: boolean;
78
78
  }
79
+ interface ColCheckResultKeys {
80
+ keys?: string[];
81
+ checkCols?: ConfigDataModal;
82
+ }
79
83
  export interface TableInstance {
80
84
  reload: (params?: ParamsModal) => Promise<any>;
81
85
  setSelectedRowData: (keys: React.Key[], data: any) => void;
82
86
  dispatch: (key: string, params: any) => void;
83
87
  reloadWithParams: (params?: ParamsModal) => Promise<any>;
84
88
  getParams: () => any;
85
- settingKeys: {
86
- keys?: string[];
87
- checkCols?: ConfigDataModal;
88
- };
89
89
  getSelectedRowData: () => RowObj;
90
90
  getTableSourceData: () => any;
91
+ getColSettingKeys: () => ColCheckResultKeys;
91
92
  }
92
93
  export interface HTableInstance {
93
94
  form: HFormInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/table",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "基于antd二次开发table组件",
5
5
  "keywords": [
6
6
  "table"
@@ -7,7 +7,7 @@ import { getItemValue } from "./utils";
7
7
 
8
8
  export const ColsSettingContent = ({
9
9
  columns,
10
- onChange,
10
+ onCheck,
11
11
  checkKeys,
12
12
  }: ItemProps) => {
13
13
  const content = useClassName("hw-table-body-option-setting-content");
@@ -29,21 +29,17 @@ export const ColsSettingContent = ({
29
29
  });
30
30
  return treeData;
31
31
  }, [columns]);
32
- const change = (key: string[]) => {
33
- const newCols = [...columns];
34
- newCols.forEach(({ dataIndex }, index) => {
35
- if (!dataIndex) {
36
- return;
37
- }
38
- const strDataIndex = dataIndex.toString();
39
- const item = newCols[index];
40
- newCols[index] = {
41
- ...item,
42
- hideInTable: key.indexOf(strDataIndex) == -1,
43
- };
44
- });
45
- onChange(newCols);
46
- };
32
+ const check=(keys:string[])=>{
33
+ const notCheck:string[]=[];
34
+ contentTreeData.forEach(({key})=>{
35
+ const cuKey=(key as string);
36
+ const index=keys.indexOf(cuKey);
37
+ if (index===-1){
38
+ notCheck.push(cuKey)
39
+ }
40
+ })
41
+ onCheck(keys,notCheck)
42
+ }
47
43
  return (
48
44
  <div className={content}>
49
45
  <div style={{ paddingTop: 6, paddingBottom: 6 }}>
@@ -51,8 +47,8 @@ export const ColsSettingContent = ({
51
47
  checkable
52
48
  className={treeClass}
53
49
  checkedKeys={checkKeys}
54
- onCheck={(key) => {
55
- change(key as string[]);
50
+ onCheck={(key)=>{
51
+ check((key as string[]))
56
52
  }}
57
53
  height={268}
58
54
  treeData={contentTreeData}
@@ -3,31 +3,28 @@ import { Checkbox, Row, Space, Typography } from "antd";
3
3
  import type { ItemProps } from "./modal";
4
4
  import { useMemo } from "react";
5
5
  const { Link } = Typography;
6
- export const Title = ({ columns, onChange, checkKeys }: ItemProps) => {
6
+ export const Title = ({ columns, onCheck, checkKeys,reset }: ItemProps) => {
7
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) {
8
+ const relArrayKeys = useMemo(() => {
9
+ const keys:string[]=[];
10
+ columns.forEach((value)=>{
11
+ const {dataIndex,hideInTable}=value;
12
+ if (hideInTable || !dataIndex){
19
13
  return;
20
14
  }
21
- newCols[index] = {
22
- ...item,
23
- hideInTable,
24
- };
25
- });
26
- onChange(newCols);
27
- };
28
- const reset = () => {
29
- allChange(false);
15
+ const dataIndexStr=dataIndex.toString();
16
+ keys.push(dataIndexStr);
17
+ })
18
+ return keys;
19
+ }, [columns]);
20
+ const allKeys=columns
21
+ const allCheck = () => {
22
+ onCheck(relArrayKeys,[]);
30
23
  };
24
+ const allNotCheck=()=>{
25
+ onCheck([],relArrayKeys);
26
+ }
27
+ const relLen=relArrayKeys.length;
31
28
  const indeterminate = relLen !== checkKeys.length && checkKeys.length > 0;
32
29
  return (
33
30
  <Row className={title} justify={"space-between"}>
@@ -36,7 +33,11 @@ export const Title = ({ columns, onChange, checkKeys }: ItemProps) => {
36
33
  checked={relLen === checkKeys.length}
37
34
  indeterminate={indeterminate}
38
35
  onChange={(e) => {
39
- allChange(!e.target.checked);
36
+ if (e.target.checked){
37
+ allCheck();
38
+ return;
39
+ }
40
+ allNotCheck();
40
41
  }}
41
42
  />
42
43
  <span>列展示</span>
@@ -0,0 +1,21 @@
1
+ import {useMemo} from "react";
2
+ import {IProps} from "@/components/HTableBody/Options/modal";
3
+
4
+ export const useCheckKeys=({columns,colStatusValue}:Pick<IProps, "colStatusValue"|"columns">)=>{
5
+ return useMemo(()=>{
6
+ const keys:string[]=[];
7
+ columns.forEach((value)=>{
8
+ const {dataIndex,hideInTable}=value;
9
+ if (hideInTable || !dataIndex){
10
+ return;
11
+ }
12
+ const dataIndexStr=dataIndex.toString();
13
+ const {show=true}=colStatusValue[dataIndexStr]||{};
14
+ if (!show){
15
+ return;
16
+ }
17
+ keys.push(dataIndexStr);
18
+ })
19
+ return keys;
20
+ },[colStatusValue,columns])
21
+ }
@@ -6,12 +6,11 @@ import {
6
6
  SettingOutlined,
7
7
  } from "@ant-design/icons";
8
8
  import type { SizeType } from "antd/lib/config-provider/SizeContext";
9
- import { useEffect, useRef, useState } from "react";
9
+ import {useRef} from "react";
10
10
  import { ColsSettingContent } from "./Content";
11
11
  import { Title } from "./Title";
12
12
  import type { IProps } from "./modal";
13
- import { useHTableContext } from "../../context";
14
- import { defaultKeys } from "./utils";
13
+ import {useCheckKeys} from "@/components/HTableBody/Options/hooks";
15
14
  export default ({
16
15
  reload,
17
16
  size = "middle",
@@ -19,22 +18,15 @@ export default ({
19
18
  setSizeChange,
20
19
  columns,
21
20
  onChange,
21
+ colStatusValue,
22
+ reset
22
23
  }: IProps) => {
23
24
  const pointer = useClassName([
24
25
  "hw-table-pointer",
25
26
  "hw-table-body-option-icon",
26
27
  ]);
27
28
  const ref = useRef<HTMLDivElement>(null);
28
- const [keys, setKeys] = useState<string[]>([]);
29
- const { tableInstance } = useHTableContext();
30
- useEffect(() => {
31
- const { keys: changeKeys, allKeys, checkCols } = defaultKeys(columns);
32
- tableInstance.table.settingKeys = {
33
- keys: allKeys,
34
- checkCols: checkCols,
35
- };
36
- setKeys(changeKeys);
37
- }, [columns]); //同步改变
29
+ const checkKeys = useCheckKeys({columns,colStatusValue})
38
30
  const SizeItem = () => {
39
31
  const MenuComponent = Menu as any;
40
32
  const MenuItem = Menu.Item as any;
@@ -90,12 +82,12 @@ export default ({
90
82
  content={
91
83
  <ColsSettingContent
92
84
  columns={columns}
93
- checkKeys={keys}
94
- onChange={onChange}
85
+ checkKeys={checkKeys}
86
+ onCheck={onChange}
95
87
  />
96
88
  }
97
89
  title={
98
- <Title columns={columns} checkKeys={keys} onChange={onChange} />
90
+ <Title columns={columns} reset={reset} checkKeys={checkKeys} onCheck={onChange} />
99
91
  }
100
92
  placement="bottomLeft"
101
93
  getPopupContainer={() => ref.current || document.body}
@@ -1,14 +1,20 @@
1
1
  import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
2
2
  import type { SizeType } from "antd/lib/config-provider/SizeContext";
3
3
  import type { ConfigDataModal } from "../../modal";
4
+ import {ColumnsState} from "@ant-design/pro-table/es/container";
4
5
 
5
6
  export interface IProps extends OptionConfig {
6
7
  size?: SizeType;
7
8
  setSizeChange: (size: SizeType) => void;
8
9
  columns: ConfigDataModal;
9
- onChange: (cols: ConfigDataModal) => void;
10
+ onChange: (keys:string[],notCheck:string[]) => void;
11
+ colStatusValue:Record<string, ColumnsState>
12
+ reset:VoidFunction;
10
13
  }
11
14
 
12
- export interface ItemProps extends Omit<IProps, "setSizeChange"> {
15
+ export interface ItemProps {
13
16
  checkKeys: string[];
17
+ onCheck:(keys:string[],notCheck:string[])=>void;
18
+ columns: ConfigDataModal;
19
+ reset?:VoidFunction;
14
20
  }
@@ -1,5 +1,6 @@
1
1
  import type { ConfigDataModal, ConfigItemModal } from "../../modal";
2
2
  import React from "react";
3
+ import {ColumnsState} from "@ant-design/pro-table/es/container";
3
4
  export const getItemValue = (data: ConfigItemModal) => {
4
5
  const { dataIndex, title, titleStr, ...oData } = data;
5
6
  let resultTitle = React.isValidElement(title) ? title.props.children : title;
@@ -11,58 +12,4 @@ export const getItemValue = (data: ConfigItemModal) => {
11
12
  dataIndex,
12
13
  ...oData,
13
14
  };
14
- };
15
- const childDataIndexProvider = (
16
- data: ConfigItemModal[] | string[],
17
- title?: string | React.ReactNode
18
- ) => {
19
- const keys: string[] = [];
20
- const cols: ConfigDataModal = [];
21
- data.forEach((value) => {
22
- if (typeof value === "string") {
23
- keys.push(value);
24
- cols.push(
25
- getItemValue({
26
- title,
27
- dataIndex: value,
28
- })
29
- );
30
- return;
31
- }
32
- keys.push(value.dataIndex);
33
- cols.push(getItemValue(value));
34
- });
35
- return {
36
- keys,
37
- cols,
38
- };
39
- };
40
- export const defaultKeys = (cols: ConfigDataModal) => {
41
- const keys: string[] = [];
42
- const allKeys: string[] = [];
43
- const checkCols: ConfigDataModal = [];
44
- cols.forEach((value) => {
45
- const { title, titleStr, dataIndex, hideInTable, childrenDataIndex } =
46
- value;
47
- if (hideInTable || !dataIndex) {
48
- return;
49
- }
50
- keys.push(dataIndex.toString());
51
- if (childrenDataIndex) {
52
- const { keys: childKeys, cols: childCols } = childDataIndexProvider(
53
- childrenDataIndex,
54
- titleStr || title
55
- );
56
- allKeys.push(...childKeys);
57
- checkCols.push(...childCols);
58
- return;
59
- }
60
- allKeys.push(dataIndex.toString());
61
- checkCols.push(getItemValue(value));
62
- });
63
- return {
64
- keys,
65
- allKeys,
66
- checkCols,
67
- };
68
- };
15
+ };
@@ -4,11 +4,14 @@ import type {
4
4
  HRowSelection,
5
5
  ConfigDataModal,
6
6
  } from "../modal";
7
- import React, { useEffect, useState } from "react";
7
+ import React, {useEffect, useMemo, useState} from "react";
8
8
  import { useHTableContext } from "../context";
9
9
  import type { GetRowKey } from "rc-table/lib/interface";
10
10
  import { RowSelectionBox, RowSelectionTitle } from "./RowSelection";
11
11
  import type { SizeType } from "antd/lib/config-provider/SizeContext";
12
+ import {ColumnsStateType} from "@ant-design/pro-table/es/typing";
13
+ import {ColumnsState} from "@ant-design/pro-table/es/container";
14
+ import {mkChangeValue, outColSetting} from "./utils";
12
15
  const rowSelectionCol = (rowSelection?: HRowSelection) => {
13
16
  const { allPageCheck, onChange, getCheckboxProps } = rowSelection || {};
14
17
  return {
@@ -58,12 +61,8 @@ export const useCols = ({ configData, rowSelection, table }: HTableProps) => {
58
61
  useEffect(() => {
59
62
  setCols(changeConfigData(configData));
60
63
  }, [configData, table, rowSelection]);
61
- const changeCols = (cuCols: ConfigDataModal) => {
62
- setCols(cuCols);
63
- };
64
64
  return {
65
- cols,
66
- changeCols,
65
+ cols
67
66
  };
68
67
  };
69
68
  interface FilterKeysModal {
@@ -99,3 +98,45 @@ export const useSize = (size: SizeType) => {
99
98
  setCuSize,
100
99
  };
101
100
  };
101
+ interface useColumnsStateTypeModal {
102
+ columnsState?:ColumnsStateType;
103
+ columns:ConfigDataModal
104
+ }
105
+ export const useColumnsStateType=({columnsState,columns}:useColumnsStateTypeModal)=>{
106
+ const {
107
+ tableInstance
108
+ } = useHTableContext();
109
+ const {persistenceType,persistenceKey,value,defaultValue,onChange}=columnsState||{};
110
+ const [selfValue,setSelfValue]=useState<Record<string, ColumnsState>|undefined>(defaultValue);
111
+ const initTableColsVal = useMemo(() => {
112
+ return selfValue;
113
+ }, []);
114
+ useEffect(() => {
115
+ tableInstance.table.getColSettingKeys=()=>{
116
+ return outColSetting(columns,selfValue);
117
+ }
118
+ }, [selfValue]);
119
+ useEffect(() => {
120
+ setSelfValue(mkChangeValue(columnsState));
121
+ }, [value]);
122
+
123
+
124
+ const change=(keys:string[],notCheck:string[])=>{
125
+ const newObj={};
126
+ notCheck.forEach((key)=>{
127
+ newObj[key]={show:false}
128
+ });
129
+ setSelfValue(newObj);
130
+ onChange?.(newObj);
131
+ }
132
+ const reset=()=>{
133
+ setSelfValue(initTableColsVal);
134
+ }
135
+ return {
136
+ persistenceType,
137
+ persistenceKey,
138
+ value:selfValue,
139
+ onChange:change,
140
+ reset
141
+ }
142
+ }//设置选项
@@ -7,7 +7,7 @@ import type {
7
7
  HTableInstance,
8
8
  HRowSelection,
9
9
  } from "../modal";
10
- import { useCols, useSize, useSynchronousKeys } from "./hooks";
10
+ import {useCols, useColumnsStateType, useSize, useSynchronousKeys} from "./hooks";
11
11
  import { useHTableContext } from "../context";
12
12
  import React from "react";
13
13
  import { ConfigProvider, Empty, Alert } from "antd";
@@ -64,9 +64,9 @@ export default ({
64
64
  optionsRender,
65
65
  paginationActionRender,
66
66
  localSorter,
67
+ columnsState,
67
68
  ...props
68
69
  }: HTableBodyProps) => {
69
- // @ts-ignore
70
70
  const { selectedRowKeys, alwaysShowAlert: configAlwaysShowAlert } =
71
71
  rowSelection || {};
72
72
  const {
@@ -86,12 +86,14 @@ export default ({
86
86
  const { cuSize, setCuSize } = useSize(size);
87
87
  const bodyConfigData = configData || contextConfigData;
88
88
  const { records } = data || {};
89
- const { cols, changeCols } = useCols({
89
+
90
+ const { cols } = useCols({
90
91
  configData: bodyConfigData,
91
92
  table: tableInstance,
92
93
  rowSelection,
93
94
  });
94
95
 
96
+ const {value,onChange,reset,...selfColStatus} = useColumnsStateType({columnsState,columns:cols});
95
97
  useSynchronousKeys({ selectedRowKeys, records, rowKey });
96
98
  const optionsNode = options && (
97
99
  <Options
@@ -102,7 +104,9 @@ export default ({
102
104
  size={cuSize}
103
105
  columns={cols}
104
106
  setSizeChange={setCuSize}
105
- onChange={changeCols}
107
+ colStatusValue={value||{}}
108
+ onChange={onChange}
109
+ reset={reset}
106
110
  />
107
111
  );
108
112
  const { keys = [], selectAll } = selectedRowData;
@@ -136,6 +140,10 @@ export default ({
136
140
  >
137
141
  <ProTable
138
142
  {...props}
143
+ columnsState={{
144
+ ...selfColStatus,
145
+ value,
146
+ }}
139
147
  columns={cols as any}
140
148
  size={cuSize}
141
149
  search={false}
@@ -154,10 +162,10 @@ export default ({
154
162
  asc,
155
163
  });
156
164
  }}
157
- options={false}
158
165
  tableStyle={{
159
166
  paddingBottom: 0,
160
167
  }}
168
+ options={false}
161
169
  rowSelection={false}
162
170
  loading={loading}
163
171
  rowKey={rowKey}