@hw-component/table 1.9.59 → 1.9.61

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 (33) hide show
  1. package/.eslintcache +1 -1
  2. package/es/HTableBody/HeaderTitle/index.d.ts +1 -1
  3. package/es/HTableBody/{hooks.d.ts → hooks/useColData.d.ts} +3 -16
  4. package/es/HTableBody/{hooks.js → hooks/useColData.js} +21 -58
  5. package/es/HTableBody/hooks/useControl.d.ts +16 -0
  6. package/es/HTableBody/hooks/useControl.js +119 -0
  7. package/es/HTableBody/index.d.ts +2 -27
  8. package/es/HTableBody/index.js +9 -21
  9. package/es/HTableBody/modal.d.ts +27 -0
  10. package/es/Table.js +2 -1
  11. package/es/modal.d.ts +1 -1
  12. package/lib/HTableBody/HeaderTitle/index.d.ts +1 -1
  13. package/lib/HTableBody/{hooks.d.ts → hooks/useColData.d.ts} +3 -16
  14. package/lib/HTableBody/{hooks.js → hooks/useColData.js} +20 -59
  15. package/lib/HTableBody/hooks/useControl.d.ts +16 -0
  16. package/lib/HTableBody/hooks/useControl.js +122 -0
  17. package/lib/HTableBody/index.d.ts +2 -27
  18. package/lib/HTableBody/index.js +13 -25
  19. package/lib/HTableBody/modal.d.ts +27 -0
  20. package/lib/Table.js +2 -1
  21. package/lib/modal.d.ts +1 -1
  22. package/package.json +1 -1
  23. package/src/components/HTableBody/HeaderTitle/index.tsx +1 -1
  24. package/src/components/HTableBody/{hooks.tsx → hooks/useColData.tsx} +27 -61
  25. package/src/components/HTableBody/hooks/useControl.tsx +106 -0
  26. package/src/components/HTableBody/index.tsx +13 -62
  27. package/src/components/HTableBody/modal.ts +41 -0
  28. package/src/components/Table.tsx +1 -1
  29. package/src/components/index.less +1 -1
  30. package/src/components/modal.ts +1 -1
  31. package/src/components/render/config.tsx +1 -1
  32. package/src/components/styles/local.less +1 -0
  33. package/src/pages/Table/index.tsx +16 -14
@@ -1,22 +1,25 @@
1
+ import { useHTableContext } from "@/components/context";
2
+ import React, { useEffect, useMemo, useState } from "react";
3
+ import { GetRowKey } from "rc-table/lib/interface";
1
4
  import type {
2
- HTableInstance,
3
- HTableProps,
4
- HRowSelection,
5
5
  ConfigDataModal,
6
6
  ConfigItemModal,
7
- } from "../modal";
8
- import React, { useEffect, useMemo, useState } from "react";
9
- import { useHTableContext } from "../context";
10
- import type { GetRowKey } from "rc-table/lib/interface";
11
- import { RowSelectionBox, RowSelectionTitle } from "./RowSelection";
12
- import type { SizeType } from "antd/lib/config-provider/SizeContext";
13
- import type { ColumnsStateType } from "@ant-design/pro-table/es/typing";
14
- import type { ColumnsState } from "@ant-design/pro-table/es/container";
15
- import { mkChangeValue, outColSetting } from "./utils";
16
- import configRender from "../render";
7
+ HRowSelection,
8
+ HTableInstance,
9
+ HTableProps,
10
+ } from "@/components/modal";
11
+ import { useClassName } from "@/components/hooks";
17
12
  import { useHTableConfigContext } from "@/components/TableConfig";
18
13
  import { textTypes } from "@/components/render/config";
19
- import { useClassName } from "@/components/hooks";
14
+ import configRender from "@/components/render";
15
+ import {
16
+ RowSelectionBox,
17
+ RowSelectionTitle,
18
+ } from "@/components/HTableBody/RowSelection";
19
+ import type { ColumnsState } from "@ant-design/pro-table/es/container";
20
+ import { mkChangeValue, outColSetting } from "@/components/HTableBody/utils";
21
+ import type { ColumnsStateType } from "@ant-design/pro-table/es/typing";
22
+
20
23
  const rowSelectionCol = (rowSelection?: HRowSelection) => {
21
24
  const { allPageCheck, onChange, getCheckboxProps } = rowSelection || {};
22
25
  return {
@@ -44,7 +47,12 @@ const rowSelectionCol = (rowSelection?: HRowSelection) => {
44
47
  };
45
48
  };
46
49
 
47
- export const useCols = ({ configData, rowSelection, table ,bordered}: HTableProps) => {
50
+ export const useCols = ({
51
+ configData,
52
+ rowSelection,
53
+ table,
54
+ bordered,
55
+ }: HTableProps) => {
48
56
  const trClassname = useClassName("hw-table-col-hr");
49
57
  const [cols, setCols] = useState<ConfigDataModal>([]);
50
58
  const { valueTypeConfig } = useHTableConfigContext({});
@@ -61,10 +69,9 @@ export const useCols = ({ configData, rowSelection, table ,bordered}: HTableProp
61
69
  className = "",
62
70
  children = [],
63
71
  } = item;
64
- const trClassName =bordered?"":itemClassNameMk(
65
- children as any[],
66
- lastChildren as any[]
67
- );
72
+ const trClassName = bordered
73
+ ? ""
74
+ : itemClassNameMk(children as any[], lastChildren as any[]);
68
75
  const itemType = valueType as string;
69
76
  if (textTypes.indexOf(itemType) !== -1) {
70
77
  const { ellipsis } = valueTypeProps;
@@ -100,52 +107,11 @@ export const useCols = ({ configData, rowSelection, table ,bordered}: HTableProp
100
107
  cols,
101
108
  };
102
109
  };
103
- interface FilterKeysModal {
104
- selectedRowKeys?: React.Key[];
105
- records?: any[];
106
- rowKey?: string | GetRowKey<any>;
107
- }
108
- export const useSynchronousKeys = ({
109
- selectedRowKeys,
110
- records,
111
- rowKey,
112
- }: FilterKeysModal) => {
113
- const { rowOnChange } = useHTableContext();
114
- const findId = (key) => {
115
- const msRecords = records as any[];
116
- const rowIndex = msRecords.findIndex((item, index) => {
117
- const id =
118
- typeof rowKey === "function"
119
- ? rowKey(item, index)
120
- : item[rowKey as string];
121
- return id === key;
122
- });
123
- return msRecords[rowIndex];
124
- };
125
- useEffect(() => {
126
- if (selectedRowKeys && records && rowKey) {
127
- const resultData = selectedRowKeys.map((key) => {
128
- return findId(key);
129
- });
130
- rowOnChange(selectedRowKeys, resultData);
131
- }
132
- }, [selectedRowKeys, records, rowKey]);
133
- };
134
-
135
- export const useSize = (size: SizeType) => {
136
- const [cuSize, setCuSize] = useState(size);
137
- useEffect(() => {
138
- setCuSize(size);
139
- }, [size]);
140
- return {
141
- cuSize,
142
- setCuSize,
143
- };
144
- };
145
110
  interface useColumnsStateTypeModal {
146
111
  columnsState?: ColumnsStateType;
147
112
  columns: ConfigDataModal;
148
113
  }
114
+
149
115
  export const useColumnsStateType = ({
150
116
  columnsState,
151
117
  columns,
@@ -0,0 +1,106 @@
1
+ import type React from "react";
2
+ import { useEffect, useMemo, useState } from "react";
3
+ import type { SizeType } from "antd/lib/config-provider/SizeContext";
4
+ import type { HTableBodyProps } from "../modal";
5
+ import { useHTableContext } from "@/components/context";
6
+ import type { GetRowKey } from "rc-table/lib/interface";
7
+
8
+ export const useSize = (size: SizeType) => {
9
+ const [cuSize, setCuSize] = useState(size);
10
+ useEffect(() => {
11
+ setCuSize(size);
12
+ }, [size]);
13
+ return {
14
+ cuSize,
15
+ setCuSize,
16
+ };
17
+ };
18
+
19
+ export const useTableChange = ({
20
+ columns,
21
+ onChange,
22
+ localSorter,
23
+ table: tableInstance,
24
+ }: HTableBodyProps) => {
25
+ const filtersObj = useMemo(() => {
26
+ const obj = {};
27
+ columns?.forEach(({ filterMultiple = true, filters, dataIndex }) => {
28
+ if (!filters || !dataIndex) {
29
+ return;
30
+ }
31
+ if (Array.isArray(dataIndex)) {
32
+ obj[dataIndex.join(",")] = filterMultiple;
33
+ return;
34
+ }
35
+ obj[dataIndex] = filterMultiple;
36
+ });
37
+ return obj;
38
+ }, [columns]);
39
+ const filtersMk = (filters) => {
40
+ const keys = Object.keys(filters);
41
+ const len = keys.length;
42
+ if (!len) {
43
+ return {};
44
+ }
45
+ const paramsObj = {};
46
+ keys.forEach((key) => {
47
+ if (filtersObj[key]) {
48
+ paramsObj[key] = filters[key];
49
+ return;
50
+ }
51
+ paramsObj[key] = filters[key]?.[0];
52
+ });
53
+ return paramsObj;
54
+ };
55
+ return (page, filters, sorter, extra) => {
56
+ if (onChange) {
57
+ return onChange(page, filters, sorter, extra);
58
+ }
59
+ const { field, order, column } = sorter as any;
60
+ const { sorter: colSorter } = column || {};
61
+ if (localSorter || typeof colSorter === "function") {
62
+ return;
63
+ }
64
+ const orderByField = typeof order === "undefined" ? undefined : field;
65
+ const asc = typeof order === "undefined" ? undefined : order === "ascend";
66
+ tableInstance?.table.reloadWithParams({
67
+ current: 1,
68
+ orderByField,
69
+ asc,
70
+ ...filtersMk(filters),
71
+ });
72
+ };
73
+ };
74
+
75
+ interface FilterKeysModal {
76
+ selectedRowKeys?: React.Key[];
77
+ records?: any[];
78
+ rowKey?: string | GetRowKey<any>;
79
+ }
80
+
81
+ export const useSynchronousKeys = ({
82
+ selectedRowKeys,
83
+ records,
84
+ rowKey,
85
+ }: FilterKeysModal) => {
86
+ const { rowOnChange } = useHTableContext();
87
+ const findId = (key) => {
88
+ const msRecords = records as any[];
89
+ const rowIndex = msRecords.findIndex((item, index) => {
90
+ const id =
91
+ typeof rowKey === "function"
92
+ ? rowKey(item, index)
93
+ : item[rowKey as string];
94
+ return id === key;
95
+ });
96
+ return msRecords[rowIndex];
97
+ };
98
+ useEffect(() => {
99
+ if (selectedRowKeys && records && rowKey) {
100
+ const resultData = selectedRowKeys.map((key) => {
101
+ return findId(key);
102
+ });
103
+ rowOnChange(selectedRowKeys, resultData);
104
+ }
105
+ }, [selectedRowKeys, records, rowKey]);
106
+ };
@@ -1,59 +1,21 @@
1
- import type { ProTableProps } from "@ant-design/pro-table";
2
1
  import ProTable from "@ant-design/pro-table";
3
- import type {
4
- ActionRenderFn,
5
- ConfigDataModal,
6
- ParamsModal,
7
- HTableInstance,
8
- HRowSelection,
9
- } from "../modal";
10
2
  import {
11
- useCols,
12
- useColumnsStateType,
13
3
  useSize,
4
+ useTableChange,
14
5
  useSynchronousKeys,
15
- } from "./hooks";
6
+ } from "./hooks/useControl";
7
+ import { useCols, useColumnsStateType } from "./hooks/useColData";
16
8
  import { useHTableContext } from "../context";
17
9
  import React from "react";
18
10
  import { ConfigProvider, Alert, Space } from "antd";
19
11
  import { useHTableConfigContext } from "../TableConfig";
20
- import type { IPaginationProps } from "../HTablePagination";
21
12
  import HTablePagination from "../HTablePagination";
22
13
  import { useClassName } from "../hooks";
23
14
  import AlertMsg from "./AlertMsg";
24
- import type { AffixProps } from "antd/lib/affix";
25
15
  import Options from "./Options";
26
16
  import HeaderTitle from "./HeaderTitle";
27
- import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
28
17
  import { errorDefaultRender, emptyDefaultRender } from "./defaultRender";
29
- export interface OptionModal extends OptionConfig {
30
- settingRender?: () => React.ReactNode;
31
- }
32
- export interface HTableBodyProps
33
- extends Omit<
34
- ProTableProps<any, any>,
35
- "dataSource" | "rowSelection" | "options" | "pagination"
36
- > {
37
- configData?: ConfigDataModal;
38
- onPageChange?: (params: ParamsModal) => void;
39
- emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
40
- errorRender?: (
41
- tableInstance: HTableInstance,
42
- error: Error
43
- ) => React.ReactNode;
44
- tableStyle?: React.CSSProperties;
45
- paginationStyle?: React.CSSProperties;
46
- actionRender?: ActionRenderFn;
47
- rowSelection?: HRowSelection | false;
48
- affixProps?: AffixProps | false;
49
- goTop?: boolean;
50
- optionsRender?: (node: React.ReactNode) => React.ReactNode;
51
- paginationActionRender?: (tableInstance: HTableInstance) => React.ReactNode;
52
- localSorter?: boolean;
53
- options?: OptionModal | false;
54
- table?: HTableInstance;
55
- pagination?: IPaginationProps | false;
56
- }
18
+ import type { HTableBodyProps } from "./modal";
57
19
 
58
20
  export default (bodyProps: HTableBodyProps) => {
59
21
  const {
@@ -104,13 +66,14 @@ export default (bodyProps: HTableBodyProps) => {
104
66
  configData: bodyConfigData,
105
67
  table: tableInstance,
106
68
  rowSelection,
107
- bordered
69
+ bordered,
108
70
  });
109
71
 
110
72
  const { value, onChange, reset, ...selfColStatus } = useColumnsStateType({
111
73
  columnsState,
112
74
  columns: cols,
113
75
  });
76
+
114
77
  useSynchronousKeys({ selectedRowKeys, records, rowKey });
115
78
  const optionsNode = options && (
116
79
  <Options
@@ -135,6 +98,12 @@ export default (bodyProps: HTableBodyProps) => {
135
98
  const { tableStyle: defaultTableStyle } = useHTableConfigContext({
136
99
  tableStyle,
137
100
  });
101
+ const change = useTableChange({
102
+ columns: cols as any,
103
+ onChange: tableOnchange,
104
+ table: tableInstance,
105
+ localSorter,
106
+ });
138
107
  return (
139
108
  <div style={defaultTableStyle} className={`hw_table_body ${className}`}>
140
109
  <Space size={16} direction={"vertical"} style={{ width: "100%" }}>
@@ -164,25 +133,7 @@ export default (bodyProps: HTableBodyProps) => {
164
133
  columns={cols as any}
165
134
  size={cuSize}
166
135
  search={false}
167
- onChange={(page, filters, sorter, extra) => {
168
- if (tableOnchange) {
169
- return tableOnchange(page, filters, sorter, extra);
170
- }
171
- const { field, order, column } = sorter as any;
172
- const { sorter: colSorter } = column || {};
173
- if (localSorter || typeof colSorter === "function") {
174
- return;
175
- }
176
- const orderByField =
177
- typeof order === "undefined" ? undefined : field;
178
- const asc =
179
- typeof order === "undefined" ? undefined : order === "ascend";
180
- tableInstance.table.reloadWithParams({
181
- current: 1,
182
- orderByField,
183
- asc,
184
- });
185
- }}
136
+ onChange={change}
186
137
  tableStyle={{
187
138
  paddingBottom: 0,
188
139
  }}
@@ -0,0 +1,41 @@
1
+ import type { OptionConfig } from "@ant-design/pro-table/lib/components/ToolBar";
2
+ import type React from "react";
3
+ import type { ProTableProps } from "@ant-design/pro-table";
4
+ import type {
5
+ ActionRenderFn,
6
+ ConfigDataModal,
7
+ HRowSelection,
8
+ HTableInstance,
9
+ ParamsModal,
10
+ } from "@/components/modal";
11
+ import type { AffixProps } from "antd/lib/affix";
12
+ import type { IPaginationProps } from "@/components/HTablePagination";
13
+
14
+ export interface OptionModal extends OptionConfig {
15
+ settingRender?: () => React.ReactNode;
16
+ }
17
+ export interface HTableBodyProps
18
+ extends Omit<
19
+ ProTableProps<any, any>,
20
+ "dataSource" | "rowSelection" | "options" | "pagination"
21
+ > {
22
+ configData?: ConfigDataModal;
23
+ onPageChange?: (params: ParamsModal) => void;
24
+ emptyRender?: (tableInstance: HTableInstance) => React.ReactNode;
25
+ errorRender?: (
26
+ tableInstance: HTableInstance,
27
+ error: Error
28
+ ) => React.ReactNode;
29
+ tableStyle?: React.CSSProperties;
30
+ paginationStyle?: React.CSSProperties;
31
+ actionRender?: ActionRenderFn;
32
+ rowSelection?: HRowSelection | false;
33
+ affixProps?: AffixProps | false;
34
+ goTop?: boolean;
35
+ optionsRender?: (node: React.ReactNode) => React.ReactNode;
36
+ paginationActionRender?: (tableInstance: HTableInstance) => React.ReactNode;
37
+ localSorter?: boolean;
38
+ options?: OptionModal | false;
39
+ table?: HTableInstance;
40
+ pagination?: IPaginationProps | false;
41
+ }
@@ -19,7 +19,7 @@ export default ({
19
19
  tableStyle,
20
20
  action = {},
21
21
  spaceSize = 15,
22
- className,
22
+ className = "",
23
23
  paginationStyle,
24
24
  rowKey = "id",
25
25
  onFinish,
@@ -122,7 +122,7 @@
122
122
 
123
123
  .@{ant-prefix}-hw-table-render-copy{
124
124
  margin-bottom: 0 !important;
125
- color:#1890ff !important;
125
+ color:@primary-color !important;
126
126
  cursor: pointer;
127
127
  }
128
128
 
@@ -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 type { OptionModal } from "./HTableBody";
12
+ import type { OptionModal } from "./HTableBody/modal";
13
13
  import type { DrawerProps } from "antd";
14
14
  import type { IPaginationProps } from "@/components/HTablePagination";
15
15
 
@@ -99,7 +99,7 @@ const textRender = (config: ConfigItemModal, itemData: any) => {
99
99
  emptyNode = "-",
100
100
  } = valueTypeProps;
101
101
  const tableVal = getTableVal(config, itemData);
102
- const content=tableVal===null?emptyNode:tableVal;
102
+ const content = tableVal === null ? emptyNode : tableVal;
103
103
  return (
104
104
  <Paragraph
105
105
  type={type}
@@ -1 +1,2 @@
1
1
  @ant-prefix: ant;
2
+ @primary-color: #1890ff;
@@ -39,10 +39,16 @@ export const configData = [
39
39
  {
40
40
  title: "报警联系人名称",
41
41
  width: 120,
42
- dataIndex: "name",
42
+ dataIndex: ["name", "1"],
43
43
  valueType: "text",
44
44
  searchType: "rangePicker",
45
45
  showSearch: true,
46
+ sorter: true,
47
+ filterMultiple: false,
48
+ filters: [
49
+ { value: 1, text: "123" },
50
+ { value: 2, text: "2222" },
51
+ ],
46
52
  valueTypeProps: {
47
53
  ellipsis: {
48
54
  tooltip: true,
@@ -65,6 +71,7 @@ export const configData = [
65
71
  title: "id",
66
72
  dataIndex: "id",
67
73
  width: 120,
74
+ valueType: "copy",
68
75
  sorter: (a, b) => {
69
76
  const { id: aNum } = a;
70
77
  const { id: bNum } = b;
@@ -131,7 +138,7 @@ const Test = ({ name, selectedRowData }) => {
131
138
  };
132
139
  const maker = (name) => {
133
140
  const data = [];
134
- for (let i = 0; i < 10; i += 1) {
141
+ for (let i = 0; i < 100; i += 1) {
135
142
  data.push({
136
143
  name,
137
144
  id: i,
@@ -220,7 +227,13 @@ export default () => {
220
227
  mobileList: "mobileList",
221
228
  }}
222
229
  request={(params) => {
223
- return Promise.reject(new Error("错误"));
230
+ console.log(params);
231
+ return Promise.resolve({
232
+ current: 1,
233
+ records: maker(`第${100}页`),
234
+ size: 10,
235
+ total: 100,
236
+ });
224
237
  }}
225
238
  tableExtraRender={() => {
226
239
  return <div>ffff</div>;
@@ -239,17 +252,6 @@ export default () => {
239
252
  </div>
240
253
  </div>
241
254
  }
242
- reload={(params) => {
243
- const { size, current } = params;
244
- setDataSource({
245
- records: maker(`第${current}页`),
246
- size,
247
- current,
248
- total: "100",
249
- });
250
- return Promise.resolve();
251
- }}
252
- dataSource={dataSource}
253
255
  options={{
254
256
  settingRender: () => {
255
257
  return (