@hw-component/table 1.1.7 → 1.1.9
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 +1 -1
- package/es/HTableBody/Options/Content.js +11 -25
- package/es/HTableBody/Options/Title.d.ts +1 -1
- package/es/HTableBody/Options/Title.js +25 -32
- package/es/HTableBody/Options/hooks.d.ts +2 -0
- package/es/HTableBody/Options/hooks.js +32 -0
- package/es/HTableBody/Options/index.d.ts +1 -1
- package/es/HTableBody/Options/index.js +31 -43
- package/es/HTableBody/Options/utils.d.ts +2 -7
- package/es/HTableBody/Options/utils.js +2 -57
- package/es/HTableBody/hooks.d.ts +13 -1
- package/es/HTableBody/hooks.js +52 -8
- package/es/HTableBody/index.d.ts +7 -2
- package/es/HTableBody/index.js +20 -6
- package/es/HTableBody/utils.d.ts +7 -0
- package/es/HTableBody/utils.js +99 -0
- package/es/HTableHeader/Context.d.ts +1 -1
- package/es/HTableHeader/defaultSubComponent.js +5 -1
- package/es/HTableHeader/index.d.ts +1 -1
- package/es/hooks/useHTable.js +3 -1
- package/es/modal.d.ts +7 -4
- package/lib/HTableBody/Options/Content.d.ts +1 -1
- package/lib/HTableBody/Options/Content.js +11 -25
- package/lib/HTableBody/Options/Title.d.ts +1 -1
- package/lib/HTableBody/Options/Title.js +25 -32
- package/lib/HTableBody/Options/hooks.d.ts +2 -0
- package/lib/HTableBody/Options/hooks.js +33 -0
- package/lib/HTableBody/Options/index.d.ts +1 -1
- package/lib/HTableBody/Options/index.js +30 -42
- package/lib/HTableBody/Options/utils.d.ts +2 -7
- package/lib/HTableBody/Options/utils.js +1 -57
- package/lib/HTableBody/hooks.d.ts +13 -1
- package/lib/HTableBody/hooks.js +51 -6
- package/lib/HTableBody/index.d.ts +7 -2
- package/lib/HTableBody/index.js +19 -5
- package/lib/HTableBody/utils.d.ts +7 -0
- package/lib/HTableBody/utils.js +101 -0
- package/lib/HTableHeader/Context.d.ts +1 -1
- package/lib/HTableHeader/defaultSubComponent.js +5 -1
- package/lib/HTableHeader/index.d.ts +1 -1
- package/lib/hooks/useHTable.js +3 -1
- package/lib/modal.d.ts +7 -4
- package/package.json +1 -1
- package/src/components/HTableBody/Options/Content.tsx +10 -14
- package/src/components/HTableBody/Options/Title.tsx +21 -20
- package/src/components/HTableBody/Options/hooks.ts +24 -0
- package/src/components/HTableBody/Options/index.tsx +23 -26
- package/src/components/HTableBody/Options/modal.d.ts +10 -2
- package/src/components/HTableBody/Options/utils.ts +1 -54
- package/src/components/HTableBody/hooks.tsx +49 -5
- package/src/components/HTableBody/index.tsx +29 -6
- package/src/components/HTableBody/utils.ts +93 -0
- package/src/components/HTableHeader/Context.tsx +7 -7
- package/src/components/HTableHeader/defaultSubComponent.tsx +7 -3
- package/src/components/HTableHeader/index.tsx +15 -15
- package/src/components/HTableHeader/modal.ts +1 -1
- package/src/components/hooks/useHTable.tsx +5 -3
- package/src/components/modal.ts +7 -10
- package/src/pages/Table/index.tsx +27 -9
- package/src/pages/TableCustomize/index.tsx +16 -2
|
@@ -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,
|
|
6
|
+
export const Title = ({ columns, onCheck, checkKeys, reset }: ItemProps) => {
|
|
7
7
|
const title = useClassName("hw-table-body-option-setting-title");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
hideInTable,
|
|
24
|
-
};
|
|
15
|
+
const dataIndexStr = dataIndex.toString();
|
|
16
|
+
keys.push(dataIndexStr);
|
|
25
17
|
});
|
|
26
|
-
|
|
18
|
+
return keys;
|
|
19
|
+
}, [columns]);
|
|
20
|
+
const allKeys = columns;
|
|
21
|
+
const allCheck = () => {
|
|
22
|
+
onCheck(relArrayKeys, []);
|
|
27
23
|
};
|
|
28
|
-
const
|
|
29
|
-
|
|
24
|
+
const allNotCheck = () => {
|
|
25
|
+
onCheck([], relArrayKeys);
|
|
30
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
|
-
|
|
36
|
+
if (e.target.checked) {
|
|
37
|
+
allCheck();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
allNotCheck();
|
|
40
41
|
}}
|
|
41
42
|
/>
|
|
42
43
|
<span>列展示</span>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { IProps } from "@/components/HTableBody/Options/modal";
|
|
3
|
+
|
|
4
|
+
export const useCheckKeys = ({
|
|
5
|
+
columns,
|
|
6
|
+
colStatusValue,
|
|
7
|
+
}: Pick<IProps, "colStatusValue" | "columns">) => {
|
|
8
|
+
return useMemo(() => {
|
|
9
|
+
const keys: string[] = [];
|
|
10
|
+
columns.forEach((value) => {
|
|
11
|
+
const { dataIndex, hideInTable } = value;
|
|
12
|
+
if (hideInTable || !dataIndex) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const dataIndexStr = dataIndex.toString();
|
|
16
|
+
const { show = true } = colStatusValue[dataIndexStr] || {};
|
|
17
|
+
if (!show) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
keys.push(dataIndexStr);
|
|
21
|
+
});
|
|
22
|
+
return keys;
|
|
23
|
+
}, [colStatusValue, columns]);
|
|
24
|
+
};
|
|
@@ -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 {
|
|
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 {
|
|
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,16 @@ export default ({
|
|
|
19
18
|
setSizeChange,
|
|
20
19
|
columns,
|
|
21
20
|
onChange,
|
|
21
|
+
colStatusValue,
|
|
22
|
+
reset,
|
|
23
|
+
settingRender,
|
|
22
24
|
}: IProps) => {
|
|
23
25
|
const pointer = useClassName([
|
|
24
26
|
"hw-table-pointer",
|
|
25
27
|
"hw-table-body-option-icon",
|
|
26
28
|
]);
|
|
27
29
|
const ref = useRef<HTMLDivElement>(null);
|
|
28
|
-
const
|
|
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]); //同步改变
|
|
30
|
+
const checkKeys = useCheckKeys({ columns, colStatusValue });
|
|
38
31
|
const SizeItem = () => {
|
|
39
32
|
const MenuComponent = Menu as any;
|
|
40
33
|
const MenuItem = Menu.Item as any;
|
|
@@ -58,8 +51,8 @@ export default ({
|
|
|
58
51
|
);
|
|
59
52
|
};
|
|
60
53
|
return (
|
|
61
|
-
<Row justify={"end"}
|
|
62
|
-
<Space size={
|
|
54
|
+
<Row justify={"end"}>
|
|
55
|
+
<Space size={15}>
|
|
63
56
|
{reload && (
|
|
64
57
|
<Tooltip title="刷新">
|
|
65
58
|
<ReloadOutlined
|
|
@@ -85,25 +78,29 @@ export default ({
|
|
|
85
78
|
</Dropdown>
|
|
86
79
|
</Tooltip>
|
|
87
80
|
)}
|
|
88
|
-
<
|
|
89
|
-
<Popover
|
|
81
|
+
<Popover
|
|
90
82
|
content={
|
|
91
83
|
<ColsSettingContent
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
columns={columns}
|
|
85
|
+
checkKeys={checkKeys}
|
|
86
|
+
onCheck={onChange}
|
|
95
87
|
/>
|
|
96
88
|
}
|
|
97
89
|
title={
|
|
98
|
-
<Title
|
|
90
|
+
<Title
|
|
91
|
+
columns={columns}
|
|
92
|
+
reset={reset}
|
|
93
|
+
checkKeys={checkKeys}
|
|
94
|
+
onCheck={onChange}
|
|
95
|
+
/>
|
|
99
96
|
}
|
|
100
|
-
placement="
|
|
97
|
+
placement="bottomRight"
|
|
101
98
|
getPopupContainer={() => ref.current || document.body}
|
|
99
|
+
arrowPointAtCenter
|
|
102
100
|
trigger="click"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
</Tooltip>
|
|
101
|
+
>
|
|
102
|
+
{settingRender?settingRender():<Tooltip title="列设置"><SettingOutlined className={pointer} width={24} /></Tooltip>}
|
|
103
|
+
</Popover>
|
|
107
104
|
</Space>
|
|
108
105
|
</Row>
|
|
109
106
|
);
|
|
@@ -1,14 +1,22 @@
|
|
|
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 type { ColumnsState } from "@ant-design/pro-table/es/container";
|
|
5
|
+
import React from "react";
|
|
4
6
|
|
|
5
7
|
export interface IProps extends OptionConfig {
|
|
6
8
|
size?: SizeType;
|
|
7
9
|
setSizeChange: (size: SizeType) => void;
|
|
8
10
|
columns: ConfigDataModal;
|
|
9
|
-
onChange: (
|
|
11
|
+
onChange: (keys: string[], notCheck: string[]) => void;
|
|
12
|
+
colStatusValue: Record<string, ColumnsState>;
|
|
13
|
+
reset: VoidFunction;
|
|
14
|
+
settingRender?:()=>React.ReactNode
|
|
10
15
|
}
|
|
11
16
|
|
|
12
|
-
export interface ItemProps
|
|
17
|
+
export interface ItemProps {
|
|
13
18
|
checkKeys: string[];
|
|
19
|
+
onCheck: (keys: string[], notCheck: string[]) => void;
|
|
20
|
+
columns: ConfigDataModal;
|
|
21
|
+
reset?: VoidFunction;
|
|
14
22
|
}
|
|
@@ -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;
|
|
@@ -12,57 +13,3 @@ export const getItemValue = (data: ConfigItemModal) => {
|
|
|
12
13
|
...oData,
|
|
13
14
|
};
|
|
14
15
|
};
|
|
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
|
-
};
|
|
@@ -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 type { ColumnsStateType } from "@ant-design/pro-table/es/typing";
|
|
13
|
+
import type { 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
65
|
cols,
|
|
66
|
-
changeCols,
|
|
67
66
|
};
|
|
68
67
|
};
|
|
69
68
|
interface FilterKeysModal {
|
|
@@ -99,3 +98,48 @@ 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 = ({
|
|
106
|
+
columnsState,
|
|
107
|
+
columns,
|
|
108
|
+
}: useColumnsStateTypeModal) => {
|
|
109
|
+
const { tableInstance } = useHTableContext();
|
|
110
|
+
const { persistenceType, persistenceKey, value, defaultValue, onChange } =
|
|
111
|
+
columnsState || {};
|
|
112
|
+
const [selfValue, setSelfValue] = useState<
|
|
113
|
+
Record<string, ColumnsState> | undefined
|
|
114
|
+
>(defaultValue);
|
|
115
|
+
const initTableColsVal = useMemo(() => {
|
|
116
|
+
return selfValue;
|
|
117
|
+
}, []);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
tableInstance.table.getColSettingKeys = () => {
|
|
120
|
+
return outColSetting(columns, selfValue);
|
|
121
|
+
};
|
|
122
|
+
}, [selfValue]);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
setSelfValue(mkChangeValue(columnsState));
|
|
125
|
+
}, [value]);
|
|
126
|
+
|
|
127
|
+
const change = (keys: string[], notCheck: string[]) => {
|
|
128
|
+
const newObj = {};
|
|
129
|
+
notCheck.forEach((key) => {
|
|
130
|
+
newObj[key] = { show: false };
|
|
131
|
+
});
|
|
132
|
+
setSelfValue(newObj);
|
|
133
|
+
onChange?.(newObj);
|
|
134
|
+
};
|
|
135
|
+
const reset = () => {
|
|
136
|
+
setSelfValue(initTableColsVal);
|
|
137
|
+
};
|
|
138
|
+
return {
|
|
139
|
+
persistenceType,
|
|
140
|
+
persistenceKey,
|
|
141
|
+
value: selfValue,
|
|
142
|
+
onChange: change,
|
|
143
|
+
reset,
|
|
144
|
+
};
|
|
145
|
+
}; //设置选项
|
|
@@ -7,7 +7,12 @@ import type {
|
|
|
7
7
|
HTableInstance,
|
|
8
8
|
HRowSelection,
|
|
9
9
|
} from "../modal";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
useCols,
|
|
12
|
+
useColumnsStateType,
|
|
13
|
+
useSize,
|
|
14
|
+
useSynchronousKeys,
|
|
15
|
+
} from "./hooks";
|
|
11
16
|
import { useHTableContext } from "../context";
|
|
12
17
|
import React from "react";
|
|
13
18
|
import { ConfigProvider, Empty, Alert } from "antd";
|
|
@@ -18,8 +23,13 @@ import AlertMsg from "./AlertMsg";
|
|
|
18
23
|
import type { AffixProps } from "antd/lib/affix";
|
|
19
24
|
import Options from "./Options";
|
|
20
25
|
import HeaderTitle from "./HeaderTitle";
|
|
26
|
+
import {OptionConfig} from "@ant-design/pro-table/lib/components/ToolBar";
|
|
27
|
+
|
|
28
|
+
export interface OptionModal extends OptionConfig {
|
|
29
|
+
settingRender?:()=>React.ReactNode
|
|
30
|
+
}
|
|
21
31
|
export interface HTableBodyProps
|
|
22
|
-
extends Omit<ProTableProps<any, any>, "dataSource" | "rowSelection"> {
|
|
32
|
+
extends Omit<ProTableProps<any, any>, "dataSource" | "rowSelection"|"options"> {
|
|
23
33
|
configData?: ConfigDataModal;
|
|
24
34
|
onPageChange?: (params: ParamsModal) => void;
|
|
25
35
|
emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
|
|
@@ -36,6 +46,7 @@ export interface HTableBodyProps
|
|
|
36
46
|
optionsRender?: (node: React.ReactNode) => React.ReactNode;
|
|
37
47
|
paginationActionRender?: (tableInstance: HTableInstance) => React.ReactNode;
|
|
38
48
|
localSorter?: boolean;
|
|
49
|
+
options?:OptionModal|false
|
|
39
50
|
}
|
|
40
51
|
const defaultRender = () => {
|
|
41
52
|
return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />;
|
|
@@ -64,9 +75,9 @@ export default ({
|
|
|
64
75
|
optionsRender,
|
|
65
76
|
paginationActionRender,
|
|
66
77
|
localSorter,
|
|
78
|
+
columnsState,
|
|
67
79
|
...props
|
|
68
80
|
}: HTableBodyProps) => {
|
|
69
|
-
// @ts-ignore
|
|
70
81
|
const { selectedRowKeys, alwaysShowAlert: configAlwaysShowAlert } =
|
|
71
82
|
rowSelection || {};
|
|
72
83
|
const {
|
|
@@ -86,12 +97,17 @@ export default ({
|
|
|
86
97
|
const { cuSize, setCuSize } = useSize(size);
|
|
87
98
|
const bodyConfigData = configData || contextConfigData;
|
|
88
99
|
const { records } = data || {};
|
|
89
|
-
|
|
100
|
+
|
|
101
|
+
const { cols } = useCols({
|
|
90
102
|
configData: bodyConfigData,
|
|
91
103
|
table: tableInstance,
|
|
92
104
|
rowSelection,
|
|
93
105
|
});
|
|
94
106
|
|
|
107
|
+
const { value, onChange, reset, ...selfColStatus } = useColumnsStateType({
|
|
108
|
+
columnsState,
|
|
109
|
+
columns: cols,
|
|
110
|
+
});
|
|
95
111
|
useSynchronousKeys({ selectedRowKeys, records, rowKey });
|
|
96
112
|
const optionsNode = options && (
|
|
97
113
|
<Options
|
|
@@ -102,7 +118,9 @@ export default ({
|
|
|
102
118
|
size={cuSize}
|
|
103
119
|
columns={cols}
|
|
104
120
|
setSizeChange={setCuSize}
|
|
105
|
-
|
|
121
|
+
colStatusValue={value || {}}
|
|
122
|
+
onChange={onChange}
|
|
123
|
+
reset={reset}
|
|
106
124
|
/>
|
|
107
125
|
);
|
|
108
126
|
const { keys = [], selectAll } = selectedRowData;
|
|
@@ -136,6 +154,10 @@ export default ({
|
|
|
136
154
|
>
|
|
137
155
|
<ProTable
|
|
138
156
|
{...props}
|
|
157
|
+
columnsState={{
|
|
158
|
+
...selfColStatus,
|
|
159
|
+
value,
|
|
160
|
+
}}
|
|
139
161
|
columns={cols as any}
|
|
140
162
|
size={cuSize}
|
|
141
163
|
search={false}
|
|
@@ -154,15 +176,16 @@ export default ({
|
|
|
154
176
|
asc,
|
|
155
177
|
});
|
|
156
178
|
}}
|
|
157
|
-
options={false}
|
|
158
179
|
tableStyle={{
|
|
159
180
|
paddingBottom: 0,
|
|
160
181
|
}}
|
|
182
|
+
options={false}
|
|
161
183
|
rowSelection={false}
|
|
162
184
|
loading={loading}
|
|
163
185
|
rowKey={rowKey}
|
|
164
186
|
dataSource={records}
|
|
165
187
|
pagination={false}
|
|
188
|
+
|
|
166
189
|
/>
|
|
167
190
|
{pagination !== false && (
|
|
168
191
|
<HTablePagination
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ColumnsStateType } from "@ant-design/pro-table/es/typing";
|
|
2
|
+
import type { ConfigDataModal, ConfigItemModal } from "@/components/modal";
|
|
3
|
+
import type 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 } =
|
|
23
|
+
columnsState || {};
|
|
24
|
+
if (value) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
if (!persistenceKey) {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
const cuPersistenceType = persistenceType || "localStorage";
|
|
31
|
+
const saveValStr = window[cuPersistenceType].getItem(persistenceKey);
|
|
32
|
+
return strToJson(saveValStr);
|
|
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
|
+
export const outColSetting = (
|
|
62
|
+
columns: ConfigDataModal,
|
|
63
|
+
columnsState: ColumnsStateType = {}
|
|
64
|
+
) => {
|
|
65
|
+
const keys: string[] = [];
|
|
66
|
+
const checkCols: ConfigDataModal = [];
|
|
67
|
+
columns.forEach((value) => {
|
|
68
|
+
const { dataIndex, titleStr, title, hideInTable, childrenDataIndex } =
|
|
69
|
+
value;
|
|
70
|
+
if (hideInTable || !dataIndex) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const { show = true } = columnsState[dataIndex.toString()] || {};
|
|
74
|
+
if (!show) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (childrenDataIndex) {
|
|
78
|
+
const { keys: childKeys, cols: childCols } = childDataIndexProvider(
|
|
79
|
+
childrenDataIndex,
|
|
80
|
+
titleStr || title
|
|
81
|
+
);
|
|
82
|
+
keys.push(...childKeys);
|
|
83
|
+
checkCols.push(...childCols);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
keys.push(dataIndex.toString());
|
|
87
|
+
checkCols.push(getItemValue(value));
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
checkCols,
|
|
91
|
+
keys,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import React, {useContext} from "react";
|
|
2
|
-
import {IHeaderProps} from "./modal";
|
|
3
|
-
const Context=React.createContext<IHeaderProps>({});
|
|
1
|
+
import React, { useContext } from "react";
|
|
2
|
+
import type { IHeaderProps } from "./modal";
|
|
3
|
+
const Context = React.createContext<IHeaderProps>({});
|
|
4
4
|
|
|
5
|
-
export const HeaderProvider=Context.Provider;
|
|
5
|
+
export const HeaderProvider = Context.Provider;
|
|
6
6
|
|
|
7
|
-
export const useHeaderContext=()=>{
|
|
8
|
-
|
|
9
|
-
}
|
|
7
|
+
export const useHeaderContext = () => {
|
|
8
|
+
return useContext(Context);
|
|
9
|
+
};
|
|
@@ -4,7 +4,7 @@ import { useHTableContext } from "../context";
|
|
|
4
4
|
import React, { useMemo } from "react";
|
|
5
5
|
import { DownOutlined, UpOutlined } from "@ant-design/icons";
|
|
6
6
|
import type { RowProps } from "antd/lib/grid/row";
|
|
7
|
-
import {useHeaderContext} from "./Context";
|
|
7
|
+
import { useHeaderContext } from "./Context";
|
|
8
8
|
interface IProps {
|
|
9
9
|
form: HFormInstance;
|
|
10
10
|
}
|
|
@@ -36,7 +36,7 @@ const OpenComponent = () => {
|
|
|
36
36
|
};
|
|
37
37
|
export const DefaultSubComponent = ({ form }: IProps) => {
|
|
38
38
|
const { loading, headerOpen } = useHTableContext();
|
|
39
|
-
const {onReset}=useHeaderContext();
|
|
39
|
+
const { onReset } = useHeaderContext();
|
|
40
40
|
const hide = typeof headerOpen === "undefined";
|
|
41
41
|
const { justify, style } = useMemo(() => {
|
|
42
42
|
if (headerOpen === true || hide) {
|
|
@@ -71,7 +71,11 @@ export const DefaultSubComponent = ({ form }: IProps) => {
|
|
|
71
71
|
<Button
|
|
72
72
|
style={{ borderRadius: 4 }}
|
|
73
73
|
onClick={() => {
|
|
74
|
-
onReset
|
|
74
|
+
if (onReset) {
|
|
75
|
+
onReset();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
form.resetFields();
|
|
75
79
|
}}
|
|
76
80
|
>
|
|
77
81
|
重置
|
|
@@ -5,7 +5,7 @@ import React from "react";
|
|
|
5
5
|
import { useClassName } from "../hooks";
|
|
6
6
|
import type { IHeaderProps } from "./modal";
|
|
7
7
|
import { useHideMoreTitle } from "./hooks";
|
|
8
|
-
import {HeaderProvider} from "./Context";
|
|
8
|
+
import { HeaderProvider } from "./Context";
|
|
9
9
|
|
|
10
10
|
const defaultSearchSpan = {
|
|
11
11
|
xxl: 4,
|
|
@@ -22,7 +22,7 @@ export default ({
|
|
|
22
22
|
initValues,
|
|
23
23
|
hideLabel,
|
|
24
24
|
labelWidth,
|
|
25
|
-
onReset
|
|
25
|
+
onReset,
|
|
26
26
|
}: IHeaderProps) => {
|
|
27
27
|
const {
|
|
28
28
|
tableInstance,
|
|
@@ -55,20 +55,20 @@ export default ({
|
|
|
55
55
|
className={`hw_table_header ${className}`}
|
|
56
56
|
bodyStyle={{ paddingBottom: 0 }}
|
|
57
57
|
>
|
|
58
|
-
<HeaderProvider value={{onReset}}>
|
|
58
|
+
<HeaderProvider value={{ onReset }}>
|
|
59
59
|
<HForm
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
itemSpan={searchSpan}
|
|
61
|
+
onFinish={subOnFinish}
|
|
62
|
+
submitLoading={loading}
|
|
63
|
+
gutter={[20, 0]}
|
|
64
|
+
initialValues={initValues}
|
|
65
|
+
hideLabel={
|
|
66
|
+
typeof tableHideLabel === "undefined" ? true : tableHideLabel
|
|
67
|
+
}
|
|
68
|
+
configData={nConfigData}
|
|
69
|
+
form={form}
|
|
70
|
+
colon={true}
|
|
71
|
+
labelWidth={tableLabelWidth}
|
|
72
72
|
/>
|
|
73
73
|
</HeaderProvider>
|
|
74
74
|
</Card>
|
|
@@ -17,13 +17,15 @@ export default (): HTableInstance => {
|
|
|
17
17
|
getParams: () => {
|
|
18
18
|
return {} as any;
|
|
19
19
|
},
|
|
20
|
-
settingKeys: {},
|
|
21
20
|
getSelectedRowData: () => {
|
|
22
21
|
return {};
|
|
23
22
|
},
|
|
24
|
-
getTableSourceData:()=>{
|
|
23
|
+
getTableSourceData: () => {
|
|
25
24
|
return [];
|
|
26
|
-
}
|
|
25
|
+
},
|
|
26
|
+
getColSettingKeys: () => {
|
|
27
|
+
return {};
|
|
28
|
+
},
|
|
27
29
|
};
|
|
28
30
|
}, []);
|
|
29
31
|
return {
|