@hw-component/table 1.1.7 → 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 (52) 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/modal.d.ts +5 -4
  20. package/lib/HTableBody/Options/Content.d.ts +1 -1
  21. package/lib/HTableBody/Options/Content.js +11 -25
  22. package/lib/HTableBody/Options/Title.d.ts +1 -1
  23. package/lib/HTableBody/Options/Title.js +25 -32
  24. package/lib/HTableBody/Options/hooks.d.ts +2 -0
  25. package/lib/HTableBody/Options/hooks.js +33 -0
  26. package/lib/HTableBody/Options/index.d.ts +1 -1
  27. package/lib/HTableBody/Options/index.js +13 -26
  28. package/lib/HTableBody/Options/utils.d.ts +2 -7
  29. package/lib/HTableBody/Options/utils.js +1 -57
  30. package/lib/HTableBody/hooks.d.ts +13 -1
  31. package/lib/HTableBody/hooks.js +51 -6
  32. package/lib/HTableBody/index.d.ts +1 -1
  33. package/lib/HTableBody/index.js +19 -5
  34. package/lib/HTableBody/utils.d.ts +7 -0
  35. package/lib/HTableBody/utils.js +101 -0
  36. package/lib/hooks/useHTable.js +3 -1
  37. package/lib/modal.d.ts +5 -4
  38. package/package.json +1 -1
  39. package/src/components/HTableBody/Options/Content.tsx +14 -18
  40. package/src/components/HTableBody/Options/Title.tsx +23 -22
  41. package/src/components/HTableBody/Options/hooks.ts +21 -0
  42. package/src/components/HTableBody/Options/index.tsx +8 -16
  43. package/src/components/HTableBody/Options/modal.d.ts +8 -2
  44. package/src/components/HTableBody/Options/utils.ts +2 -55
  45. package/src/components/HTableBody/hooks.tsx +47 -6
  46. package/src/components/HTableBody/index.tsx +13 -5
  47. package/src/components/HTableBody/utils.ts +91 -0
  48. package/src/components/Table.tsx +1 -0
  49. package/src/components/hooks/useHTable.tsx +3 -1
  50. package/src/components/modal.ts +5 -4
  51. package/src/pages/Table/index.tsx +7 -2
  52. package/src/pages/TableCustomize/index.tsx +12 -3
@@ -0,0 +1,91 @@
1
+ import {ColumnsStateType} from "@ant-design/pro-table/es/typing";
2
+ import {ConfigDataModal, ConfigItemModal} from "@/components/modal";
3
+ import React from "react";
4
+ import {getItemValue} from "./Options/utils";
5
+
6
+ const strToJson=(str:string|null)=>{
7
+ if (!str){
8
+ return {};
9
+ }
10
+ try {
11
+ const result=JSON.parse(str);
12
+ if (typeof result==="object"){
13
+ return result;
14
+ }
15
+ return {};
16
+ }catch (e) {
17
+ return {}
18
+ }
19
+ }
20
+
21
+ export const mkChangeValue=(columnsState?:ColumnsStateType)=>{
22
+ const {persistenceType,persistenceKey,value,defaultValue,onChange}=columnsState||{};
23
+ if (value){
24
+ return value
25
+ }
26
+ if (!persistenceKey){
27
+ return {};
28
+ }
29
+ const cuPersistenceType=persistenceType||"localStorage";
30
+ const saveValStr=window[cuPersistenceType].getItem(persistenceKey);
31
+ return strToJson(saveValStr);
32
+ }//获取默认值
33
+
34
+
35
+ const childDataIndexProvider = (
36
+ data: ConfigItemModal[] | string[],
37
+ title?: string | React.ReactNode
38
+ ) => {
39
+ const keys: string[] = [];
40
+ const cols: ConfigDataModal = [];
41
+ data.forEach((value) => {
42
+ if (typeof value === "string") {
43
+ keys.push(value);
44
+ cols.push(
45
+ getItemValue({
46
+ title,
47
+ dataIndex: value,
48
+ })
49
+ );
50
+ return;
51
+ }
52
+ keys.push(value.dataIndex);
53
+ cols.push(getItemValue(value));
54
+ });
55
+ return {
56
+ keys,
57
+ cols,
58
+ };
59
+ };
60
+
61
+
62
+ export const outColSetting=(columns:ConfigDataModal,columnsState:ColumnsStateType={})=>{
63
+ const keys: string[] = [];
64
+ const checkCols:ConfigDataModal=[];
65
+ columns.forEach((value) => {
66
+ const { dataIndex,titleStr,title, hideInTable, childrenDataIndex } =
67
+ value;
68
+ if (hideInTable || !dataIndex) {
69
+ return;
70
+ }
71
+ const {show=true}=columnsState[dataIndex.toString()]||{};
72
+ if (!show){
73
+ return;
74
+ }
75
+ if (childrenDataIndex) {
76
+ const { keys: childKeys, cols: childCols } = childDataIndexProvider(
77
+ childrenDataIndex,
78
+ titleStr || title
79
+ );
80
+ keys.push(...childKeys);
81
+ checkCols.push(...childCols);
82
+ return;
83
+ }
84
+ keys.push(dataIndex.toString());
85
+ checkCols.push(getItemValue(value));
86
+ });
87
+ return {
88
+ checkCols,
89
+ keys
90
+ };
91
+ }
@@ -55,6 +55,7 @@ export default ({
55
55
  },
56
56
  selectedRowData,
57
57
  dataSource: data,
58
+
58
59
  });
59
60
  return (
60
61
  <HTableContext.Provider
@@ -17,12 +17,14 @@ export default (): HTableInstance => {
17
17
  getParams: () => {
18
18
  return {} as any;
19
19
  },
20
- settingKeys: {},
21
20
  getSelectedRowData: () => {
22
21
  return {};
23
22
  },
24
23
  getTableSourceData:()=>{
25
24
  return [];
25
+ },
26
+ getColSettingKeys:()=>{
27
+ return {}
26
28
  }
27
29
  };
28
30
  }, []);
@@ -114,18 +114,19 @@ export interface HTableProps
114
114
  labelWidth?: number;
115
115
  hideLabel?: boolean;
116
116
  }
117
+ interface ColCheckResultKeys {
118
+ keys?: string[];
119
+ checkCols?: ConfigDataModal;
120
+ };
117
121
  export interface TableInstance {
118
122
  reload: (params?: ParamsModal) => Promise<any>;
119
123
  setSelectedRowData: (keys: React.Key[], data: any) => void;
120
124
  dispatch: (key: string, params: any) => void;
121
125
  reloadWithParams: (params?: ParamsModal) => Promise<any>;
122
126
  getParams: () => any;
123
- settingKeys: {
124
- keys?: string[];
125
- checkCols?: ConfigDataModal;
126
- };
127
127
  getSelectedRowData: () => RowObj;
128
128
  getTableSourceData: () => any;
129
+ getColSettingKeys:()=>ColCheckResultKeys;
129
130
  }
130
131
  export interface HTableInstance {
131
132
  form: HFormInstance;
@@ -100,11 +100,16 @@ export default () => {
100
100
  scroll={{
101
101
  x: 1000,
102
102
  }}
103
+ columnsState={{
104
+ persistenceKey:"test",
105
+ persistenceType:"localStorage"
106
+ }}
103
107
  formInitValues={{
104
108
  name2: 1,
105
109
  }}
106
- headerTitle={<Button type={"primary"}>操作</Button>}
107
- options={false}
110
+ headerTitle={<Button type={"primary"} onClick={()=>{
111
+ console.log(hTable.table.getColSettingKeys());
112
+ }}>操作</Button>}
108
113
  paginationActionRender={() => {
109
114
  return <div>你大爷</div>;
110
115
  }}
@@ -3,7 +3,7 @@ import {
3
3
  HTableHeader,
4
4
  HTableBody,
5
5
  HTableFooter,
6
- HTablePagination,
6
+ HTablePagination, useHTable,
7
7
  } from "@/components";
8
8
  import { useRequest } from "ahooks";
9
9
  import { Space } from "antd";
@@ -28,6 +28,7 @@ const AddBtn = (props) => {
28
28
  return <div>fff</div>;
29
29
  };
30
30
  export default () => {
31
+ const hTable=useHTable();
31
32
  const { run, loading, error, data } = useRequest(
32
33
  (params) => {
33
34
  const { current = 1 } = params;
@@ -57,14 +58,22 @@ export default () => {
57
58
  configData={configData}
58
59
  loading={loading}
59
60
  error={error}
61
+ table={hTable}
60
62
  dataSource={data}
61
63
  reload={run}
62
- manual={true}
63
64
  >
64
65
  <Space direction={"vertical"} style={{ width: "100%" }}>
65
66
  <HTableHeader />
66
67
  <HTableBody
67
- headerTitle={<AddBtn />}
68
+ headerTitle={<div onClick={()=>{
69
+ console.log( hTable.table.getColSettingKeys())
70
+ }}>
71
+ 点我获取
72
+ </div>}
73
+ columnsState={{
74
+ persistenceKey:"zd",
75
+ persistenceType:"localStorage"
76
+ }}
68
77
  affixProps={{
69
78
  target: () => document.querySelector(".body"),
70
79
  }}