@hw-component/table 1.2.1 → 1.2.3

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/RowSelection.d.ts +2 -1
  3. package/es/HTableBody/RowSelection.js +4 -3
  4. package/es/HTableBody/hooks.js +2 -1
  5. package/es/HTableBody/index.d.ts +1 -1
  6. package/es/HTableBody/index.js +63 -63
  7. package/es/HTableHeader/index.js +6 -15
  8. package/es/HTablePagination/index.js +7 -2
  9. package/es/Table.js +5 -4
  10. package/es/TableConfig.d.ts +7 -1
  11. package/es/TableConfig.js +12 -3
  12. package/es/context.d.ts +0 -1
  13. package/es/index.css +27 -5
  14. package/es/modal.d.ts +3 -2
  15. package/lib/HTableBody/RowSelection.d.ts +2 -1
  16. package/lib/HTableBody/RowSelection.js +4 -3
  17. package/lib/HTableBody/hooks.js +2 -1
  18. package/lib/HTableBody/index.d.ts +1 -1
  19. package/lib/HTableBody/index.js +62 -62
  20. package/lib/HTableHeader/index.js +6 -15
  21. package/lib/HTablePagination/index.js +7 -2
  22. package/lib/Table.js +9 -8
  23. package/lib/TableConfig.d.ts +7 -1
  24. package/lib/TableConfig.js +12 -3
  25. package/lib/context.d.ts +0 -1
  26. package/lib/index.css +27 -5
  27. package/lib/modal.d.ts +3 -2
  28. package/package.json +1 -1
  29. package/src/components/HTableBody/Options/index.tsx +26 -20
  30. package/src/components/HTableBody/Options/modal.d.ts +2 -2
  31. package/src/components/HTableBody/RowSelection.tsx +5 -3
  32. package/src/components/HTableBody/hooks.tsx +2 -1
  33. package/src/components/HTableBody/index.tsx +75 -78
  34. package/src/components/HTableHeader/index.tsx +3 -5
  35. package/src/components/HTablePagination/index.tsx +5 -2
  36. package/src/components/Table.tsx +6 -4
  37. package/src/components/TableConfig.tsx +11 -1
  38. package/src/components/context.ts +0 -1
  39. package/src/components/index.less +30 -6
  40. package/src/components/modal.ts +4 -3
  41. package/src/pages/Table/index.tsx +85 -79
@@ -2,7 +2,7 @@ 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
4
  import type { ColumnsState } from "@ant-design/pro-table/es/container";
5
- import React from "react";
5
+ import type React from "react";
6
6
 
7
7
  export interface IProps extends OptionConfig {
8
8
  size?: SizeType;
@@ -11,7 +11,7 @@ export interface IProps extends OptionConfig {
11
11
  onChange: (keys: string[], notCheck: string[]) => void;
12
12
  colStatusValue: Record<string, ColumnsState>;
13
13
  reset: VoidFunction;
14
- settingRender?:()=>React.ReactNode
14
+ settingRender?: () => React.ReactNode;
15
15
  }
16
16
 
17
17
  export interface ItemProps {
@@ -21,8 +21,8 @@ export const RowSelectionTitle = ({
21
21
  });
22
22
  const { keys, selectAll } = selectedRowData;
23
23
  const allCheck = () => {
24
- const setKeys = newData.map((item) => {
25
- return item[rowKey];
24
+ const setKeys = newData.map((item,index) => {
25
+ return typeof rowKey==="function"?rowKey(item,index):item[(rowKey as string)];
26
26
  });
27
27
  rowOnChange(setKeys, newData);
28
28
  onChange?.(setKeys, newData);
@@ -106,15 +106,17 @@ interface RowSelectionBoxProps {
106
106
  data: any;
107
107
  onChange?: HRowSelection["onChange"];
108
108
  getCheckboxProps?: HRowSelection["getCheckboxProps"];
109
+ index:number;
109
110
  }
110
111
  export const RowSelectionBox = ({
111
112
  data,
112
113
  onChange,
114
+ index,
113
115
  getCheckboxProps,
114
116
  }: RowSelectionBoxProps) => {
115
117
  const { selectedRowData, rowOnChange, rowKey = "id" } = useHTableContext();
116
118
  const { rowData = [], keys = [] } = selectedRowData;
117
- const key = data[rowKey];
119
+ const key = typeof rowKey==="function"?rowKey(data,index):data[rowKey];
118
120
  const check = (e) => {
119
121
  const checked = e.target.checked;
120
122
  const newKeys = [...keys];
@@ -25,10 +25,11 @@ const rowSelectionCol = (rowSelection?: HRowSelection) => {
25
25
  width: 32,
26
26
  rowSelectionTitle: true,
27
27
  fixed: "left",
28
- render: (dom, data) => {
28
+ render: (dom, data,index) => {
29
29
  return (
30
30
  <RowSelectionBox
31
31
  data={data}
32
+ index={index}
32
33
  onChange={onChange}
33
34
  getCheckboxProps={getCheckboxProps}
34
35
  />
@@ -15,7 +15,7 @@ import {
15
15
  } from "./hooks";
16
16
  import { useHTableContext } from "../context";
17
17
  import React from "react";
18
- import { ConfigProvider, Empty, Alert } from "antd";
18
+ import {ConfigProvider, Empty, Alert, Space} from "antd";
19
19
  import { useHTableConfigContext } from "../TableConfig";
20
20
  import HTablePagination from "../HTablePagination";
21
21
  import { useClassName } from "../hooks";
@@ -23,13 +23,16 @@ import AlertMsg from "./AlertMsg";
23
23
  import type { AffixProps } from "antd/lib/affix";
24
24
  import Options from "./Options";
25
25
  import HeaderTitle from "./HeaderTitle";
26
- import {OptionConfig} from "@ant-design/pro-table/lib/components/ToolBar";
26
+ import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
27
27
 
28
28
  export interface OptionModal extends OptionConfig {
29
- settingRender?:()=>React.ReactNode
29
+ settingRender?: () => React.ReactNode;
30
30
  }
31
31
  export interface HTableBodyProps
32
- extends Omit<ProTableProps<any, any>, "dataSource" | "rowSelection"|"options"> {
32
+ extends Omit<
33
+ ProTableProps<any, any>,
34
+ "dataSource" | "rowSelection" | "options"
35
+ > {
33
36
  configData?: ConfigDataModal;
34
37
  onPageChange?: (params: ParamsModal) => void;
35
38
  emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
@@ -46,16 +49,11 @@ export interface HTableBodyProps
46
49
  optionsRender?: (node: React.ReactNode) => React.ReactNode;
47
50
  paginationActionRender?: (tableInstance: HTableInstance) => React.ReactNode;
48
51
  localSorter?: boolean;
49
- options?:OptionModal|false
52
+ options?: OptionModal | false;
50
53
  }
51
54
  const defaultRender = () => {
52
55
  return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />;
53
56
  };
54
- const contentStyle = {
55
- paddingLeft: 24,
56
- paddingRight: 24,
57
- paddingBottom: 16,
58
- };
59
57
  export default ({
60
58
  configData,
61
59
  pagination = {},
@@ -85,10 +83,8 @@ export default ({
85
83
  configData: contextConfigData,
86
84
  data,
87
85
  selectedRowData,
88
- rowOnChange,
89
86
  error,
90
87
  loading,
91
- allSelectChange,
92
88
  } = useHTableContext();
93
89
  const {
94
90
  emptyRender: tableEmptyRender = defaultRender,
@@ -129,75 +125,76 @@ export default ({
129
125
  : optionsNode;
130
126
  const alwaysShowAlert = keys.length > 0 || selectAll || configAlwaysShowAlert;
131
127
  const className = useClassName("hw-table-body");
128
+ const {tableStyle:defaultTableStyle}=useHTableConfigContext({tableStyle})
132
129
  return (
133
- <div style={tableStyle} className={`hw_table_body ${className}`}>
134
- {alwaysShowAlert && (
135
- <div style={contentStyle}>
136
- <Alert
137
- message={<AlertMsg actionRender={actionRender} />}
138
- type="info"
139
- />
140
- </div>
141
- )}
142
- <HeaderTitle
143
- headerTitle={headerTitle}
144
- contentStyle={contentStyle}
145
- rNode={defaultOptionsNode}
146
- />
147
- <ConfigProvider
148
- renderEmpty={() => {
149
- if (error) {
150
- return tableErrorRender?.(tableInstance, error);
151
- }
152
- return tableEmptyRender?.(tableInstance);
153
- }}
154
- >
155
- <ProTable
156
- {...props}
157
- columnsState={{
158
- ...selfColStatus,
159
- value,
160
- }}
161
- columns={cols as any}
162
- size={cuSize}
163
- search={false}
164
- onChange={(page, filters, sorter) => {
165
- if (localSorter) {
166
- return;
167
- }
168
- const { field, order } = sorter as any;
169
- const orderByField =
170
- typeof order === "undefined" ? undefined : field;
171
- const asc =
172
- typeof order === "undefined" ? undefined : order === "ascend";
173
- tableInstance.table.reloadWithParams({
174
- current: 1,
175
- orderByField,
176
- asc,
177
- });
178
- }}
179
- tableStyle={{
180
- paddingBottom: 0,
181
- }}
182
- options={false}
183
- rowSelection={false}
184
- loading={loading}
185
- rowKey={rowKey}
186
- dataSource={records}
187
- pagination={false}
130
+ <div style={defaultTableStyle} className={`hw_table_body ${className}`}>
131
+ <Space size={16} direction={"vertical"} style={{width:"100%"}}>
132
+ {alwaysShowAlert && (
133
+ <Alert
134
+ message={<AlertMsg actionRender={actionRender} />}
135
+ type="info"
136
+ />
137
+ )}
138
+ <HeaderTitle
139
+ headerTitle={headerTitle}
140
+ rNode={defaultOptionsNode}
141
+ />
142
+ <ConfigProvider
143
+ renderEmpty={() => {
144
+ if (error) {
145
+ return tableErrorRender?.(tableInstance, error);
146
+ }
147
+ return tableEmptyRender?.(tableInstance);
148
+ }}
149
+ >
150
+ <ProTable
151
+ {...props}
152
+
153
+ columnsState={{
154
+ ...selfColStatus,
155
+ value,
156
+ }}
157
+ columns={cols as any}
158
+ size={cuSize}
159
+ search={false}
160
+ onChange={(page, filters, sorter) => {
161
+ if (localSorter) {
162
+ return;
163
+ }
164
+ const { field, order } = sorter as any;
165
+ const orderByField =
166
+ typeof order === "undefined" ? undefined : field;
167
+ const asc =
168
+ typeof order === "undefined" ? undefined : order === "ascend";
169
+ tableInstance.table.reloadWithParams({
170
+ current: 1,
171
+ orderByField,
172
+ asc,
173
+ });
174
+ }}
175
+ tableStyle={{
176
+ paddingBottom: 0,
177
+ }}
178
+ options={false}
179
+ rowSelection={false}
180
+ loading={loading}
181
+ rowKey={rowKey}
182
+ dataSource={records}
183
+ pagination={false}
188
184
 
189
- />
190
- {pagination !== false && (
191
- <HTablePagination
192
- onPageChange={onPageChange}
193
- paginationStyle={paginationStyle}
194
- affixProps={affixProps}
195
- goTop={goTop}
196
- actionRender={paginationActionRender}
197
- {...pagination}
198
185
  />
199
- )}
200
- </ConfigProvider>
186
+ {pagination !== false && (
187
+ <HTablePagination
188
+ onPageChange={onPageChange}
189
+ paginationStyle={paginationStyle}
190
+ affixProps={affixProps}
191
+ goTop={goTop}
192
+ actionRender={paginationActionRender}
193
+ {...pagination}
194
+ />
195
+ )}
196
+ </ConfigProvider>
197
+ </Space>
201
198
  </div>
202
199
  );
203
200
  };
@@ -6,6 +6,7 @@ import { useClassName } from "../hooks";
6
6
  import type { IHeaderProps } from "./modal";
7
7
  import { useHideMoreTitle } from "./hooks";
8
8
  import { HeaderProvider } from "./Context";
9
+ import {useHTableConfigContext} from "../TableConfig";
9
10
 
10
11
  const defaultSearchSpan = {
11
12
  xxl: 4,
@@ -44,13 +45,10 @@ export default ({
44
45
  typeof hideLabel === "undefined" ? contextHideLabel : hideLabel;
45
46
  const tableLabelWidth = labelWidth || contextLabelWidth;
46
47
  const className = useClassName("hw-table-header");
48
+ const {headerStyle:defaultHeaderStyle}=useHTableConfigContext({headerStyle})
47
49
  return (
48
50
  <Card
49
- style={{
50
- borderBottomLeftRadius: 0,
51
- borderBottomRightRadius: 0,
52
- ...headerStyle,
53
- }}
51
+ style={defaultHeaderStyle}
54
52
  bordered={false}
55
53
  className={`hw_table_header ${className}`}
56
54
  bodyStyle={{ paddingBottom: 0 }}
@@ -6,6 +6,7 @@ import { useClassName } from "../hooks";
6
6
  import React, { useState } from "react";
7
7
  import type { AffixProps } from "antd/lib/affix";
8
8
  import GoTop from "../GoTop";
9
+ import {useHTableConfigContext} from "@/components/TableConfig";
9
10
  export interface IPaginationProps extends PaginationProps {
10
11
  onPageChange?: (params: ParamsModal) => void;
11
12
  paginationStyle?: React.CSSProperties;
@@ -36,13 +37,15 @@ export default ({
36
37
  if (!data) {
37
38
  return <></>;
38
39
  }
40
+ const {paginationStyle:defaultPaginationStyle}=useHTableConfigContext({paginationStyle})
41
+
39
42
  if (affixProps === false) {
40
43
  return (
41
44
  <Row
42
45
  justify={"space-between"}
43
46
  align={"middle"}
44
47
  className={className}
45
- style={paginationStyle}
48
+ style={defaultPaginationStyle}
46
49
  >
47
50
  <div>{actionRender?.(tableInstance)}</div>
48
51
  <Pagination
@@ -82,7 +85,7 @@ export default ({
82
85
  justify={"space-between"}
83
86
  className={className}
84
87
  align={"middle"}
85
- style={{ ...paginationStyle, ...style }}
88
+ style={{ ...defaultPaginationStyle, ...style }}
86
89
  >
87
90
  <div>{actionRender?.(tableInstance)}</div>
88
91
  <Pagination
@@ -8,14 +8,15 @@ import type { HTableProps } from "./modal";
8
8
  import useReq from "./hooks/useReq";
9
9
  import useDispatch from "./hooks/useDispatch";
10
10
  import { useState } from "react";
11
+ import {useClassName} from "@/components/hooks";
11
12
  export default ({
12
13
  request,
13
14
  configData,
14
15
  searchSpan,
15
16
  table,
16
17
  hideHeader,
17
- headerStyle = {},
18
- tableStyle = {},
18
+ headerStyle,
19
+ tableStyle,
19
20
  action = {},
20
21
  spaceSize = 15,
21
22
  className,
@@ -56,7 +57,8 @@ export default ({
56
57
  selectedRowData,
57
58
  dataSource: data,
58
59
  });
59
- return (
60
+ const contentClassName = useClassName("hw-table-content");
61
+ return (
60
62
  <HTableContext.Provider
61
63
  value={{
62
64
  tableInstance,
@@ -81,7 +83,7 @@ export default ({
81
83
  labelWidth,
82
84
  }}
83
85
  >
84
- <Space direction={"vertical"} size={0} style={{ width: "100%" }}>
86
+ <Space direction={"vertical"} size={0} style={{ width: "100%" }} className={contentClassName}>
85
87
  {!hideHeader && (
86
88
  <Header
87
89
  searchSpan={searchSpan}
@@ -4,20 +4,30 @@ import type { HTableInstance } from "src/components/modal";
4
4
  interface HTableConfigContextModal {
5
5
  emptyRender?: (table: HTableInstance) => React.ReactNode;
6
6
  errorRender?: (table: HTableInstance, error: Error) => React.ReactNode;
7
+ headerStyle?:React.CSSProperties;
8
+ tableStyle?:React.CSSProperties;
9
+ paginationStyle?:React.CSSProperties;
7
10
  }
8
11
  export const HTableConfigContext =
9
12
  React.createContext<HTableConfigContextModal | null>(null);
10
13
 
14
+
11
15
  export const useHTableConfigContext = ({
12
16
  emptyRender,
13
17
  errorRender,
18
+ headerStyle,
19
+ tableStyle,
20
+ paginationStyle
14
21
  }: HTableConfigContextModal) => {
15
- const { errorRender: configErrorRender, emptyRender: configEmptyRender } =
22
+ const { errorRender: configErrorRender, emptyRender: configEmptyRender,headerStyle:configHeaderStyle,tableStyle:configTableStyle,paginationStyle:configPaginationStyle } =
16
23
  useContext(HTableConfigContext) || {};
17
24
 
18
25
  return {
19
26
  errorRender: errorRender || configErrorRender,
20
27
  emptyRender: emptyRender || configEmptyRender,
28
+ headerStyle:headerStyle||configHeaderStyle,
29
+ tableStyle:tableStyle||configTableStyle,
30
+ paginationStyle:paginationStyle||configPaginationStyle
21
31
  };
22
32
  };
23
33
  const Index: React.FC<HTableConfigContextModal> = ({ children, ...props }) => {
@@ -14,7 +14,6 @@ interface HContextModal extends Omit<HTableProps, "request"> {
14
14
  onFinish: (value: Record<string, any>) => Promise<any>;
15
15
  onPageChange: (value: Record<string, any>) => Promise<any>;
16
16
  setSelectedRowData: (row: RowObj) => void;
17
- rowKey?: string;
18
17
  headerOpen?: boolean;
19
18
  setHeaderOpen: Dispatch<SetStateAction<boolean | undefined>>;
20
19
  }
@@ -1,14 +1,30 @@
1
1
  @import "./styles/local.less";
2
- .@{ant-prefix}-hw-table-body{
3
- border-bottom-left-radius: 4px;
4
- border-bottom-right-radius: 4px;
2
+ .@{ant-prefix}-hw-table-content{
3
+ .@{ant-prefix}-hw-table-body{
4
+ padding-top: 0px;
5
+ border-top-left-radius: 0px;
6
+ border-top-right-radius: 0px;
7
+ }
8
+ .@{ant-prefix}-hw-table-header{
9
+ border-bottom-left-radius: 0px !important;
10
+ border-bottom-right-radius: 0px !important;
11
+ }
12
+ }
13
+ .@{ant-prefix}-hw-table-body {
5
14
  background-color: #fff;
6
15
  position: relative;
16
+ padding-right: 20px;
17
+ padding-left: 20px;
18
+ padding-top: 16px;
19
+ border-radius: 4px;
20
+ overflow: hidden;
7
21
  .@{ant-prefix}-hw-table-pagination{
8
22
  padding: 12px 24px;
9
23
  background-color:#ffffff;
10
24
  border-bottom-left-radius: 4px;
11
25
  border-bottom-right-radius: 4px;
26
+ margin-left: -20px;
27
+ margin-right: -20px;
12
28
  .@{ant-prefix}-select{
13
29
  width: auto;
14
30
  }
@@ -19,9 +35,12 @@
19
35
  .@{ant-prefix}-pro-table-list-toolbar-container{
20
36
  padding-top: 0px;
21
37
  }
38
+ .@{ant-prefix}-pro-table>.@{ant-prefix}-pro-card>.@{ant-prefix}-pro-card-body{
39
+ padding: 0px;
40
+ }
22
41
  }
23
42
  .@{ant-prefix}-hw-table-pagination{
24
- padding: 24px;
43
+ padding: 20px;
25
44
  border-radius: 4px;
26
45
  background-color: #ffffff;
27
46
  position: relative;
@@ -39,12 +58,17 @@
39
58
  background-size: 100%;
40
59
  }
41
60
  .@{ant-prefix}-hw-table-header{
42
- border-top-left-radius: 4px !important;
43
- border-top-right-radius: 4px !important;
61
+ border-radius: 4px !important;
44
62
  padding-bottom: 0px;
45
63
  .@{ant-prefix}-hw-table-header-item-hide{
46
64
  display: none;
47
65
  }
66
+ .@{ant-prefix}-card-body{
67
+ padding:24px 20px
68
+ }
69
+ .@{ant-prefix}-form-item{
70
+ margin-bottom: 16px;
71
+ }
48
72
  }
49
73
 
50
74
  .@{ant-prefix}-hw-table-body-option-icon{
@@ -9,7 +9,7 @@ import type React 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";
12
- import {OptionModal} from "./HTableBody";
12
+ import type { OptionModal } from "./HTableBody";
13
13
 
14
14
  export interface RowObj {
15
15
  keys?: React.Key[];
@@ -66,6 +66,7 @@ export type actionFn = (...arg) => void;
66
66
  export interface RowSelectionOuter {
67
67
  allPageCheck?: boolean;
68
68
  }
69
+ type RowKeyFn=(data:any,index:number)=>string;
69
70
  export type HRowSelection = RowSelectionOuter &
70
71
  (TableProps<any>["rowSelection"] & {
71
72
  alwaysShowAlert?: boolean;
@@ -96,7 +97,7 @@ export interface HTableProps
96
97
  manual?: boolean;
97
98
  dataSource?: ResultModal;
98
99
  paginationStyle?: React.CSSProperties;
99
- rowKey?: string;
100
+ rowKey?: string|RowKeyFn;
100
101
  allPageCheck?: boolean;
101
102
  rowSelection?: HRowSelection | false;
102
103
  affixProps?: AffixProps | false;
@@ -108,7 +109,7 @@ export interface HTableProps
108
109
  formInitValues?: Record<string, any>;
109
110
  labelWidth?: number;
110
111
  hideLabel?: boolean;
111
- options?:OptionModal|false
112
+ options?: OptionModal | false;
112
113
  }
113
114
  interface ColCheckResultKeys {
114
115
  keys?: string[];