@hw-component/table 1.2.1 → 1.2.2

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.
@@ -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 = {},
@@ -129,75 +127,75 @@ export default ({
129
127
  : optionsNode;
130
128
  const alwaysShowAlert = keys.length > 0 || selectAll || configAlwaysShowAlert;
131
129
  const className = useClassName("hw-table-body");
130
+ const {tableStyle:defaultTableStyle}=useHTableConfigContext({tableStyle})
132
131
  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}
132
+ <div style={defaultTableStyle} className={`hw_table_body ${className}`}>
133
+ <Space size={16} direction={"vertical"} style={{width:"100%"}}>
134
+ {alwaysShowAlert && (
135
+ <Alert
136
+ message={<AlertMsg actionRender={actionRender} />}
137
+ type="info"
138
+ />
139
+ )}
140
+ <HeaderTitle
141
+ headerTitle={headerTitle}
142
+ rNode={defaultOptionsNode}
143
+ />
144
+ <ConfigProvider
145
+ renderEmpty={() => {
146
+ if (error) {
147
+ return tableErrorRender?.(tableInstance, error);
148
+ }
149
+ return tableEmptyRender?.(tableInstance);
150
+ }}
151
+ >
152
+ <ProTable
153
+ {...props}
154
+ columnsState={{
155
+ ...selfColStatus,
156
+ value,
157
+ }}
158
+ columns={cols as any}
159
+ size={cuSize}
160
+ search={false}
161
+ onChange={(page, filters, sorter) => {
162
+ if (localSorter) {
163
+ return;
164
+ }
165
+ const { field, order } = sorter as any;
166
+ const orderByField =
167
+ typeof order === "undefined" ? undefined : field;
168
+ const asc =
169
+ typeof order === "undefined" ? undefined : order === "ascend";
170
+ tableInstance.table.reloadWithParams({
171
+ current: 1,
172
+ orderByField,
173
+ asc,
174
+ });
175
+ }}
176
+ tableStyle={{
177
+ paddingBottom: 0,
178
+ }}
179
+ options={false}
180
+ rowSelection={false}
181
+ loading={loading}
182
+ rowKey={rowKey}
183
+ dataSource={records}
184
+ pagination={false}
188
185
 
189
- />
190
- {pagination !== false && (
191
- <HTablePagination
192
- onPageChange={onPageChange}
193
- paginationStyle={paginationStyle}
194
- affixProps={affixProps}
195
- goTop={goTop}
196
- actionRender={paginationActionRender}
197
- {...pagination}
198
186
  />
199
- )}
200
- </ConfigProvider>
187
+ {pagination !== false && (
188
+ <HTablePagination
189
+ onPageChange={onPageChange}
190
+ paginationStyle={paginationStyle}
191
+ affixProps={affixProps}
192
+ goTop={goTop}
193
+ actionRender={paginationActionRender}
194
+ {...pagination}
195
+ />
196
+ )}
197
+ </ConfigProvider>
198
+ </Space>
201
199
  </div>
202
200
  );
203
201
  };
@@ -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 }) => {
@@ -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[];
@@ -108,7 +108,7 @@ export interface HTableProps
108
108
  formInitValues?: Record<string, any>;
109
109
  labelWidth?: number;
110
110
  hideLabel?: boolean;
111
- options?:OptionModal|false
111
+ options?: OptionModal | false;
112
112
  }
113
113
  interface ColCheckResultKeys {
114
114
  keys?: string[];
@@ -1,7 +1,7 @@
1
- import { HTable, useHTable } from "@/components";
2
- import {Button, Tooltip} from "antd";
1
+ import { HTable, useHTable ,HTableConfig} from "@/components";
2
+ import {Button, Card, Tooltip} from "antd";
3
3
  import { HFormConfigProvider } from "@hw-component/form";
4
- import {SettingOutlined} from "@ant-design/icons";
4
+ import { SettingOutlined } from "@ant-design/icons";
5
5
 
6
6
  const configData = [
7
7
  {
@@ -9,7 +9,6 @@ const configData = [
9
9
  showSearch: true,
10
10
  searchType: "rangePicker",
11
11
  dataIndex: "id",
12
- searchLabel: "fff",
13
12
  sorter: true,
14
13
  itemProps: {
15
14
  options: [{ label: "1", value: 1 }],
@@ -22,7 +21,6 @@ const configData = [
22
21
  },
23
22
  {
24
23
  title: "座位断开",
25
- showSearch: true,
26
24
  dataIndex: "name1",
27
25
  childrenDataIndex: [
28
26
  {
@@ -41,7 +39,6 @@ const configData = [
41
39
  {
42
40
  title: <div>座位fff</div>,
43
41
  titleStr: "座位",
44
- showSearch: true,
45
42
  dataIndex: "name2",
46
43
  searchType: "select",
47
44
  sorter: true,
@@ -54,9 +51,8 @@ const configData = [
54
51
  name: "aaa",
55
52
  fixed: "right",
56
53
  width: 200,
57
- showSearch: true,
58
54
  render: () => {
59
- return <div>fff</div>;
55
+ return <Card>fff</Card>;
60
56
  },
61
57
  },
62
58
  ];
@@ -67,7 +63,9 @@ const Test = ({ name, selectedRowData }) => {
67
63
  export default () => {
68
64
  const hTable = useHTable();
69
65
  return (
70
- <HFormConfigProvider>
66
+ <HFormConfigProvider
67
+
68
+ >
71
69
  <div>
72
70
  <div
73
71
  onClick={() => {
@@ -76,78 +74,84 @@ export default () => {
76
74
  >
77
75
  获取
78
76
  </div>
79
- <HTable
80
- configData={configData}
81
- rowKey={"id"}
82
- table={hTable}
83
- onReset={() => {
84
- hTable.form.setFieldsValue({
85
- name1: "ffff",
86
- });
87
- }}
88
- hideLabel={false}
89
- labelWidth={88}
90
- action={{
91
- test: (params) => {
92
- console.log(params, "lllll");
93
- },
94
- }}
95
- rowSelection={{
96
- allPageCheck: false,
97
- }}
98
- affixProps={{
99
- target: () => document.querySelector(".body"),
100
- }}
101
- scroll={{
102
- x: 1000,
103
- }}
104
- columnsState={{
105
- persistenceKey: "test",
106
- persistenceType: "localStorage",
107
- }}
108
- formInitValues={{
109
- name2: 1,
110
- }}
111
- headerTitle={
112
- <Button
113
- type={"primary"}
114
- onClick={() => {
115
- console.log(hTable.table.getColSettingKeys());
77
+ <HTableConfig>
78
+ <HTable
79
+ configData={configData}
80
+ rowKey={"id"}
81
+ table={hTable}
82
+ onReset={() => {
83
+ hTable.form.setFieldsValue({
84
+ name1: "ffff",
85
+ });
116
86
  }}
117
- >
118
- 操作
119
- </Button>
120
- }
121
- paginationActionRender={() => {
122
- return <div>你大爷</div>;
123
- }}
124
- request={(params) => {
125
- const { current = 1, size = "10" } = params;
126
- const arrayData = [];
127
- for (let i = 0; i < 100; i = i + 1) {
128
- arrayData.push({
129
- id: i,
130
- name: "11",
131
- });
132
- }
133
- return new Promise((resolve, reject) => {
134
- setTimeout(() => {
135
- // reject(new Error("错误"));
136
- resolve({
137
- size: size,
138
- current: current.toString(10),
139
- total: "1000",
140
- records: arrayData,
87
+ hideLabel={false}
88
+ labelWidth={88}
89
+ action={{
90
+ test: (params) => {
91
+ console.log(params, "lllll");
92
+ },
93
+ }}
94
+ rowSelection={{
95
+ allPageCheck: false,
96
+ }}
97
+ affixProps={{
98
+ target: () => document.querySelector(".body"),
99
+ }}
100
+ scroll={{
101
+ x: 1000,
102
+ }}
103
+ columnsState={{
104
+ persistenceKey: "test",
105
+ persistenceType: "localStorage",
106
+ }}
107
+ formInitValues={{
108
+ name2: 1,
109
+ }}
110
+ headerTitle={
111
+ <Button
112
+ type={"primary"}
113
+ onClick={() => {
114
+ console.log(hTable.table.getColSettingKeys());
115
+ }}
116
+ >
117
+ 操作
118
+ </Button>
119
+ }
120
+ paginationActionRender={() => {
121
+ return <div>你大爷</div>;
122
+ }}
123
+ request={(params) => {
124
+ const { current = 1, size = "10" } = params;
125
+ const arrayData = [];
126
+ for (let i = 0; i < 100; i = i + 1) {
127
+ arrayData.push({
128
+ id: i,
129
+ name: "11",
130
+ });
131
+ }
132
+ return new Promise((resolve, reject) => {
133
+ setTimeout(() => {
134
+ // reject(new Error("错误"));
135
+ resolve({
136
+ size: size,
137
+ current: current.toString(10),
138
+ total: "1000",
139
+ records: arrayData,
140
+ });
141
+ }, 2000);
141
142
  });
142
- }, 2000);
143
- });
144
- }}
145
- options={{
146
- settingRender:()=>{
147
- return <Tooltip title="321312312312321"><SettingOutlined width={24} /></Tooltip>
148
- }
149
- }}
150
- />
143
+ }}
144
+ options={{
145
+ settingRender: () => {
146
+ return (
147
+ <Tooltip title="321312312312321">
148
+ <SettingOutlined width={24} />
149
+ </Tooltip>
150
+ );
151
+ },
152
+ }}
153
+ />
154
+ </HTableConfig>
151
155
  </div>
152
156
  </HFormConfigProvider>
153
157
  );