@hw-component/table 1.9.87 → 1.9.88

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 (41) hide show
  1. package/.eslintcache +1 -1
  2. package/es/HTableBody/Options/utils.d.ts +5 -2
  3. package/es/HTableBody/RowCheckBox/RowItem.d.ts +2 -8
  4. package/es/HTableBody/RowCheckBox/hooks.d.ts +2 -2
  5. package/es/HTableBody/RowRadioBoxSelection.d.ts +1 -8
  6. package/es/HTableBody/hooks/useRowClassName.d.ts +4 -0
  7. package/es/HTableBody/hooks/useRowClassName.js +39 -0
  8. package/es/HTableBody/index.js +8 -25
  9. package/es/HTableBody/modal.d.ts +7 -1
  10. package/es/HTableBody/utils.d.ts +1 -0
  11. package/es/HTableHeader/RangePickerSearch.d.ts +1 -1
  12. package/es/TableConfig.d.ts +2 -0
  13. package/es/TableConfig.js +4 -2
  14. package/es/modal.d.ts +2 -1
  15. package/es/render/Text.d.ts +0 -1
  16. package/lib/HTableBody/Options/utils.d.ts +5 -2
  17. package/lib/HTableBody/RowCheckBox/RowItem.d.ts +2 -8
  18. package/lib/HTableBody/RowCheckBox/hooks.d.ts +2 -2
  19. package/lib/HTableBody/RowRadioBoxSelection.d.ts +1 -8
  20. package/lib/HTableBody/hooks/useRowClassName.d.ts +4 -0
  21. package/lib/HTableBody/hooks/useRowClassName.js +42 -0
  22. package/lib/HTableBody/index.js +7 -24
  23. package/lib/HTableBody/modal.d.ts +7 -1
  24. package/lib/HTableBody/utils.d.ts +1 -0
  25. package/lib/HTableHeader/RangePickerSearch.d.ts +1 -1
  26. package/lib/TableConfig.d.ts +2 -0
  27. package/lib/TableConfig.js +4 -2
  28. package/lib/modal.d.ts +2 -1
  29. package/lib/render/Text.d.ts +0 -1
  30. package/package.json +1 -1
  31. package/src/components/HTableBody/RowCheckBox/RowItem.tsx +2 -8
  32. package/src/components/HTableBody/RowCheckBox/hooks.ts +2 -2
  33. package/src/components/HTableBody/RowRadioBoxSelection.tsx +1 -7
  34. package/src/components/HTableBody/hooks/useRowClassName.ts +33 -0
  35. package/src/components/HTableBody/index.tsx +3 -21
  36. package/src/components/HTableBody/modal.ts +8 -1
  37. package/src/components/HTableBody/utils.ts +5 -0
  38. package/src/components/TableConfig.tsx +3 -0
  39. package/src/components/hooks/useRowObj.ts +1 -1
  40. package/src/components/modal.ts +6 -1
  41. package/src/pages/Table/index.tsx +62 -60
@@ -0,0 +1,33 @@
1
+ import type { HTableBodyProps } from "@/components/HTableBody/modal";
2
+ import { useHTableContext } from "@/components/context";
3
+ import { useContext } from "react";
4
+ import { ConfigProvider } from "antd";
5
+ import type { RowClassName } from "rc-table/lib/interface";
6
+ import { useHTableConfigContext } from "@/components/TableConfig";
7
+
8
+ export default ({
9
+ rowClassName,
10
+ rowKey = "id",
11
+ }: HTableBodyProps): RowClassName<any> => {
12
+ const { selectedRowData } = useHTableContext();
13
+ const { defaultSelectedRowClassName } = useHTableConfigContext({});
14
+ const { keys = [] } = selectedRowData;
15
+ const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
16
+
17
+ return (record: any, index: number, indent: number) => {
18
+ const key =
19
+ typeof rowKey === "function" ? rowKey(record, index) : record[rowKey];
20
+ const propsRowClassName =
21
+ typeof rowClassName === "function"
22
+ ? rowClassName(record, index, indent)
23
+ : rowClassName;
24
+ const relPropsRowClassName = propsRowClassName || "";
25
+ if (keys?.indexOf(key) === -1) {
26
+ return relPropsRowClassName;
27
+ }
28
+ if (typeof defaultSelectedRowClassName === "undefined") {
29
+ return `${getPrefixCls("table-row-selected")} ${relPropsRowClassName}`;
30
+ }
31
+ return `${defaultSelectedRowClassName || ""} ${relPropsRowClassName}`;
32
+ };
33
+ };
@@ -17,8 +17,7 @@ import Options from "./Options";
17
17
  import HeaderTitle from "./HeaderTitle";
18
18
  import { errorDefaultRender, emptyDefaultRender } from "./defaultRender";
19
19
  import type { HTableBodyProps } from "./modal";
20
- import { useContext } from "react";
21
- const { ConfigContext } = ConfigProvider;
20
+ import useRowClassName from "@/components/HTableBody/hooks/useRowClassName";
22
21
 
23
22
  export default (bodyProps: HTableBodyProps) => {
24
23
  const {
@@ -110,9 +109,7 @@ export default (bodyProps: HTableBodyProps) => {
110
109
  table: tableInstance,
111
110
  localSorter,
112
111
  });
113
- const { keys = [], selectAll } = selectedRowData;
114
- const { getPrefixCls } = useContext(ConfigContext);
115
-
112
+ const rowClassNameFn = useRowClassName(bodyProps);
116
113
  return (
117
114
  <div style={defaultTableStyle} className={`hw_table_body ${className}`}>
118
115
  <Space size={16} direction={"vertical"} style={{ width: "100%" }}>
@@ -134,22 +131,7 @@ export default (bodyProps: HTableBodyProps) => {
134
131
  >
135
132
  <ProTable
136
133
  {...props}
137
- rowClassName={(record, index, indent) => {
138
- const key =
139
- typeof rowKey === "function"
140
- ? rowKey(record, index)
141
- : record[rowKey];
142
- const propsRowClassName =
143
- typeof rowClassName === "function"
144
- ? rowClassName(record, index, indent)
145
- : rowClassName;
146
- if (keys?.indexOf(key) !== -1) {
147
- return `${getPrefixCls(
148
- "table-row-selected"
149
- )} ${propsRowClassName}`;
150
- }
151
- return propsRowClassName;
152
- }}
134
+ rowClassName={(rowClassNameFn as any)}
153
135
  bordered={bordered}
154
136
  columnsState={{
155
137
  ...selfColStatus,
@@ -1,5 +1,5 @@
1
1
  import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
2
- import type React from "react";
2
+ import React, {Key} from "react";
3
3
  import type { ProTableProps } from "@ant-design/pro-table";
4
4
  import type {
5
5
  ActionRenderFn,
@@ -39,3 +39,10 @@ export interface HTableBodyProps
39
39
  table?: HTableInstance;
40
40
  pagination?: IPaginationProps | false;
41
41
  }
42
+
43
+ export interface RowRadioSelectionProps {
44
+ data: any;
45
+ onChange?:(keys:Key[],data:any[])=>void;
46
+ getCheckboxProps?: HRowSelection["getCheckboxProps"];
47
+ index: number;
48
+ }
@@ -91,3 +91,8 @@ export const outColSetting = (
91
91
  keys,
92
92
  };
93
93
  };
94
+ interface RowItemFnModal {}
95
+
96
+ export const rowItemFn = (action, record, index) => {
97
+ return typeof action === "function" ? action(record, index) : record[action];
98
+ };
@@ -8,6 +8,7 @@ interface HTableConfigContextModal {
8
8
  tableStyle?: React.CSSProperties;
9
9
  paginationStyle?: React.CSSProperties;
10
10
  valueTypeConfig?: ValueTypeConfigModal;
11
+ defaultSelectedRowClassName?: string | null;
11
12
  }
12
13
  export const HTableConfigContext =
13
14
  React.createContext<HTableConfigContextModal | null>(null);
@@ -26,6 +27,7 @@ export const useHTableConfigContext = ({
26
27
  tableStyle: configTableStyle,
27
28
  paginationStyle: configPaginationStyle,
28
29
  valueTypeConfig = {},
30
+ defaultSelectedRowClassName,
29
31
  } = useContext(HTableConfigContext) || {};
30
32
 
31
33
  return {
@@ -35,6 +37,7 @@ export const useHTableConfigContext = ({
35
37
  tableStyle: tableStyle || configTableStyle,
36
38
  paginationStyle: paginationStyle || configPaginationStyle,
37
39
  valueTypeConfig,
40
+ defaultSelectedRowClassName,
38
41
  };
39
42
  };
40
43
  const Index: React.FC<HTableConfigContextModal> = ({ children, ...props }) => {
@@ -1,5 +1,5 @@
1
1
  import type React from "react";
2
- import { useMemo, useState } from "react";
2
+ import { useState } from "react";
3
3
  import type { RowObj } from "../modal";
4
4
  import type { HRowSelection } from "../modal";
5
5
 
@@ -5,7 +5,7 @@ import type {
5
5
  HFormInstance,
6
6
  } from "@hw-component/form/es/Form/modal";
7
7
  import type { ColProps, FormInstance } from "antd";
8
- import type React from "react";
8
+ import React, {Key} from "react";
9
9
  import type { ModalProps } from "antd";
10
10
  import type { TableProps } from "antd/lib/table";
11
11
  import type { AffixProps } from "antd/lib/affix";
@@ -54,7 +54,9 @@ interface BcItemModal {
54
54
  export type ConfigItemModal = Omit<HItemProps, "render" | "type"> &
55
55
  HColumns &
56
56
  BcItemModal;
57
+
57
58
  export type ConfigDataModal = ConfigItemModal[];
59
+
58
60
  export type ActionRenderFn = (
59
61
  selectedRowKeys: RowObj,
60
62
  tableInstance: HTableInstance
@@ -65,9 +67,12 @@ export type FooterBtnRenderFn = (
65
67
  selectedRowKeys: RowObj,
66
68
  setAllCheck: (row: RowObj) => void
67
69
  ) => React.ReactNode;
70
+
68
71
  export type actionFn = (...arg) => void;
72
+
69
73
  export interface RowSelectionOuter {
70
74
  allPageCheck?: boolean;
75
+ onChange?:(keys:Key[],data:any[])=>void;
71
76
  }
72
77
  export type HRowSelection = RowSelectionOuter &
73
78
  (TableProps<any>["rowSelection"] & {
@@ -121,38 +121,47 @@ export default () => {
121
121
  >
122
122
  获取
123
123
  </div>
124
- <HTable
125
- configData={configData}
126
- rowKey={(rowData, index) => {
127
- return index;
128
- }}
129
- table={hTable}
130
- labelWidth={88}
131
- action={{
132
- test: (params) => {
133
- console.log(params, "lllll");
134
- },
135
- }}
136
- rowSelection={{
137
- preserveSelectedRowKeys: true,
138
- }}
139
- affixProps={{
140
- target: () => document.querySelector(".body"),
141
- }}
142
- scroll={{
143
- x: 1000,
144
- }}
145
- columnsState={{
146
- persistenceKey: "test",
147
- persistenceType: "localStorage",
148
- }}
149
- formInitValues={{
150
- deviceType: "1",
151
- }}
152
- dataSource={[{}, {}, {}]}
153
- headerTitle={
154
- <Space size={8}>
155
- <div style={{ width: 1000 }}>
124
+ <HTableConfig defaultSelectedRowClassName={null}>
125
+ <HTable
126
+ configData={configData}
127
+ rowKey={(rowData, index) => {
128
+ return index;
129
+ }}
130
+ table={hTable}
131
+ labelWidth={88}
132
+ action={{
133
+ test: (params) => {
134
+ console.log(params, "lllll");
135
+ },
136
+ }}
137
+ rowSelection={{
138
+ preserveSelectedRowKeys: true,
139
+ }}
140
+ affixProps={{
141
+ target: () => document.querySelector(".body"),
142
+ }}
143
+ scroll={{
144
+ x: 1000,
145
+ }}
146
+ columnsState={{
147
+ persistenceKey: "test",
148
+ persistenceType: "localStorage",
149
+ }}
150
+ formInitValues={{
151
+ deviceType: "1",
152
+ }}
153
+ dataSource={[{}, {}, {}]}
154
+ headerTitle={
155
+ <Space size={8}>
156
+ <div style={{ width: 1000 }}>
157
+ <Button
158
+ onClick={() => {
159
+ console.log(hTable.table.getColSettingKeys());
160
+ }}
161
+ >
162
+ 操作
163
+ </Button>
164
+ </div>
156
165
  <Button
157
166
  onClick={() => {
158
167
  console.log(hTable.table.getColSettingKeys());
@@ -160,34 +169,27 @@ export default () => {
160
169
  >
161
170
  操作
162
171
  </Button>
163
- </div>
164
- <Button
165
- onClick={() => {
166
- console.log(hTable.table.getColSettingKeys());
167
- }}
168
- >
169
- 操作
170
- </Button>
171
- <Button
172
- onClick={() => {
173
- console.log(hTable.table.getColSettingKeys());
174
- }}
175
- >
176
- 操作
177
- </Button>
178
- </Space>
179
- }
180
- options={{
181
- settingRender: () => {
182
- return (
183
- <Tooltip title="321312312312321">
184
- <SettingOutlined width={24} />
185
- </Tooltip>
186
- );
187
- },
188
- }}
189
- pagination={false}
190
- />
172
+ <Button
173
+ onClick={() => {
174
+ console.log(hTable.table.getColSettingKeys());
175
+ }}
176
+ >
177
+ 操作
178
+ </Button>
179
+ </Space>
180
+ }
181
+ options={{
182
+ settingRender: () => {
183
+ return (
184
+ <Tooltip title="321312312312321">
185
+ <SettingOutlined width={24} />
186
+ </Tooltip>
187
+ );
188
+ },
189
+ }}
190
+ pagination={false}
191
+ />
192
+ </HTableConfig>
191
193
  </div>
192
194
  </HFormConfigProvider>
193
195
  );